Beispiel #1
0
    DiMaterialPtr DiMaterial::Clone( const DiString& newname )
    {
        DiMaterialPtr mat = DiAssetManager::GetInstance().CreateManualAsset<DiMaterial>(newname);

        mat->SetShaderFlag(mat->mShaderFlag);
        mat->LoadShader(mVertexShader->GetName().ExtractBaseName(),
            mPixelShader->GetName().ExtractBaseName());

        mat->mCullMode        = mCullMode;
        mat->mDepthWrite      = mDepthWrite;
        mat->mDepthCheck      = mDepthCheck;
        mat->mWireframe       = mWireframe;
        mat->mForceWireframe  = mForceWireframe;
        mat->mBlendMode       = mBlendMode;
        mat->mInstanceState   = mInstanceState;
        mat->mOpacity         = mOpacity;
        mat->mShininess       = mShininess;
        mat->mAmbient         = mAmbient;
        mat->mDiffuse         = mDiffuse;
        mat->mSpecular        = mSpecular;

        mShaderParameter->CloneVarsTo(mat->GetShaderParameter());
        
        return mat;
    }
Beispiel #2
0
    DiEditorManager::DiEditorManager()
    {
        sEditorMgr = this;
        
        InitFactories();
        InitCommands();

        mRootObject = CreateEditorObject("Base");
        mRootObject->OnCreate();
        mRootObject->OnCreateUI();

        DiMaterialPtr dbgHelperMat = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_USE_COLOR);
        dbgHelperMat->SetDepthCheck(false);
        mGridPlane = make_shared<DiGridPlane>(30, 10, DiColor(0.1f, 0.1f, 0.1f), DiColor(0.5f, 0.5f, 0.5f));
        mGridPlane->SetMaterial(dbgHelperMat);
        Driver->GetSceneManager()->GetRootNode()->AttachObject(mGridPlane);
        
        CommandManager::getInstance().registerCommand("Command_ToolPlay", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolPlay));
        CommandManager::getInstance().registerCommand("Command_ToolPause", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolPause));
        CommandManager::getInstance().registerCommand("Command_ToolStop", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolStop));
        CommandManager::getInstance().registerCommand("Command_ToolNewFile", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolNew));
        CommandManager::getInstance().registerCommand("Command_ToolSaveFile", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolSave));
        CommandManager::getInstance().registerCommand("Command_ToolOpenFile", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolOpen));
        CommandManager::getInstance().registerCommand("Command_ToolReset", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolReset));
        CommandManager::getInstance().registerCommand("Command_ToolSelect", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolSelect));
        CommandManager::getInstance().registerCommand("Command_ToolMove", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolMove));
        CommandManager::getInstance().registerCommand("Command_ToolRotate", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolRotate));
        CommandManager::getInstance().registerCommand("Command_ToolScale", MyGUI::newDelegate(this, &DiEditorManager::Command_ToolScale));
    }
Beispiel #3
0
    DiMaterialPtr DiMaterial::QuickCreate(const DiString& name, const DiString& vs, const DiString& ps, uint64 flag )
    {
        DiMaterialPtr mat = DiAssetManager::GetInstance().CreateOrReplaceAsset<DiMaterial>(name);

        mat->SetShaderFlag(flag);
        mat->LoadShader(vs,ps);

        return mat;
    }
Beispiel #4
0
    DiMaterialPtr DiMaterial::QuickCreate( const DiString& vs, const DiString& ps , uint64 flag)
    {
        static int quickcreateID = 0;
        DiString name;
        name.Format("quick_%d", quickcreateID++);
        DiMaterialPtr mat = DiAssetManager::GetInstance().CreateOrReplaceAsset<DiMaterial>(name);

        mat->SetShaderFlag(flag);
        mat->LoadShader(vs,ps);

        return mat;
    }
