Exemplo n.º 1
0
        private void OnSpawnCubeEntity(object arg)
        {
            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                CMeshAsset cubeAsset = CImportManager.Instance.MeshImporter.LoadMeshAsync("TestResources/Cube.fbx");
                CEntity cubeEntity   = CEngine.Instance.CurrentWorld.SpawnEntity <CEntity>();
                cubeEntity.AddComponent <CSceneComponent>(true, true);
                CMeshComponent meshComponent = cubeEntity.AddComponent <CMeshComponent>(true, true);
                meshComponent.LocalPosition  = new Vector3(0, 0, 0.5f);
                meshComponent.Mesh           = cubeAsset;
                SEntityId id = new SEntityId(cubeEntity.Id);

                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    Instance.SetSelectedObject(new CEditableObject(id));
                }));
                UndoRedoUtility.Purge(null);
            });
        }
Exemplo n.º 2
0
        public void Init(CInitializer initializer)
        {
            UpdateScheduler = new CUpdateScheduler();

            CreateLevel();
            GameConsole.Init();
            PhysicsWorld.Init(this);


            #region Sponza
            CModelAsset sponzaAsset = CImportManager.Instance.MeshImporter.LoadModelAsync("TestResources/SponzaAtrium/sponza.obj");
            m_sponzaEntity = SpawnEntity <CEntity>();
            CModelComponent modelComponent = m_sponzaEntity.AddComponent <CModelComponent>(true, true);
            m_sponzaEntity.SetWorldPosition(new Vector3(0, -5, -5));
            m_sponzaEntity.SetWorldRotation(Quaternion.RotationAxis(Axis.Up, MathUtil.DegreesToRadians(90)));
            m_sponzaEntity.SetWorldScale(new Vector3(0.03f));
            CStaticModelColliderComponent staticModelCollider = m_sponzaEntity.AddComponent <CStaticModelColliderComponent>(true, true);
            staticModelCollider.ModelAsset  = sponzaAsset;
            modelComponent.Model            = sponzaAsset;
            m_sponzaEntity.IsPhysicsStatic  = true;
            m_sponzaEntity.IsPhysicsEnabled = true;
            #endregion

            CMeshAsset cubeAsset = CImportManager.Instance.MeshImporter.LoadMeshAsync("EngineResources/DefaultMeshes/DefaultCube.obj");

            CEntity floorEntity = SpawnEntity <CEntity>();
            floorEntity.AddComponent <CSceneComponent>(true, true);
            CMeshComponent floorMesh = floorEntity.AddComponent <CMeshComponent>(true, true);
            floorMesh.Mesh       = cubeAsset;
            floorMesh.LocalScale = new Vector3(500, 1, 500);
            CBoxColliderComponent floorCollider = floorEntity.AddComponent <CBoxColliderComponent>(true, true);
            floorCollider.Height = 1;
            floorCollider.Width  = 500;
            floorCollider.Length = 500;
            floorEntity.SetLocalPosition(new Vector3(0, -15, 0));
            floorEntity.IsPhysicsStatic         = true;
            floorEntity.IsPhysicsEnabled        = true;
            floorEntity.PhysicalStatic.Material = new Material(1, 0.8f, 1f);

            #region LightSetup
            m_lightEntity = SpawnEntity <CEntity>();
            m_lightEntity.AddComponent <CSceneComponent>(true, true);

            CDirectionalLightComponent directionalLight = m_lightEntity.AddComponent <CDirectionalLightComponent>(true, true);
            directionalLight.LocalRotation = MathUtilities.CreateLookAtQuaternion(Vector3.Normalize(new Vector3(0.2f, -0.5f, 0.2f)), Axis.Up);
            directionalLight.LightColor    = Color4.White * 0.8f;

            CSpotLightComponent spotLight = m_lightEntity.AddComponent <CSpotLightComponent>(true, true);
            spotLight.ConstantAttenuation  = 0.01f;
            spotLight.LinearAttenuation    = 0.3f;
            spotLight.QuadraticAttenuation = 0.0f;
            spotLight.Enabled    = true;
            spotLight.SpotAngle  = MathUtil.DegreesToRadians(30.0f);
            spotLight.LightColor = new Color4(0.1f, 0.8f, 0.1f, 1.0f);
            spotLight.Range      = 100.0f;
            Quaternion deltaRotation = Quaternion.RotationAxis(Axis.Right, MathUtil.DegreesToRadians(10));
            spotLight.LocalRotation = deltaRotation;
            spotLight.LocalPosition = new Vector3(0, 1, -4);

            CPointLightComponent pointLight1 = m_lightEntity.AddComponent <CPointLightComponent>(true, true);
            pointLight1.ConstantAttenuation = 1;
            pointLight1.LinearAttenuation   = 0.2f;
            pointLight1.Enabled             = true;
            pointLight1.Range         = 100.0f;
            pointLight1.LightColor    = new Color4(0.8f, 0.1f, 0.1f, 1.0f);
            pointLight1.LocalPosition = new Vector3(0, 0, 3.0f);

            CPointLightComponent pointLight2 = m_lightEntity.AddComponent <CPointLightComponent>(true, true);
            pointLight2.ConstantAttenuation = 1;
            pointLight2.LinearAttenuation   = 0.4f;
            pointLight2.Enabled             = true;
            pointLight2.Range         = 100.0f;
            pointLight2.LightColor    = new Color4(0.1f, 0.1f, 0.8f, 1.0f);
            pointLight2.LocalPosition = new Vector3(0, -3, -8.0f);

            CAmbientLightComponent ambientLight = m_lightEntity.AddComponent <CAmbientLightComponent>(true, true);
            ambientLight.LightColor = Color4.White * 0.15f;
            #endregion
        }