Example #1
0
    void DiK2World::Load(const DiString& path)
    {
        DI_LOG("Loading world: %s", path.c_str());

        DiK2WorldSerial serial;
        serial.Load(path,this);
        mRootNode->AttachObject(mTerrain);
        
        // sun light
        mSun = make_shared<DiDirLight>();
        DiSceneManager* sm = DiBase::Driver->GetSceneManager();
        DiCullNode* dirNode = sm->GetRootNode()->CreateChild();
        dirNode->AttachObject(mSun);
        mSun->SetColor(DiColor());
        
        DiRadian altitude(DiDegree(mConfigs.mSunAltitude));
        DiVec3 dir(0,-DiMath::Sin(altitude),DiMath::Cos(altitude));
        
        DiRadian azimuth(DiDegree(mConfigs.mSunAzimuth));
        DiQuat rot(azimuth, DiVec3::UNIT_Y);
        dir = rot * dir;
        mSun->SetDirection(dir);
        
        sm->SetAmbientColor(DiColor());
    
        Demi::DiRenderBatchGroup* group = Driver->GetPipeline()->GetBatchGroup(Demi::BATCH_MODEL);
        group->SetPreProcess([this](){
            Driver->GetPipeline()->GetShaderEnvironment()->globalAmbient = mConfigs.mEntityAmbient;
            Driver->GetPipeline()->GetShaderEnvironment()->dirLightsColor[0] = mConfigs.mEntitySunColor;
        });
    }
Example #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));
    }
Example #3
0
void InitScene()
{
	DiSceneManager* sm = DiBase::Driver->GetSceneManager();

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

	DiDirLight* dirlight = sm->CreateDirLight();
	dirlight->SetColor(DiColor());
	dirlight->SetDirection(DiVec3(1,1,2).normalisedCopy());

	AddMeshes();

	SetupPostEffects();
}
		uint32 toColourARGB(const Colour& _colour)
		{
            return DiBase::Driver->GetNativeColor(DiColor(_colour.red, _colour.green, _colour.blue, _colour.alpha));
// 			uint32 val32 = uint8(_colour.alpha * 255);
// 			val32 <<= 8;
// 			val32 += uint8(_colour.red * 255);
// 			val32 <<= 8;
// 			val32 += uint8(_colour.green * 255);
// 			val32 <<= 8;
// 			val32 += uint8(_colour.blue * 255);
// 			return val32;
		}
Example #5
0
    DiTexture::DiTexture(const DiString& name)
        :DiAsset(name)
        , mFilter(FILTER_DEFAULT)
        , mTextureDrv(nullptr)
        , mResUsage(RU_NONE)
        , mAutoGenerateMipmap(true)
    {

        mAddressingU   = AM_WRAP;
        mAddressingV   = AM_WRAP;
        mBorderColor   = DiColor(0, 0, 0, 0);
        mPixelFormat   = PIXEL_FORMAT_MAX;
                       
        mTextureType   = TEXTURE_2D;
        mUsage         = TU_TEXURE;
                       
        mTextureDrv    = Driver ? Driver->CreateTextureDriver(this) : nullptr;
        mRenderTarget  = nullptr;
                       
        mWidth         = 0;
        mHeight        = 0;
        mNumLevels     = 1;
        mUvSet         = 0;

        mUScroll       = 0;
        mVScroll       = 0;
        mRotateSpeed   = 0;
        mRotateDegree  = 0;
        mUScale        = 0;
        mVScale        = 0;
        mUTrans        = 0;
        mVTrans        = 0;
        mRotation      = 0;
        mUScale        = 1;
        mVScale        = 1;

        mNeedRecalcTexMat = false;

        mViewportScale = DiVec2::UNIT_SCALE;

        mAdaptedRT     = nullptr;

        if (Driver)
            Driver->AddDeviceLostListener(this);
    }