Beispiel #5
0
void ModelConverter::WriteSimpleMaterial( int boneWeightsNum, const DiString& filename )
{
	DiMaterialPtr mat = Demi::DiAssetManager::GetInstancePtr(
		)->CreateOrReplaceAsset<DiMaterial>("_tempSimple");

	if (boneWeightsNum == 0)
	{
		mat->LoadVertexShader(DiMaterialDefine::STATIC_MESH_SHADER_NAME);
	}
	else if (boneWeightsNum == 1)
	{
        mat->LoadVertexShader(DiMaterialDefine::SKINING_1_WEIGHT_SHADER);
	}
	else if (boneWeightsNum == 2)
	{
        mat->LoadVertexShader(DiMaterialDefine::SKINING_2_WEIGHTS_SHADER);
	}
	else
	{
        mat->LoadVertexShader(DiMaterialDefine::SKINING_4_WEIGHTS_SHADER);
	}

    mat->LoadPixelShader(DiMaterialDefine::DIFFUSE_PIXEL_SHADER);

	Demi::DiShaderParameter* materialIns = mat->GetShaderParameter();
	materialIns->WriteTexture2D("diffuseTexture","_default.dds");

	DiMaterialSerializer mas;
	mas.SaveMaterial(filename,mat.get());
}
Beispiel #6
0
    DiK2World::DiK2World()
        : mRootNode(nullptr)
    {
        mRootNode = Driver->GetSceneManager()->GetRootNode()->CreateChild();

#ifdef _DEBUG_CLIFF_POS
        mDebugger = make_shared<DiDebugHelper>();
        DiMaterialPtr helpermat = DiMaterial::QuickCreate(
            "basic_v", "basic_p", SHADER_FLAG_USE_COLOR);
        helpermat->SetDepthCheck(false);
        mDebugger->SetMaterial(helpermat);
        mRootNode->AttachObject(mDebugger);
#endif

    }
Beispiel #7
0
    DiString DiInstanceManager::SetupMaterial( const DiString& materialName )
    {
        DiString insmaterial = materialName + ".instance";

        DiMaterialPtr nmt = DiAssetManager::GetInstance().FindAsset<DiMaterial>(insmaterial);
        if ( nmt )
        {
            return insmaterial;
        }
        else
        {
            DiMaterialPtr mt = DiAssetManager::GetInstance().GetAsset<DiMaterial>(materialName);
            DiMaterialPtr newmt = mt->Clone(insmaterial);
            newmt->SetInstanceType(mInstancingTechnique);
            return insmaterial;
        }
    }
Beispiel #8
0
    Demi::DiMaterialPtr DiMaterial::Clone()
    {
        DiMaterialPtr mat = QuickCreate(mVertexShader->GetName().ExtractBaseName(),
            mPixelShader->GetName().ExtractBaseName(), mShaderFlag);

        mat->mCullMode        = mCullMode;
        mat->mDepthWrite      = mDepthWrite;
        mat->mDepthCheck      = mDepthCheck;
        mat->mWireframe       = mWireframe;
        mat->mForceWireframe  = mForceWireframe;
        mat->mBlendMode       = mBlendMode;
        mat->mInstanceState   = mInstanceState;
        mat->mOpacity         = mOpacity;
        mat->mShininess       = mShininess;
        mat->mAmbient         = mAmbient;
        mat->mDiffuse         = mDiffuse;
        mat->mSpecular        = mSpecular;

        mShaderParameter->CloneVarsTo(mat->GetShaderParameter());

        return mat;
    }
