void ActionCreateEntityFromFile::Update(WorldState& worldState)
	{ 
		assert(worldState.sector != nullptr);

		Entity* entityCopy = worldState.world->ClassDefinitionContainer.FindEntity((*this)[ATTRIBUTE_ENTITY_CLASS_NAME].Get<std::string>());
		assert(entityCopy != nullptr);

		Entity* newEntity = entityCopy->Clone(*entityCopy)->AssertiveAs<Entity>();

		worldState.sector->AdoptEntity(*newEntity, (*this)[ATTRIBUTE_ENTITY_INSTANCE_NAME].Get<std::string>());

		newEntity->BeginPlay(worldState);
		*mNewEntity = *newEntity;
	}
Exemplo n.º 2
0
DAVA::Scene * DAEConvertAction::CreateSceneFromSce() const
{
    FilePath scePath = FilePath::CreateWithNewExtension(daePath, ".sce");
    
    Scene *scene = new Scene();
    Entity *rootNode = scene->GetRootNode(scePath);
	if(rootNode)
	{
		rootNode = rootNode->Clone();
		scene->AddNode(rootNode);
		scene->BakeTransforms();
		rootNode->Release();
	}
    
    return scene;
}
Exemplo n.º 3
0
DAVA::Scene * DAEConvertWithSettingsAction::CreateSceneFromSc2(const DAVA::FilePath &scenePathname)
{
    Scene * scene = new Scene();
    
    Entity * rootNode = scene->GetRootNode(scenePathname);
	if(rootNode)
	{
		rootNode = rootNode->Clone();

		Vector<Entity*> tmpEntities;
		uint32 entitiesCount = (uint32)rootNode->GetChildrenCount();
        
		// optimize scene
        SceneFileV2 *sceneFile = new SceneFileV2();
		sceneFile->OptimizeScene(rootNode);
		sceneFile->Release();
        
		// remember all child pointers, but don't add them to scene in this cycle
		// because when entity is adding it is automatically removing from its old hierarchy
		tmpEntities.reserve(entitiesCount);
		for (uint32 i = 0; i < entitiesCount; ++i)
		{
			tmpEntities.push_back(rootNode->GetChild(i));
		}
        

		// now we can safely add entities into our hierarchy
		for (uint32 i = 0; i < (uint32) tmpEntities.size(); ++i)
		{
			scene->AddNode(tmpEntities[i]);
		}

		rootNode->Release();

        Set<String> errorsLog;
        SceneValidator::Instance()->ValidateScene(scene, scenePathname, errorsLog);
	}
    
    return scene;
}
Exemplo n.º 4
0
void CommandConvertScene::Execute()
{
    DVASSERT(CheckExtension(String(".dae")) && "Wrong extension");
//    TextureDescriptorUtils::CreateDescriptorsForFolder(EditorSettings::Instance()->GetDataSourcePath());
    DVASSERT(false)
    
    eColladaErrorCodes code = ConvertDaeToSce(filePathname);
    if(code == COLLADA_OK)
    {
        // load sce to scene object
        FilePath path = FilePath::CreateWithNewExtension(filePathname, ".sce");

        Scene * scene = new Scene();
        
        Entity *rootNode = scene->GetRootNode(path);
		if(rootNode)
		{
			rootNode = rootNode->Clone();
			scene->AddNode(rootNode);
			rootNode->Release();
		}
        
        scene->BakeTransforms();
        
        // Export to *.sc2
        path.ReplaceExtension(".sc2");
        scene->Save(path);
        SafeRelease(scene);
    }
    else if(code == COLLADA_ERROR_OF_ROOT_NODE)
    {
        ShowErrorDialog(String("Can't convert from DAE. Looks like one of materials has same name as root node."));
    }
    else
    {
        ShowErrorDialog(String("Can't convert from DAE."));
    }
}