void SceneValidator::ValidateRenderBatch(Entity *ownerNode, RenderBatch *renderBatch, Set<String> &errorsLog) { ownerNode->RemoveFlag(Entity::NODE_INVALID); Material *material = renderBatch->GetMaterial(); if(material) { ValidateMaterial(material, errorsLog); } InstanceMaterialState *materialState = renderBatch->GetMaterialInstance(); if(materialState) { ValidateInstanceMaterialState(materialState, errorsLog); ConvertLightmapSizeFromProperty(ownerNode, materialState); } PolygonGroup *polygonGroup = renderBatch->GetPolygonGroup(); if(polygonGroup) { if(material) { if (material->Validate(polygonGroup) == Material::VALIDATE_INCOMPATIBLE) { ownerNode->AddFlag(Entity::NODE_INVALID); errorsLog.insert(Format("Material: %s incompatible with node:%s.", material->GetName().c_str(), ownerNode->GetFullName().c_str())); errorsLog.insert("For lightmapped objects check second coordinate set. For normalmapped check tangents, binormals."); } } } }
rapidjson::Document SceneConvertor::Convert( const Scene* scene ) { Document json; json.SetObject(); Document::AllocatorType& al = json.GetAllocator(); json.AddMember( "FILE_TYPE", "SCENE", al ); Value stringNode; Value nullNode; nullNode.SetNull(); Material* skyboxMat = scene->GetSkyboxMaterial(); if (skyboxMat != NULL) { stringNode.SetString( skyboxMat->GetName().ToChar(), al ); json.AddMember( "skyboxMaterial", stringNode, al ); } else { json.AddMember( "skyboxMaterial", nullNode, al ); } json.AddMember( "skyboxSize", scene->GetSkyboxSize(), al ); Value vec3Node = _Vec3_to_JSON( scene->GetAmbientLight(), al ); json.AddMember( "ambientLight", vec3Node, al ); if ( scene->GetMainCamera() != NULL ) { stringNode.SetString( scene->GetMainCamera()->GetName().ToChar(), al ); json.AddMember( "mainCamera", stringNode, al ); } else { json.AddMember( "mainCamera", nullNode, al ); } Value arrayNode; arrayNode.SetArray(); for (uint i = 0; i < scene->GetGameObjectCount(); ++i) { GameObject* gameObject = scene->GetGameObjectAt(i); if ( gameObject->GetParentNode() == NULL && (_useAll || gameObject->IsSavable()) ) { arrayNode.PushBack( _GameObject_to_JSON(gameObject, al), al ); } } json.AddMember( "gameObjects", arrayNode, al ); return json; }
void mitk::Material::Initialize( const Material& property ) { this->SetColor( property.GetColor() ); this->SetColorCoefficient( property.GetColorCoefficient() ); this->SetSpecularColor( property.GetSpecularColor() ); this->SetSpecularCoefficient( property.GetSpecularCoefficient() ); this->SetSpecularPower( property.GetSpecularPower() ); this->SetOpacity( property.GetOpacity() ); this->SetInterpolation( property.GetInterpolation() ); this->SetRepresentation( property.GetRepresentation() ); this->SetLineWidth( property.GetLineWidth() ); this->SetName( property.GetName() ); }
bool OBJParser::getMaterial(const wchar_t* mtlName, Material** material) { bool isSucceed = false; Assert(NULL != material); *material = NULL; for(size_t i = 0; i < mMtlList.size(); ++i) { Material* curMaterial = mMtlList[i]; if(YString::Compare(curMaterial->GetName(), mtlName) == 0) *material = curMaterial; } Assert(NULL != *material); isSucceed = true; Exit: return isSucceed; }
RenderObject* GL33Renderer::LoadRenderObject(const MeshRenderer& meshRenderer, int type) { GL33RenderObject* object = new GL33RenderObject(); this->GenerateVertexArrayID(*object); RenderData* renderData = &(meshRenderer.m_mesh->m_renderData); object->m_toMeshTriangles = &(renderData->m_triangleIndices); object->m_toMeshVertices = &(renderData->m_vertPos); object->m_toMeshNormals = &(renderData->m_vertNormal); object->m_toMeshTangents = &(renderData->m_vertTangent); object->m_toMeshBiTangents = &(renderData->m_vertBiTangent); object->m_toMeshUVs = &(renderData->m_vertUVs); object->m_modelTransform = meshRenderer.GetTransformMatrix(); if (!this->GenerateArrays(*object)) { return nullptr; } for (int i = 0; i < meshRenderer.m_materials.size(); i++) { Material* mat = meshRenderer.m_materials[i]; AssignMaterial(*object, mat->GetName()); for (int j = 0; j < mat->m_textureSamplerAttributes.size(); j++) { LoadTextureSample(*object, mat->m_textureSamplerAttributes[j].first, mat->m_textureSamplerAttributes[j].second); } } object->m_renderType = meshRenderer.m_renderType; //if (type == 0) // m_meshRenderPool.push_back(object); //else if (type == 1) // m_gizmoRenderPool.push_back(object); return object; }
void DataViewer_GameObject::_UpdatePiece_MeshDrawing( MeshDrawing* meshDrawing ) { _WriteWidget_Bool( _dataMeshDrawing.enable, meshDrawing->IsEnabled() ); Material* material = meshDrawing->GetMaterial(); if ( material != NULL ) _WriteWidget_Picking( _dataMeshDrawing.material, material->GetName() ); else _WriteWidget_Picking( _dataMeshDrawing.material, "NULL" ); Mesh* mesh = meshDrawing->GetMesh(); if ( mesh != NULL ) _WriteWidget_Picking( _dataMeshDrawing.mesh, mesh->GetName() ); else _WriteWidget_Picking( _dataMeshDrawing.mesh, "NULL" ); _WriteWidget_Bool ( _dataMeshDrawing.castShadows, meshDrawing->IsCastingShadows() ); _WriteWidget_Bool ( _dataMeshDrawing.receiveShadows, meshDrawing->IsReceivingShadows() ); _Colorize_MeshDrawing( meshDrawing->IsEnabled() && _selectedObject->IsEnabled() ); }
void gfx::MaterialBank::LoadMaterials(rString filename) { Model dummy; ObjectImporter assetImporter; assetImporter.LoadObject(filename, dummy); rVector<RoboMat> mats = assetImporter.GetMaterials(); for ( auto& it : mats ) { Material* mat = pNew( Material ); mat->SetBaseColor(vec3(it.Color[0],it.Color[1],it.Color[2])); mat->SetSpecularColor(vec3(it.Specularity[0],it.Specularity[1],it.Specularity[2])); mat->SetName(it.Name); if(it.HasAlbedoMap) { mat->SetAlbedoTexture(it.AlbedoTex); } if(it.HasBumpMap) { mat->SetNormalTexture(it.BumpTex); } if(it.HasRoughMap) { mat->SetRoughnessTexture(it.RoughTex); } if(it.HasMetalMap) { mat->SetMetalTexture(it.MetalTex); } if(it.HasGlowMap) { mat->SetGlowTexture(it.GlowTex); } m_Materials.push_back( mat ); m_MatMap.emplace(mat->GetName(),mat); } //TODOHJ: HAX for restarting m_TextureAtlasses = pNewArray(TextureAtlas,Texture_Atlas_Type::Count); }
UIListCell *MaterialEditor::CellAtIndex(UIList *forList, int32 index) { UIListCell *c = forList->GetReusableCell("Material name cell"); if (!c) { c = new UIListCell(Rect(0, 0, forList->GetRect().dx, 20), "Material name cell"); float32 boxSize = 16; float32 y = (CellHeight(forList, index) - boxSize) / 2; float32 x = forList->GetRect().dx - boxSize; //Temporary fix for loading of UI Interface to avoid reloading of texrures to different formates. // 1. Reset default format before loading of UI // 2. Restore default format after loading of UI from stored settings. Texture::SetDefaultFileFormat(NOT_FILE); Rect r = Rect(x, y, boxSize, boxSize); UIControl *sceneFlagBox = new UIControl(r); sceneFlagBox->SetName("flagBox"); sceneFlagBox->GetBackground()->SetDrawType(UIControlBackground::DRAW_SCALE_TO_RECT); sceneFlagBox->SetSprite("~res:/Gfx/UI/marker", 1); sceneFlagBox->SetInputEnabled(false); c->AddControl(sceneFlagBox); SafeRelease(sceneFlagBox); Texture::SetDefaultFileFormat((ImageFileFormat)EditorSettings::Instance()->GetTextureViewFileFormat()); } Material *mat = GetMaterial(index); bool found = false; if(EDM_ALL == displayMode) { for (int32 i = 0; i < (int32)workingNodeMaterials.size(); ++i) { if(workingNodeMaterials[i] == mat) { found = true; break; } } } else { found = true; } ControlsFactory::CustomizeListCell(c, StringToWString(mat->GetName()), false); UIControl *sceneFlagBox = c->FindByName("flagBox"); sceneFlagBox->SetVisible(found, false); if (index == selectedMaterial) { c->SetSelected(true, false); lastSelection = c; } else { c->SetSelected(false, false); } return c; }
void MeshInstancePropertyControl::ReadFrom(Entity * sceneNode) { NodesPropertyControl::ReadFrom(sceneNode); MeshInstanceNode *mesh = dynamic_cast<MeshInstanceNode *> (sceneNode); DVASSERT(mesh); propertyList->AddSection("property.meshinstance.meshinstance", GetHeaderState("property.meshinstance.meshinstance", true)); //BBOX AABBox3 bbox = mesh->GetBoundingBox(); AABBox3 transformedBox; bbox.GetTransformedBox(mesh->GetWorldTransform(), transformedBox); propertyList->AddStringProperty("property.meshinstance.bboxmin", PropertyList::PROPERTY_IS_READ_ONLY); propertyList->AddStringProperty("property.meshinstance.bboxmax", PropertyList::PROPERTY_IS_READ_ONLY); propertyList->SetStringPropertyValue("property.meshinstance.bboxmin", Format("%0.2f, %0.2f, %0.2f", transformedBox.min.x, transformedBox.min.y, transformedBox.min.z)); propertyList->SetStringPropertyValue("property.meshinstance.bboxmax", Format("%0.2f, %0.2f, %0.2f", transformedBox.max.x, transformedBox.max.y, transformedBox.max.z)); materials.clear(); materialNames.clear(); if(workingScene) { workingScene->GetDataNodes(materials); } int32 matCount = (int32)materials.size(); for(int32 i = 0; i < matCount; ++i) { Material *mat = materials[i]; materialNames.push_back(mat->GetName()); } Vector<PolygonGroupWithMaterial*> polygroups = mesh->GetPolygonGroups(); for(int32 i = 0; i < (int32)polygroups.size(); ++i) { PolygonGroup *pg = polygroups[i]->GetPolygonGroup(); String fieldName = Format("PolygonGroup #%d", i); propertyList->AddSection(fieldName, GetHeaderState(fieldName, true)); int32 vertexFormat = pg->GetFormat(); String keyPrefix = Format("#%d", i); propertyList->AddBoolProperty(keyPrefix + ". fmt.NORMAL", PropertyList::PROPERTY_IS_EDITABLE); propertyList->SetBoolPropertyValue(keyPrefix + ". fmt.NORMAL", 0 != (vertexFormat & EVF_NORMAL)); propertyList->AddBoolProperty(keyPrefix + ". fmt.COLOR", PropertyList::PROPERTY_IS_EDITABLE); propertyList->SetBoolPropertyValue(keyPrefix + ". fmt.COLOR", 0 != (vertexFormat & EVF_COLOR)); propertyList->AddBoolProperty(keyPrefix + ". fmt.TEXCOORD0", PropertyList::PROPERTY_IS_EDITABLE); propertyList->SetBoolPropertyValue(keyPrefix + ". fmt.TEXCOORD0", 0 != (vertexFormat & EVF_TEXCOORD0)); propertyList->AddBoolProperty(keyPrefix + ". fmt.TEXCOORD1", PropertyList::PROPERTY_IS_EDITABLE); propertyList->SetBoolPropertyValue(keyPrefix + ". fmt.TEXCOORD1", 0 != (vertexFormat & EVF_TEXCOORD1)); propertyList->AddBoolProperty(keyPrefix + ". fmt.TEXCOORD2", PropertyList::PROPERTY_IS_EDITABLE); propertyList->SetBoolPropertyValue(keyPrefix + ". fmt.TEXCOORD2", 0 != (vertexFormat & EVF_TEXCOORD2)); propertyList->AddBoolProperty(keyPrefix + ". fmt.TEXCOORD3", PropertyList::PROPERTY_IS_EDITABLE); propertyList->SetBoolPropertyValue(keyPrefix + ". fmt.TEXCOORD3", 0 != (vertexFormat & EVF_TEXCOORD3)); propertyList->AddBoolProperty(keyPrefix + ". fmt.TANGENT", PropertyList::PROPERTY_IS_EDITABLE); propertyList->SetBoolPropertyValue(keyPrefix + ". fmt.TANGENT", 0 != (vertexFormat & EVF_TANGENT)); propertyList->AddBoolProperty(keyPrefix + ". fmt.BINORMAL", PropertyList::PROPERTY_IS_EDITABLE); propertyList->SetBoolPropertyValue(keyPrefix + ". fmt.BINORMAL", 0 != (vertexFormat & EVF_BINORMAL)); propertyList->AddBoolProperty(keyPrefix + ". fmt.JOINTWEIGHT", PropertyList::PROPERTY_IS_EDITABLE); propertyList->SetBoolPropertyValue(keyPrefix + ". fmt.JOINTWEIGHT", 0 != (vertexFormat & EVF_JOINTWEIGHT)); propertyList->AddIntProperty(keyPrefix + ".lightmap.size"); propertyList->SetIntPropertyValue(keyPrefix + ".lightmap.size", currentSceneNode->GetCustomProperties()->GetInt32(keyPrefix + ".lightmap.size", 128)); if(matCount && !createNodeProperties) { String comboName = keyPrefix + ". Material"; propertyList->AddComboProperty(comboName, materialNames); if(polygroups[i]->GetMaterial()) { String meshMatName = polygroups[i]->GetMaterial()->GetName(); for(int32 iMat = 0; iMat < (int32)materials.size(); ++iMat) { if(meshMatName == materialNames[iMat]) { propertyList->SetComboPropertyIndex(comboName, iMat); break; } } } else { propertyList->SetComboPropertyIndex(comboName, 0); } propertyList->AddMessageProperty("property.meshinstance.editmaterial", Message(this, &MeshInstancePropertyControl::OnGo2Materials, polygroups[i]->GetMaterial())); } propertyList->AddMessageProperty("property.meshinstance.showtriangles", Message(this, &MeshInstancePropertyControl::OnShowTexture, pg)); } propertyList->AddSection("property.meshinstance.dynamicshadow", GetHeaderState("property.meshinstance.dynamicshadow", true)); propertyList->AddBoolProperty("property.meshinstance.dynamicshadow.enable"); propertyList->SetBoolPropertyValue("property.meshinstance.dynamicshadow.enable", currentSceneNode->GetCustomProperties()->GetBool("property.meshinstance.dynamicshadow.enable", false)); propertyList->AddMessageProperty("property.meshinstance.dynamicshadow.converttovolume", Message(this, &MeshInstancePropertyControl::OnConvertToShadowVolume)); }
void Grafkit::SceneLoader::SceneLoaderHelper::Load(Archive &ar, IResourceManager * const & resman) { Persist(ar, resman); LOGGER(Log::Logger().Info("-- ASSIGN --")); // 5. material -> mesh relation LOGGER(Log::Logger().Info("Materials: %d", m_materials_to_meshes.size())); for (auto it = m_materials_to_meshes.begin(); it != m_materials_to_meshes.end(); ++it) { USHORT key = it->first; USHORT val = it->second; Material * material = m_materials[key]; Model *model = dynamic_cast<Model *>(m_entities[val]); if (model && material) { model->SetMaterial(material); LOGGER(Log::Logger().Info("%hu (\"%s\") -> %hu (\"%s\")", key, material->GetName().c_str(), val, model->GetName().c_str())); } } // ... // 6. entitiy -> actor relation LOGGER(Log::Logger().Info("Entities: %d", m_entities_to_actors.size())); for (auto it = m_entities_to_actors.begin(); it != m_entities_to_actors.end(); ++it) { USHORT key = it->first; USHORT val = it->second; Entity3D *entity = m_entities[key]; Actor *actor = m_actors[val]; if (actor && entity) { actor->AddEntity(entity); LOGGER(Log::Logger().Info("%hu (\"%s\") -> %hu (\"%s\")", key, entity->GetName().c_str()), val, actor->GetName().c_str()); } } // ... // 7. actor -> actor relation - scenegraph LOGGER(Log::Logger().Info("Actors: %d", m_actor_to_actor.size())); for (auto it = m_actor_to_actor.begin(); it != m_actor_to_actor.end(); ++it) { USHORT key = it->first; USHORT val = it->second; Actor *child = m_actors[val]; Actor *parent = m_actors[key]; if (parent && child) { parent->AddChild(child); LOGGER(Log::Logger().Info("%hu (\"%s\") -> %hu (\"%s\")", key, parent->GetName().c_str(), val, child->GetName().c_str())); } } //8, 9 animation -> actor, entity LOGGER(Log::Logger().Info("Animations: %d", m_animation_to_actor.size() + m_animation_to_entity.size())); for (auto it = m_animation_to_actor.cbegin(); it != m_animation_to_actor.cend(); ++it) { USHORT key = it->first; USHORT value = it->second; ActorAnimation *actor_animation = dynamic_cast<ActorAnimation *>(m_Animations[key]); if (actor_animation) { Actor* actor = m_actors[value]; if (actor) { actor_animation->SetActor(ActorRef(actor)); m_scene->AddAnimation(actor_animation); LOGGER(Log::Logger().Info("Actor %hu (\"%s\") -> %hu (\"%s\")", key, actor->GetName().c_str(), value, actor_animation->GetName().c_str())); } } } for (auto it = m_animation_to_entity.cbegin(); it != m_animation_to_entity.cend(); ++it) { USHORT key = it->first; USHORT value = it->second; EntityAnimation *entity_animation = dynamic_cast<EntityAnimation*>(m_Animations[key]); if (entity_animation) { Entity3D* entity = m_entities[value]; if (entity) { entity_animation->SetEntity(Ref<Entity3D>(entity)); m_scene->AddAnimation(entity_animation); LOGGER(Log::Logger().Info("Entity %hu -> %hu", key, value)); } } } if (m_actors.empty()) throw new EX_DETAILS(SceneLoadException, "Actors are empty for some reason"); Actor * root = m_actors[0]; m_scene->Initialize(root); }