Beispiel #9
0
void InitScene()
{
    DiSceneManager* sm = DiBase::Driver->GetSceneManager();
    sm->SetAmbientColor(DiColor(0.6f, 0.6f, 0.6f));
    
    float scale = 0.5f;
    DiDirLightPtr dirlight;
    dirlight = make_shared<DiDirLight>();
    DiCullNode* dirNode = sm->GetRootNode()->CreateChild();
    dirNode->AttachObject(dirlight);
    dirlight->SetColor(DiColor(0.8f,0.8f,0.8f));
    dirlight->SetDirection(DiVec3(0.3f,-0.7f,0.4).normalisedCopy());
    //dirlight->InitForShadowCasting(sm, ShadowTextureConfig(1024,1024,PF_A32B32G32R32F));
    
    auto pos = DiVec3(150,275,130)*2;
    dirNode->SetPosition(pos);
    
    DiCullNode* spotNode = sm->GetRootNode()->CreateChild();
    DiSpotLightPtr sptLt = make_shared<DiSpotLight>();
    spotNode->AttachObject(sptLt);
    //spotNode->SetPosition(50, 100, 40);
    spotNode->SetPosition(pos);
    sptLt->SetDirection((-pos).normalisedCopy());
    sptLt->SetRange( DiDegree(80), DiDegree(90) );
    sptLt->InitForShadowCasting(sm, ShadowTextureConfig(1024,1024,PF_A32B32G32R32F));
    
    sptLt->mShadowCameraNear = 50;
    sptLt->mShadowCameraFar = 200;
    sptLt->mShadowCameraFov = 50;
    sptLt->_UpdateShadowCamera();
    
    DiDebugHelperPtr dbghelper;
    auto mat = DiMaterial::QuickCreate("lambert_v", "lambert_p", SHADER_FLAG_SHADOW_RECEIVER);
    mat->SetAmbient(DiColor(0.8f, 0.8f, 0.8f));
    mat->SetDiffuse(DiColor(0.8f, 0.8f, 0.8f));

    dbghelper = make_shared<DiDebugHelper>();
    sm->GetRootNode()->AttachObject(dbghelper);
    DiMaterialPtr helpermat = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_USE_COLOR);
    helpermat->SetDepthCheck(false);
    dbghelper->SetMaterial(helpermat);
    //dbghelper->AddFrustum(dirlight->GetShadowCamera(0), DiColor::Red);

    hp = dbghelper.get();
    lt = sptLt.get();

#if 0
    DiSimpleShapePtr plane = make_shared<DiSimpleShape>();
    plane->SetShadowCastEnable(false);
    plane->CreatePlane(600, 600);
    plane->SetMaterial(mat);
    plane->GetMaterial()->SetDiffuse(DiColor::White);
    DiCullNode* planeNode = sm->GetRootNode()->CreateChild();
    planeNode->AttachObject(plane);
    planeNode->Translate(0, 0, 0);

    const int size = 1;
    for (int i = -size; i <= size; i++)
    {
        for (int j = -size; j <= size; j++)
        {
            DiMaterialPtr mat = DiMaterial::QuickCreate("lambert_v", "lambert_p", SHADER_FLAG_SKINNED | SHADER_FLAG_SHADOW_RECEIVER);
            mat->SetDiffuse(DiColor(1, 1, 1));
            mat->SetAmbient(DiColor(0.7f, 0.7f, 0.7f));
            
            DiString name;
            name.Format("md_%d_%d", i, j);
            DiAnimModelPtr model = make_shared<DiAnimModel>(name, "robot.model", "robot.motion");
            //DiModelPtr model = make_shared<DiModel>(name, "robot.model");
            model->SetMaterial(mat);
            model->SetShadowCastEnable(true);
            
            model->SetAutoUpdateAnims(true);
            model->GetClipSet()->GetClipController("Walk")->SetEnabled(true);
            
            DiCullNode* cullnode = sm->GetRootNode()->CreateChild();
            cullnode->AttachObject(model);
            cullnode->SetPosition(i * 140.0f, 0, j * 140.0f);
        }
    }
    
