コード例 #1
0
ファイル: Scene.cpp プロジェクト: galek/dava.framework
Entity *Scene::GetRootNode(const FilePath &rootNodePath)
{
	ProxyNodeMap::const_iterator it = rootNodes.find(FILEPATH_MAP_KEY(rootNodePath));
	if (it != rootNodes.end())
	{
        ProxyNode * node = it->second;
		return node->GetNode();
	}
    
    if(rootNodePath.IsEqualToExtension(".sce"))
    {
        SceneFile *file = new SceneFile();
        file->SetDebugLog(true);
        file->LoadScene(rootNodePath, this);
        SafeRelease(file);
    }
    else if(rootNodePath.IsEqualToExtension(".sc2"))
    {
        uint64 startTime = SystemTimer::Instance()->AbsoluteMS();
        SceneFileV2 *file = new SceneFileV2();
        file->EnableDebugLog(false);
        SceneFileV2::eError loadResult = file->LoadScene(rootNodePath, this);
        SafeRelease(file);
				
        uint64 deltaTime = SystemTimer::Instance()->AbsoluteMS() - startTime;
        Logger::FrameworkDebug("[GETROOTNODE TIME] %dms (%ld)", deltaTime, deltaTime);

        if (loadResult != SceneFileV2::ERROR_NO_ERROR)
        {
            return 0;
        }
    }
    
	it = rootNodes.find(FILEPATH_MAP_KEY(rootNodePath));
	if (it != rootNodes.end())
	{
        ProxyNode * node = it->second;
        //int32 nowCount = node->GetNode()->GetChildrenCountRecursive();
		return node->GetNode();
	}
    return 0;
}
コード例 #2
0
void LandscapeTestScreen::LoadResources()
{
#if 0
//    RenderManager::Instance()->EnableOutputDebugStatsEveryNFrame(30);
    RenderManager::Instance()->SetFPS(30.0);
	scene = new Scene();
    
	scene3dView = 0;
    scene3dView = new UI3DView(Rect(0, 0, 480, 320));
    //scene3dView->SetDebugDraw(true);
    scene3dView->SetScene(scene);
    scene3dView->SetInputEnabled(false);
    AddControl(scene3dView);
    
    camera = new Camera();
    scene->AddCamera(camera);
    camera->Setup(70.0f, 480.0f / 320.0f, 1.0f, 5000.0f); 
    scene->SetCurrentCamera(camera);
    camera->SetDebugFlags(SceneNode::DEBUG_DRAW_ALL);
    camera->SetUp(Vector3(0.0f, 0.0f, 1.0f));
    camera->SetPosition(Vector3(0.0f, 0.0f, 10.0f));
    scene->SetCurrentCamera(camera);
    scene->SetDebugFlags(SceneNode::DEBUG_DRAW_ALL);
 
    LandscapeNode * node = new LandscapeNode();
    AABBox3 box(Vector3(445.0f / 2.0f, 445.0f / 2.0f, 0), Vector3(-445.0f / 2.0f, -445.0f / 2.0f, 50.0f));
    
    //node->SetDebugFlags(LandscapeNode::DEBUG_DRAW_ALL);
#if 0
	node->BuildLandscapeFromHeightmapImage(LandscapeNode::RENDERING_MODE_DETAIL_SHADER, "~res:/Landscape/hmp2_1.png", box);
    
    Texture::EnableMipmapGeneration();
    node->SetTexture(LandscapeNode::TEXTURE_COLOR, "~res:/Landscape/diffuse_l2.png");
    node->SetTexture(LandscapeNode::TEXTURE_DETAIL, "~res:/Landscape/detail_gravel.png");
    Texture::DisableMipmapGeneration();

	
//     node->BuildLandscapeFromHeightmapImage(LandscapeNode::RENDERING_MODE_DETAIL_SHADER, "~res:/Landscape/hmp2_1.png", box);
//     
//     Texture::EnableMipmapGeneration();
//     node->SetTexture(LandscapeNode::TEXTURE_TEXTURE0, "~res:/Landscape/tex3.png");
//     node->SetTexture(LandscapeNode::TEXTURE_DETAIL, "~res:/Landscape/detail_gravel.png");
//     Texture::DisableMipmapGeneration();
#else
    node->BuildLandscapeFromHeightmapImage("~res:/Landscape/hmp2_1.png", box);
    
    Texture::EnableMipmapGeneration();
    node->SetTexture(LandscapeNode::TEXTURE_COLOR, "~res:/Landscape/diffuse.png");
    node->SetTexture(LandscapeNode::TEXTURE_TILE0, "~res:/Landscape/blend/d.png");
    node->SetTexture(LandscapeNode::TEXTURE_TILE1, "~res:/Landscape/blend/s.png");
    node->SetTexture(LandscapeNode::TEXTURE_TILE2, "~res:/Landscape/blend/d.png");
    node->SetTexture(LandscapeNode::TEXTURE_TILE3, "~res:/Landscape/blend/s.png");
    node->SetTexture(LandscapeNode::TEXTURE_TILE_MASK, "~res:/Landscape/blend/mask.png");
    Texture::DisableMipmapGeneration();
#endif
    
    node->SetName("landscapeNode");
    scene->AddNode(node);
    SafeRelease(node);
    
//    Sprite * sprite = Sprite::Create("~res:/Gfx/Billboards/billboards");
//    //sprite->SetPivotPoint(sprite->GetWidth() / 2.0f, sprite->GetHeight() / 2.0f);
//    SpriteNode * spriteNode = new SpriteNode(scene, sprite, 0, Vector2(0.1f, 0.1f), Vector2(sprite->GetWidth() / 2.0f, sprite->GetHeight() / 2.0f));
//    spriteNode->SetName("testSpriteNode");
//    spriteNode->SetLocalTransform(Matrix4::MakeTranslation(Vector3(0.f, 10.0f, 0.0f)));
//    spriteNode->SetDebugFlags(SceneNode::DEBUG_DRAW_ALL);
//    spriteNode->SetType(SpriteNode::TYPE_BILLBOARD);
//    scene->AddNode(spriteNode);

    
    SceneFile * file = new SceneFile();
    file->SetDebugLog(true);
    file->LoadScene("~res:/Scenes/level2/level2_445.sce", scene);
    scene->AddNode(scene->GetRootNode("~res:/Scenes/level2/level2_445.sce"));
    SafeRelease(file);

	inTouch = false;
    
	scene3dView = 0;
    scene3dView = new UI3DView(Rect(0, 0, 480, 320));
    scene3dView->SetInputEnabled(false);
    scene3dView->SetScene(scene);
    
    AddControl(scene3dView);
    
    viewXAngle = 0;
    viewYAngle = 0; 
    
	positionJoypad = new UIJoypad(Rect(0, 320 - 80, 80, 80));
    positionJoypad->GetBackground()->SetSprite("~res:/Gfx/Joypad/joypad", 0);
    positionJoypad->SetStickSprite("~res:/Gfx/Joypad/joypad", 1);
	AddControl(positionJoypad);

    angleJoypad = new UIJoypad(Rect(480 - 80, 320 - 80, 80, 80));
    angleJoypad->GetBackground()->SetSprite("~res:/Gfx/Joypad/joypad", 0);
    angleJoypad->SetStickSprite("~res:/Gfx/Joypad/joypad", 1);
	AddControl(angleJoypad);
#endif
}
コード例 #3
0
int32 ScenePreviewControl::OpenScene(const FilePath &pathToFile)
{
    ReleaseScene();
    RecreateScene();
    
    int32 retError = SceneFileV2::ERROR_NO_ERROR;
    if(pathToFile.IsEqualToExtension(".sce"))
    {
        SceneFile *file = new SceneFile();
        file->SetDebugLog(true);
        if(!file->LoadScene(pathToFile, editorScene))
        {
            retError = ERROR_CANNOT_OPEN_FILE;
        }
        
        SafeRelease(file);
    }
    else if(pathToFile.IsEqualToExtension(".sc2"))
    {
        SceneFileV2 *file = new SceneFileV2();
        file->EnableDebugLog(true);
        retError = file->LoadScene(pathToFile, editorScene);
        SafeRelease(file);
    }
    else
    {
        retError = ERROR_WRONG_EXTENSION;
    }
    
    if(SceneFileV2::ERROR_NO_ERROR == retError)
    {
        rootNode = editorScene->GetRootNode(pathToFile);
        if(rootNode)
        {
            currentScenePath = pathToFile;
            editorScene->AddNode(rootNode);
            
            needSetCamera = true;
            Camera *cam = editorScene->GetCamera(0);
            if(!cam)
            {
                Camera * cam = new Camera();
                //cam->SetDebugFlags(Entity::DEBUG_DRAW_ALL);
                cam->SetUp(Vector3(0.0f, 0.0f, 1.0f));
                cam->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
                cam->SetTarget(Vector3(0.0f, 1.0f, 0.0f));
                
                cam->SetupPerspective(70.0f, 320.0f / 480.0f, 1.0f, 5000.0f); 
                

                
                ScopedPtr<Entity> node(new Entity());
                node->SetName("preview-camera");
                node->AddComponent(new CameraComponent(cam));
                editorScene->AddNode(node);
                editorScene->AddCamera(cam);
                editorScene->SetCurrentCamera(cam);
                cameraController->SetScene(editorScene);
                
                SafeRelease(cam);
                
                sceCamera = false;
            }
            else
            {
                sceCamera = true;
            }
        }
    }
    
    SceneValidator::Instance()->ValidateSceneAndShowErrors(editorScene);
    
    return retError;
}
コード例 #4
0
Entity *Scene::GetRootNode(const FilePath &rootNodePath)
{
//    ProxyNode * proxyNode = dynamic_cast<ProxyNode*>(scenes->FindByName(rootNodePath));
//    if (proxyNode)
//    {
//        return proxyNode->GetNode();
//    }
//    
//    String ext = FileSystem::Instance()->GetExtension(rootNodePath);
//    if(ext == ".sce")
//    {
//        SceneFile *file = new SceneFile();
//        file->SetDebugLog(true);
//        file->LoadScene(rootNodePath, this);
//        SafeRelease(file);
//    }
//    else if(ext == ".sc2")
//    {
//        SceneFileV2 *file = new SceneFileV2();
//        file->EnableDebugLog(true);
//        file->LoadScene(rootNodePath.c_str(), this);
//        SafeRelease(file);
//    }
//
//    proxyNode = dynamic_cast<ProxyNode*>(scenes->FindByName(rootNodePath));
//    if (proxyNode)
//    {
//        return proxyNode->GetNode();
//    }
//    return 0;
    
	Map<String, ProxyNode*>::const_iterator it;
	it = rootNodes.find(rootNodePath.GetAbsolutePathname());
	if (it != rootNodes.end())
	{
        ProxyNode * node = it->second;
		return node->GetNode();
	}
    
    if(rootNodePath.IsEqualToExtension(".sce"))
    {
        SceneFile *file = new SceneFile();
        file->SetDebugLog(true);
        file->LoadScene(rootNodePath, this);
        SafeRelease(file);
    }
    else if(rootNodePath.IsEqualToExtension(".sc2"))
    {
        uint64 startTime = SystemTimer::Instance()->AbsoluteMS();
        SceneFileV2 *file = new SceneFileV2();
        file->EnableDebugLog(false);
        file->LoadScene(rootNodePath, this);
        SafeRelease(file);
        uint64 deltaTime = SystemTimer::Instance()->AbsoluteMS() - startTime;
        Logger::Info("[GETROOTNODE TIME] %dms (%ld)", deltaTime, deltaTime);
    }
    
	it = rootNodes.find(rootNodePath.GetAbsolutePathname());
	if (it != rootNodes.end())
	{
        ProxyNode * node = it->second;
        //int32 nowCount = node->GetNode()->GetChildrenCountRecursive();
		return node->GetNode();
	}
    return 0;
}
コード例 #5
0
void AnimationTestScreen::LoadResources()
{
    RenderManager::Instance()->EnableOutputDebugStatsEveryNFrame(30);
    RenderManager::Instance()->SetFPS(30.0);
	scene = new Scene();
    
    
//    cam = new Camera(scene);
//    scene->AddCamera(cam);
//    //cam->SetFOV(75.0f);
//    cam->Setup(60.0f, 320.0f / 480.0f, 1.0f, 3000.0f, false);
//    cam->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
//    cam->SetDirection(Vector3(1.0f, 0.0f, 0.0f));
//    cam->SetUp(Vector3(0.0f, 0.0f, 1.0f));
//    scene->SetCurrentCamera(cam);

	SceneFile * file = new SceneFile();
	//file->SetDebugLog(true);
	file->LoadScene("~res:/Scenes/vit/scene.sce", scene);
    scene->AddNode(scene->GetRootNode("~res:/Scenes/vit/scene.sce"));

//	file->LoadScene("~res:/Scenes/garage_lit/hungar.sce", scene);
//  scene->AddNode(scene->GetRootNode("~res:/Scenes/garage_lit/hungar.sce"));
//    file->LoadScene("~res:/Scenes/level_test/level_test_3.sce", scene);
//    scene->AddNode(scene->GetRootNode("~res:/Scenes/level_test/level_test_3.sce"));
    
	SafeRelease(file);

//    LandscapeNode * node = new LandscapeNode(scene);
//    AABBox3 box(Vector3(198, 201, 0), Vector3(-206, -203, 22.7f));
    //box.min += cam->GetPosition();
    //box.max += cam->GetPosition();
    //box.min -= Vector3(512, 512, 0);
    //box.max = Vector3(512, 512, 0);
    
    //node->SetDebugFlags(LandscapeNode::DEBUG_DRAW_ALL);
//    node->BuildLandscapeFromHeightmapImage("~res:/Landscape/hmp2_1.png", box);
//    
//    Texture * tex = Texture::CreateFromFile("~res:/Landscape/tex3.png");
//    node->SetTexture(LandscapeNode::TEXTURE_BASE, tex);
//
//    Texture * detailTex = Texture::CreateFromFile("~res:/Landscape/detail.png");
//    node->SetTexture(LandscapeNode::TEXTURE_DETAIL, detailTex);
//
//    SafeRelease(detailTex);
//    SafeRelease(tex);
//    
//    node->SetName("landscapeNode");
//    scene->AddNode(node);


	currentTankAngle = 0.0f;
	inTouch = false;
	startRotationInSec = 0.0f;
	rotationSpeed = 8.0f;   
    

	scene3dView = 0;
    scene3dView = new UI3DView(Rect(0, 0, 480, 320));
    scene3dView->SetInputEnabled(false);
    scene3dView->SetScene(scene);
    
    cam = scene->GetCamera(0);
    cam->Setup(83.0f, 320.0f / 480.0f, 1.0f, 5000.0f); 

    //cam->Setup(60.0f, 
    scene->SetCurrentCamera(cam);
    AddControl(scene3dView);
    
    viewXAngle = 0;
    viewYAngle = 0; 
    
	positionJoypad = new UIJoypad(Rect(0, 320 - 80, 80, 80));
    positionJoypad->GetBackground()->SetSprite("~res:/Gfx/Joypad/joypad", 0);
    positionJoypad->SetStickSprite("~res:/Gfx/Joypad/joypad", 1);
	AddControl(positionJoypad);

    angleJoypad = new UIJoypad(Rect(480 - 80, 320 - 80, 80, 80));
    angleJoypad->GetBackground()->SetSprite("~res:/Gfx/Joypad/joypad", 0);
    angleJoypad->SetStickSprite("~res:/Gfx/Joypad/joypad", 1);
	AddControl(angleJoypad);
}