Example #6
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);
}
Example #7
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;
    }
}
Example #8
0
    void InitFx_Repeater01()
    {
        // effect
        auto _ps = DiEffectManager::GetInstance().CreateParticleSystemTemplate("Fx_repeater1");
        std::shared_ptr<DiTransformUnit> ps(_ps);

        _ps->Start();
        {
            DiParticleElement* element = _ps->CreateElement();
            element->SetRenderer("Billboard");
            auto emitter = element->CreateEmitter("Box");
            
            auto mat = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_USE_COLOR | SHADER_FLAG_USE_MAP);
            mat->GetShaderParameter()->WriteTexture2D("map", "glow_01.dds");
            mat->SetBlendMode(BLEND_ADD);
            mat->SetDepthWrite(false);
            element->SetMaterialName(mat->GetName());
            
            ((DiBoxEmitter*)emitter)->SetWidth(50);
            ((DiBoxEmitter*)emitter)->SetHeight(70);
            ((DiBoxEmitter*)emitter)->SetDepth(50);
            emitter->position = DiVec3(0, 165, 5);
            
            auto rt = DI_NEW DiAttributeFixed();
            rt->SetValue(30);
            emitter->SetDynEmissionRate(rt);
            
            auto spd = DI_NEW DiAttributeFixed();
            spd->SetValue(20);
            emitter->SetDynVelocity(spd);
            
            auto ttl = DI_NEW DiAttributeRandom();
            ttl->SetMinMax(1, 2);
            emitter->SetDynTotalTimeToLive(ttl);
            
            auto sz = DI_NEW DiAttributeRandom();
            sz->SetMinMax(20, 40);
            emitter->SetDynParticleAllDimensions(sz);
            
            DiColorController* colorCtrl = (DiColorController*)element->CreateController("Color");
            colorCtrl->AddColour(0, DiColor::Black);
            colorCtrl->AddColour(0.5f, DiColor(0.25f, 1, 0.5f));
            colorCtrl->AddColour(1, DiColor::Black);
        }
        {
            DiParticleElement* element = _ps->CreateElement();
            element->SetRenderer("Billboard");
            auto emitter = element->CreateEmitter("Box");
            
            auto mat = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_USE_COLOR | SHADER_FLAG_USE_MAP);
            auto texture = mat->GetShaderParameter()->WriteTexture2D("map", "mysticenergy2.dds");
            mat->SetBlendMode(BLEND_ADD);
            mat->SetDepthWrite(false);
            element->SetMaterialName(mat->GetName());
            texture->SetAddressing(AM_CLAMP);
            
            ((DiBoxEmitter*)emitter)->SetWidth(50);
            ((DiBoxEmitter*)emitter)->SetHeight(70);
            ((DiBoxEmitter*)emitter)->SetDepth(50);
            emitter->position = DiVec3(0, 165, 5);
            
            auto rt = DI_NEW DiAttributeFixed();
            rt->SetValue(6);
            emitter->SetDynEmissionRate(rt);
            
            auto spd = DI_NEW DiAttributeFixed();
            spd->SetValue(20);
            emitter->SetDynVelocity(spd);
            
            auto ttl = DI_NEW DiAttributeRandom();
            ttl->SetMinMax(1, 2);
            emitter->SetDynTotalTimeToLive(ttl);
            
            auto sz = DI_NEW DiAttributeRandom();
            sz->SetMinMax(20, 40);
            emitter->SetDynParticleAllDimensions(sz);
            
            DiColorController* colorCtrl = (DiColorController*)element->CreateController("Color");
            colorCtrl->AddColour(0, DiColor::Black);
            colorCtrl->AddColour(0.5f, DiColor(0.25f, 1, 0.5f));
            colorCtrl->AddColour(1, DiColor::Black);
            
            DiTextureRotatorController* texrotCtrl = (DiTextureRotatorController*)element->CreateController("TextureRotator");
            texrotCtrl->SetUseOwnRotationSpeed(true);
            auto rotspeed = DI_NEW DiAttributeRandom();
            rotspeed->SetMinMax(-100, 100);
            texrotCtrl->SetRotationSpeed(rotspeed);
            auto rot = DI_NEW DiAttributeRandom();
            rot->SetMinMax(0, 300);
            texrotCtrl->SetRotation(rot);
        }
        
        // create the editor object from the particle system
        DiEditorManager::Get()->LoadParticleSystem(_ps);
    }
