Пример #1
0
void SceneSaver::SaveFile(const String &fileName, Set<String> &errorLog)
{
    Logger::Info("[SceneSaver::SaveFile] %s", fileName.c_str());
    
    FilePath filePath = sceneUtils.dataSourceFolder + fileName;

    //Load scene with *.sc2
    Scene *scene = new Scene();
    Entity *rootNode = scene->GetRootNode(filePath);
    if(rootNode)
    {
        int32 count = rootNode->GetChildrenCount();
		Vector<Entity*> tempV;
		tempV.reserve((count));
        for(int32 i = 0; i < count; ++i)
        {
			tempV.push_back(rootNode->GetChild(i));
        }
		for(int32 i = 0; i < count; ++i)
		{
			scene->AddNode(tempV[i]);
		}
		
		SaveScene(scene, filePath, errorLog);
    }
	else
	{
		errorLog.insert(Format("[SceneSaver::SaveFile] Can't open file %s", fileName.c_str()));
	}

    SafeRelease(scene);
}
Пример #2
0
void CommandConvertScene::Execute()
{
    DVASSERT(CheckExtension(String(".dae")) && "Wrong extension");
    SceneValidator::Instance()->CreateDefaultDescriptors(EditorSettings::Instance()->GetDataSourcePath());
    
    eColladaErrorCodes code = ConvertDaeToSce(filePathname);
    if(code == COLLADA_OK)
    {
        // load sce to scene object
        String path = FileSystem::Instance()->ReplaceExtension(filePathname, ".sce");
        Scene * scene = new Scene();
        
        Entity *rootNode = scene->GetRootNode(path);
        scene->AddNode(rootNode);
        
        scene->BakeTransforms();
        
        // Export to *.sc2
        path = FileSystem::Instance()->ReplaceExtension(path, ".sc2");
        SceneFileV2 * file = new SceneFileV2();
        file->EnableDebugLog(true);
        file->SaveScene(path.c_str(), scene);
        SafeRelease(file);
        
        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."));
    }
}
Пример #3
0
void Test::LoadResources()
{
	time = 0.f;
	isFinished = false;
	skipFrames = 100;

	Scene *scene = new Scene();
	scene->AddNode(scene->GetRootNode(fullName));
	DVASSERT_MSG(scene, "Could not load the scene");

	Camera* cam = new Camera();
	scene->AddCamera(cam);

	Core* core = DAVA::Core::Instance();
	float32 aspect = core->GetVirtualScreenHeight() / core->GetVirtualScreenWidth();

	cam->Setup(70.f, aspect, 1.f, 5000.f);
	cam->SetLeft(Vector3(1, 0, 0));
	cam->SetUp(Vector3(0, 0, 1));
    
    scene->SetCurrentCamera(cam);
	SafeRelease(cam);

	UI3DView *sceneView = new UI3DView(Rect(0, 0, GetSize().x, GetSize().y));
	sceneView->SetScene(scene);
	AddControl(sceneView);
	SafeRelease(sceneView);

	Landscape* landscape = GetLandscape();
	DVASSERT_MSG(scene, "There is no landscape in a scene");
	landscape->SetTiledShaderMode(Landscape::TILED_MODE_TEXTURE);

	uint32 textureMemory = TextureHelper::GetSceneTextureMemory(scene, GetFilePath());
	testData.SetTextureMemorySize(textureMemory);

	File* file = File::Create(fullName, File::OPEN | File::READ);
	DVASSERT_MSG(file, "Could not open file scene file");
	testData.SetSceneFileSize(file->GetSize());
	SafeRelease(file);

	PreparePath();
    PrepareFpsStat();
    PrepareCameraAnimation();
    ZeroCurFpsStat();
    MoveToNextPoint();

    SafeRelease(scene);
}
Пример #4
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;
}
Пример #5
0
void SceneSaver::ResaveFile(const String &fileName, Set<String> &errorLog)
{
    DVASSERT(0);    //TODO: check save

	Logger::Info("[SceneSaver::ResaveFile] %s", fileName.c_str());

	FilePath sc2Filename = sceneUtils.dataSourceFolder + fileName;

	//Load scene with *.sc2
	Scene *scene = new Scene();
	Entity *rootNode = scene->GetRootNode(sc2Filename);
	if(rootNode)
	{
		int32 count = rootNode->GetChildrenCount();

		Vector<Entity*> tempV;
		tempV.reserve((count));
		for(int32 i = 0; i < count; ++i)
		{
			tempV.push_back(rootNode->GetChild(i));
		}
		for(int32 i = 0; i < count; ++i)
		{
			scene->AddNode(tempV[i]);
		}

		scene->Update(0.f);

		SceneFileV2 * outFile = new SceneFileV2();
		outFile->EnableDebugLog(false);
		outFile->SaveScene(sc2Filename, scene);
		SafeRelease(outFile);
	}
	else
	{
		errorLog.insert(Format("[SceneSaver::ResaveFile] Can't open file %s", fileName.c_str()));
	}

	SafeRelease(scene);
}
Пример #6
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;
}
Пример #7
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."));
    }
}
Пример #8
0
Scene* CreateScene(void){
	Scene* scene = new Scene();

	//Initiate materials
	Material* sunMaterial = new Material(
		vec4(0.0f, 0.0f, 0.0f, 0.0f),
		vec4(0.0f, 0.0f, 0.0f, 0.0f),
		vec4(0.0f, 0.0f, 0.0f, 0.0f),
		vec4(1.0f, 1.0f, 0.6f, 1.0f),
		1
	);
	scene->AddMaterial(sunMaterial);

	Material* earthMaterial = new Material(
		vec4(0.04f, 0.04f, 0.2f, 1.0f),
		vec4(0.1f, 0.5f, 0.3f, 1.0f),
		vec4(0.5f, 0.5f, 0.5f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		5
	);
	scene->AddMaterial(earthMaterial);

	Material* moonMaterial = new Material(
		vec4(0.1f, 0.1f, 0.1f, 1.0f),
		vec4(0.5f, 0.5f, 0.5f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		1
	);
	scene->AddMaterial(moonMaterial);

	Material* brickMaterial = new Material(
		vec4(-0.3f, -0.3f, -0.3f, 1.0f),
		vec4(1.5f, 1.5f, 1.5f, 1.0f),
		vec4(1.6f, 1.6f, 1.6f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		20
	);
	scene->AddMaterial(earthMaterial);

	Material* metalMaterial = new Material(
		vec4(0.2f, 0.2f, 0.2f, 1.0f),
		vec4(0.2f, 0.2f, 0.2f, 1.0f),
		vec4(1.0f, 1.0f, 1.0f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		10
	);
	scene->AddMaterial(metalMaterial);

	// Initiate Textures
	Texture* mudBrickTexture = new Texture("Textures/AlternatingMudbrick-ColorMap.png");
	scene->AddTexture(mudBrickTexture);
	Texture* mudBrickNormals = new Texture("Textures/AlternatingMudbrick-NormalMap.png");
	scene->AddTexture(mudBrickNormals);

	Texture* crackedBrickTexture = new Texture("Textures/CrackedAlternatingBricks-ColorMap.png");
	scene->AddTexture(crackedBrickTexture);
	Texture* crackedBrickNormals = new Texture("Textures/CrackedAlternatingBricks-NormalMap.png");
	scene->AddTexture(crackedBrickNormals);

	Texture* sandTexture = new Texture("Textures/Sand_1_Diffuse.png");
	scene->AddTexture(sandTexture);
	Texture* sandNormals = new Texture("Textures/Sand_1_Normal.png");
	scene->AddTexture(sandNormals);

	Texture* heightMap = new Texture("Textures/terrain-heightmap.png");
	//Texture* heightMap = new Texture("Textures/heightmap.png");
	//Texture* heightMap = new Texture("Textures/z.png");
	scene->AddTexture(heightMap);

	// Initiate Models
	/*
	Model* cube = new Cube();
	scene->AddModel(cube);
	*/
	Model* sphere = new Sphere(24);
	scene->AddModel(sphere);
	Model3DS* imported = new Model3DS("Model/pine_green_v3.3DS");
	scene->AddModel(imported);
	Model* plane = new Plane(2.0f, 2.0f, 64, 64);
	scene->AddModel(plane);

	Model* heightMapPlane = new HeightMappedPlane(2.0f, 2.0f, 5.0f, 64, 64, heightMap);

	// Initiate TextureSets
	TextureSet* brickBlend = new TextureSet();
	brickBlend->Add(mudBrickTexture, 2.0f);
	brickBlend->Add(crackedBrickTexture, 2.0f);

	TextureSet* blankTextureSet = new TextureSet();

	TextureSet* brickBlendNormals = new TextureSet();
	brickBlendNormals->Add(mudBrickNormals, 2.0f);
	brickBlendNormals->Add(crackedBrickNormals, 2.0f);

	TextureSet* smallBricks = new TextureSet();
	smallBricks->Add(crackedBrickTexture, 0.25f);
	TextureSet* smallBrickNormals = new TextureSet();
	smallBrickNormals->Add(crackedBrickNormals, 0.25f);

	// Initiate Nodes
	//EulerNode* ground = new EulerNode(plane, brickMaterial, brickBlend);
	EulerNode* ground = new EulerNode(heightMapPlane, brickMaterial, brickBlend);
	ground->Position = vec3(0.0f, -10.0f, 0.0f);
	ground->SetNormalMaps(brickBlendNormals);
	
	TextureSwitcher* textureSwitcher = new TextureSwitcher(ground);
	textureSwitcher->AddTextures(mudBrickTexture, mudBrickNormals);
	textureSwitcher->AddTextures(crackedBrickTexture, crackedBrickNormals);
	textureSwitcher->AddTextures(sandTexture, sandNormals);
	scene->AddNode(textureSwitcher);
	
	EulerNode* orb = new EulerNode(sphere, metalMaterial, blankTextureSet);
	//EulerNode* orb = new EulerNode(sphere, metalMaterial, smallBricks);
	orb->Position = vec3(0.0f, 5.0f, 0.0f);
	orb->SetNormalMaps(blankTextureSet);
	//orb->SetNormalMaps(smallBrickNormals);
	orb->Size = 5;
	ground->AddChild(orb);
	
	// Initiate Lights
	PointLight* pointLight = new PointLight();
	SpotLight* spotLight = new SpotLight();
	spotLight->Ambient = vec4(0.3f, 0.3f, 0.3f, 1.0);
	spotLight->Diffuse = vec4(0.5f, 0.5f, 0.3f, 0.0);
	spotLight->Specular = vec4(1.0f, 1.0f, 1.0f, 1.0);
	spotLight->Angle = 55.0f;
	spotLight->Direction = vec3(0.0f, -1.0f, 0.0f);

	scene->AddLight(pointLight);
	scene->AddLight(spotLight);

	EulerNode* spotLightModelNode = new EulerNode(sphere, sunMaterial, blankTextureSet);
	spotLightModelNode->Position = vec3(50.0f, 100.0f, 50.0f);
	spotLightModelNode->SetNormalMaps(blankTextureSet);
	spotLightModelNode->Position = vec3(spotLight->Position);
	scene->AddNode(spotLightModelNode);

	MouseNode* spotLightMover = new MouseNode(spotLightModelNode, GLUT_LEFT_BUTTON, true);
	LightNode* spotLightNode = new LightNode(spotLight, spotLightMover);
	spotLightMover->SetPosition(vec3(5.0f, 5.0f, 5.0f));
	scene->AddNode(spotLightNode);

	EulerNode* pointLightModelNode = new EulerNode(sphere, sunMaterial, blankTextureSet);
	pointLightModelNode->Position = vec3(50.0f, 50.0f, 50.0f);
	pointLightModelNode->SetNormalMaps(blankTextureSet);
	pointLightModelNode->Position = vec3(pointLight->Position);
	scene->AddNode(pointLightModelNode);

	MouseNode* pointLightMover = new MouseNode(pointLightModelNode, GLUT_RIGHT_BUTTON, false);
	LightNode* pointLightNode = new LightNode(pointLight, pointLightMover);
	pointLightMover->SetPosition(vec3(0.0f, 5.0f, 0.0f));
	scene->AddNode(pointLightNode);

	Node* globalControls = new GlobalControls();
	scene->AddNode(globalControls);

	return scene;
}