#else
    
    DiSimpleShapePtr plane = make_shared<DiSimpleShape>();
    plane->SetShadowCastEnable(false);
    plane->CreatePlane(300, 300);
    plane->SetMaterial(mat);
    plane->GetMaterial()->SetDiffuse(DiColor::White);
    DiCullNode* planeNode = sm->GetRootNode()->CreateChild();
    planeNode->AttachObject(plane);

    DiMaterialPtr m = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_SHADOW_RECEIVER);
    m->SetDiffuse(DiColor(0.9f, 0.9f, 0.9f));
    
    DiSimpleShapePtr box = make_shared<DiSimpleShape>();
    box->SetShadowCastEnable(true);
    box->CreateBox(10);
    box->SetMaterial(m);
    DiCullNode* cullnode = sm->GetRootNode()->CreateChild();
    cullnode->SetPosition(0,5,0);
    cullnode->AttachObject(box);

#endif

    //SetupScene();

    DiCamera* camera = sm->GetCamera();
    camera->SetNearClipDistance(5);
    camera->SetFarClipDistance(5000);
}
Beispiel #10
0
void InitScene()
{
	DiSceneManager* sm = DiBase::Driver->GetSceneManager();

    mat = DiMaterial::QuickCreate("lambert_v", "lambert_p");
    mat->SetDiffuse(DiColor::White);

    sm->SetAmbientColor(DiColor(0.1f, 0.1f, 0.1f, 0.1f));

    DiDirLightPtr dirlight = make_shared<DiDirLight>();
    sm->AttachObject(dirlight);
    dirlight->SetColor(DiColor());
    dirlight->SetDirection(DiVec3(-1, -1, -2).normalisedCopy());

    int amount = 2;

    DiCullNode* parent = sm->GetRootNode();

    for (int i = 0; i < amount; i++) 
    {
        DiSimpleShapePtr model = make_shared<DiSimpleShape>();
        model->CreateBox(10);
        model->SetMaterial(mat);

        DiCullNode* node = parent->CreateChild();
        node->AttachObject(model);
        node->Translate(10, 0, 0);
        nodes.push_back(node);
        parent = node;
    }

    parent = sm->GetRootNode();
    for (int i = 0; i < amount; i++) 
    {
        DiSimpleShapePtr model = make_shared<DiSimpleShape>();
        model->CreateBox(10);
        model->SetMaterial(mat);

        DiCullNode* node = parent->CreateChild();
        node->AttachObject(model);
        node->Translate(-10, 0, 0);
        nodes.push_back(node);
        parent = node;
    }

    parent = sm->GetRootNode();
    for (int i = 0; i < amount; i++) 
    {
        DiSimpleShapePtr model = make_shared<DiSimpleShape>();
        model->CreateBox(10);
        model->SetMaterial(mat);

        DiCullNode* node = parent->CreateChild();
        node->AttachObject(model);
        node->Translate(0, 10, 0);
        nodes.push_back(node);
        parent = node;
    }

    parent = sm->GetRootNode();
    for (int i = 0; i < amount; i++) 
    {
        DiSimpleShapePtr model = make_shared<DiSimpleShape>();
        model->CreateBox(10);
        model->SetMaterial(mat);

        DiCullNode* node = parent->CreateChild();
        node->AttachObject(model);
        node->Translate(0, -10, 0);
        nodes.push_back(node);
        parent = node;
    }

    parent = sm->GetRootNode();
    for (int i = 0; i < amount; i++) 
    {
        DiSimpleShapePtr model = make_shared<DiSimpleShape>();
        model->CreateBox(10);
        model->SetMaterial(mat);

        DiCullNode* node = parent->CreateChild();
        node->AttachObject(model);
        node->Translate(0, 0, 10);
        nodes.push_back(node);
        parent = node;
    }

    parent = sm->GetRootNode();
    for (int i = 0; i < amount; i++)
    {
        DiSimpleShapePtr model = make_shared<DiSimpleShape>();
        model->CreateBox(10);
        model->SetMaterial(mat);

        DiCullNode* node = parent->CreateChild();
        node->AttachObject(model);
        node->Translate(0, 0, -10);
        nodes.push_back(node);
        parent = node;
    }
}