Example #9
0
    void HonFxerApp::OpenImpl()
    {
        DemiDemo::OpenImpl();
        DI_INSTALL_PLUGIN(DiFx);
        DI_INSTALL_PLUGIN(DiK2);

        Driver->GetMainRenderWindow()->SetForceRenderToCanvas(true);
        
        DiPostEffectManager* peMgr = DiBase::Driver->GetMainRenderWindow()->GetPostEffectManager();
        peMgr->SetManualOutputTarget(DiBase::Driver->GetMainRenderWindow()->GetSceneCanvas());

        DiBase::Driver->GetMainRenderWindow()->GetRenderBuffer()->SetClearColor(DiColor(0.2f, 0.2f, 0.2f));
        DiBase::Driver->GetMainRenderWindow()->GetSceneCanvas()->SetClearColor(DiColor(0.2f, 0.2f, 0.2f));

        DiSceneManager* sm = DiBase::Driver->GetSceneManager();
        sm->SetAmbientColor(DiColor(0.3f, 0.3f, 0.3f));
        DiDirLightPtr dirlight;
        dirlight = make_shared<DiDirLight>();
        DiCullNode* dirNode = sm->GetRootNode()->CreateChild();
        dirNode->AttachObject(dirlight);
        dirlight->SetColor(DiColor());
        dirlight->SetDirection(DiVec3(0, -0.3f, -0.4).normalisedCopy());

        //////////////////////////////////////////////////////////////////////////
        
        new CommandManager();
        CommandManager::getInstance().initialise();
        
        new HotKeyManager();
        HotKeyManager::getInstance().initialise();


        MyGUI::FactoryManager::getInstance().registerFactory<MyGUI::RTTLayer>("Layer");
        MyGUI::FactoryManager::getInstance().registerFactory<MyGUI::FilterNone>("BasisSkin");
        
        MyGUI::ResourceManager::getInstance().load("FxEditorLayers.xml");
        MyGUI::ResourceManager::getInstance().load("FxToolbar.xml");
        MyGUI::ResourceManager::getInstance().load("FxHotkeys.xml");

        DiString userSettings = DiPathLib::GetApplicationPath() + "FxSettings.xml";
        new SettingsManager();
        SettingsManager::getInstance().initialise(userSettings.c_str());

        std::string mLocale = "English";
        MyGUI::LanguageManager::getInstance().setCurrentLanguage(mLocale);

        new MessageBoxManager();
        MessageBoxManager::getInstance().initialise();

        new ColourManager();
        ColourManager::getInstance().initialise();

        MyGUI::ResourceManager::getInstance().load("FxInitialise.xml");

        MyGUI::FactoryManager& factory = MyGUI::FactoryManager::getInstance();
        factory.registerFactory<MyGUI::TreeControl>("Widget");
        factory.registerFactory<MyGUI::TreeControlItem>("Widget");
        MyGUI::ResourceManager::getInstance().load("TreeControlSkin.xml");
        MyGUI::ResourceManager::getInstance().load("TreeItemIcons.xml");

        CommandManager::getInstance().registerCommand("Command_Quit", MyGUI::newDelegate(this, &HonFxerApp::Command_QuitApp));
        CommandManager::getInstance().registerCommand("Command_Export", MyGUI::newDelegate(this, &HonFxerApp::Command_Export));
        CommandManager::getInstance().registerCommand("Command_ResLocation", MyGUI::newDelegate(this, &HonFxerApp::Command_ResLocation));
        CommandManager::getInstance().registerCommand("Command_GameLocation", MyGUI::newDelegate(this, &HonFxerApp::Command_GameLocation));
        CommandManager::getInstance().registerCommand("Command_ViewHelp", MyGUI::newDelegate(this, &HonFxerApp::Command_ViewHelp));

        mMainPane = new MainPaneControl();

        new DialogManager();
        DialogManager::getInstance().initialise();

        DI_NEW DiEditorManager();

#if 0
        DiBase::CommandMgr->ExecuteCommand("selectLast");
        
        DiBase::CommandMgr->ExecuteCommand("createChild ParticleSystem");
        DiBase::CommandMgr->ExecuteCommand("selectLast");
        
        DiBase::CommandMgr->ExecuteCommand("createChild ParticleElement");
        DiBase::CommandMgr->ExecuteCommand("selectLast");
        
        DiBase::CommandMgr->ExecuteCommand("createChild PointEmitter");
        DiBase::CommandMgr->ExecuteCommand("selectLast");
#endif
        
        mSetResLocWindow = new SetResLocWindow();
        mSetResLocWindow->eventEndDialog = MyGUI::newDelegate(this, &HonFxerApp::NotifySetResLocWindowEndDialog);
        
        mSetGameLocWindow = new SetGameLocWindow();
        mSetGameLocWindow->eventEndDialog = MyGUI::newDelegate(this, &HonFxerApp::NotifySetGameLocWindowEndDialog);
        
        mCameraHelper->UseShiftKeyToOrbit(true);
        
        //InitFx_Repeater01();
    }