예제 #1
0
        public override void Load()
        {
            _aabbGameElement = new GameElement("aabb__sceneEditorElement");
            _aabbGameElement.AttachComponent(new Material()
            {
                HasColorAmbient = true,
                ColorAmbient    = Color4.White,
                HasColorDiffuse = true,
                ColorDiffuse    = Color4.White,
                ShaderProgram   = new DiffuseShaderProgram()
            });
            _aabbGameElement.AttachComponent(new MeshRenderer());

            _initMoverAxis();
        }
예제 #2
0
        protected override void OnAddGameElement(GameElement gameElement)
        {
            if (!gameElement.Name.EndsWith("__sceneEditorElement") && gameElement.HasComponent(out MeshRenderer renderer))
            {
                var points = new Vector3f[renderer.MeshFilter.Entry.NumVertices];

                for (int i = 0; i < points.Length; i++)
                {
                    points[i] = renderer.MeshFilter.Mesh.MeshData.Positions[renderer.MeshFilter.Entry.BaseVertex + i];
                }

                var aabb = BoundingBox.CreateFromPoints(points);
                _boundingBoxes.Add(gameElement, new BoundingBox(aabb.Min * 1.05f, aabb.Max * 1.05f));

                var pickable = new PickableObject();
                pickable.Picking += (p) =>
                {
                    SelectedElement = gameElement;
                };

                gameElement.AttachComponent(pickable);
            }

            base.OnAddGameElement(gameElement);
        }
예제 #3
0
        private GameElement _appendGameElement(GameElement element, Node node)
        {
            var _tempGameMesh = new GameElement(node.Name);

            var meshTrasform = new MeshTransformation(node.Transform);

            _tempGameMesh.LocalTransform.Translation = meshTrasform.Position;
            _tempGameMesh.LocalTransform.Rotation    = meshTrasform.Rotation;
            _tempGameMesh.LocalTransform.Scale       = meshTrasform.Scale;

            if (node.HasMeshes)
            {
                if (node.MeshCount == 1)
                {
                    _tempGameMesh.AttachComponent(_materials[node.MeshIndices[0]]);
                    _tempGameMesh.AttachComponent(new MeshRenderer(_meshes[node.MeshIndices[0]]));
                }
                else
                {
                    for (int i = 0; i < node.MeshCount; i++)
                    {
                        var _subMesh = new GameElement(node.Name);
                        _subMesh.AttachComponent(_materials[node.MeshIndices[i]]);
                        _subMesh.AttachComponent(new MeshRenderer(_meshes[node.MeshIndices[i]]));
                        _tempGameMesh.AddChild(_subMesh);
                    }
                }
            }

            if (node.HasChildren)
            {
                for (int i = 0; i < node.ChildCount; i++)
                {
                    _appendGameElement(_tempGameMesh, node.Children[i]);
                }
            }

            if (element != null)
            {
                element.AddChild(_tempGameMesh);
            }

            return(_tempGameMesh);
        }
예제 #4
0
        /// <summary>
        /// Creates a new scene.
        /// </summary>
        public Scene()
        {
            GameElement _dummyCamera = new GameElement("_dummy_generated_camera");

            _dummyCamera.AttachComponent(Camera.None);

            // Initializing
            _gameElements     = new GameElementCollection();
            _lights           = new GameElementCollection();
            _cameras          = new GameElementCollection();
            _audioSources     = new GameElementCollection();
            _audioReverbZones = new GameElementCollection();
            _audioListener    = null;
            _primaryCamera    = _dummyCamera;

            // Setup Physics
            _setupPhysics();
        }
예제 #5
0
        private void _initMoverAxis()
        {
            _axisXMoverMaterial = new Material()
            {
                HasColorAmbient = true,
                ColorAmbient    = Color4.Red,
                HasColorDiffuse = true,
                ColorDiffuse    = Color4.Red,
                ShaderProgram   = new ObjectAxisShader()
            };

            _axisYMoverMaterial = new Material()
            {
                HasColorAmbient = true,
                ColorAmbient    = Color4.Green,
                HasColorDiffuse = true,
                ColorDiffuse    = Color4.Green,
                ShaderProgram   = new ObjectAxisShader()
            };

            _axisZMoverMaterial = new Material()
            {
                HasColorAmbient = true,
                ColorAmbient    = Color4.Blue,
                HasColorDiffuse = true,
                ColorDiffuse    = Color4.Blue,
                ShaderProgram   = new ObjectAxisShader()
            };

            var arrow = MeshImporter.ImportMesh("Assets/alienEngineSceneEditorObjectMover.obj");

            _axisXMoverMeshRenderer = new MeshRenderer()
            {
                Visible    = false,
                MeshFilter = new MeshFilter(arrow, arrow.RootNode.Meshes[0])
            };

            _axisYMoverMeshRenderer = new MeshRenderer()
            {
                Visible    = false,
                MeshFilter = new MeshFilter(arrow, arrow.RootNode.Meshes[0])
            };

            _axisZMoverMeshRenderer = new MeshRenderer()
            {
                Visible    = false,
                MeshFilter = new MeshFilter(arrow, arrow.RootNode.Meshes[0])
            };

            _sceneEditorObjectAxisMoverX = new GameElement("axisMoverX__sceneEditorElement");
            _sceneEditorObjectAxisMoverY = new GameElement("axisMoverY__sceneEditorElement");
            _sceneEditorObjectAxisMoverZ = new GameElement("axisMoverZ__sceneEditorElement");

            PickableObject xPicker = new PickableObject();

            xPicker.Hover     += _xPickerOnHover;
            xPicker.LostHover += _xPickerOnLostHover;
            xPicker.Picking   += _xPickerOnPicking;
            xPicker.Unpick    += _xPickerOnUnpick;

            PickableObject yPicker = new PickableObject();

            yPicker.Hover     += _yPickerOnHover;
            yPicker.LostHover += _yPickerOnLostHover;
            yPicker.Picking   += _yPickerOnPicking;
            yPicker.Unpick    += _yPickerOnUnpick;

            PickableObject zPicker = new PickableObject();

            zPicker.Hover     += _zPickerOnHover;
            zPicker.LostHover += _zPickerOnLostHover;
            zPicker.Picking   += _zPickerOnPicking;
            zPicker.Unpick    += _zPickerOnUnpick;

            _sceneEditorObjectAxisMoverX.AttachComponent(xPicker);
            _sceneEditorObjectAxisMoverX.AttachComponent(_axisXMoverMaterial);
            _sceneEditorObjectAxisMoverX.AttachComponent(_axisXMoverMeshRenderer);

            _sceneEditorObjectAxisMoverY.AttachComponent(yPicker);
            _sceneEditorObjectAxisMoverY.AttachComponent(_axisYMoverMaterial);
            _sceneEditorObjectAxisMoverY.AttachComponent(_axisYMoverMeshRenderer);

            _sceneEditorObjectAxisMoverZ.AttachComponent(zPicker);
            _sceneEditorObjectAxisMoverZ.AttachComponent(_axisZMoverMaterial);
            _sceneEditorObjectAxisMoverZ.AttachComponent(_axisZMoverMeshRenderer);

            _sceneEditorObjectAxisMoverX.LocalTransform.SetRotationZ(-90.0f);
            _sceneEditorObjectAxisMoverZ.LocalTransform.SetRotationX(+90.0f);

            _sceneEditorObjectAxisMover = new GameElement("axisMover__sceneEditorElement");
            _sceneEditorObjectAxisMover.AddChild(_sceneEditorObjectAxisMoverX);
            _sceneEditorObjectAxisMover.AddChild(_sceneEditorObjectAxisMoverY);
            _sceneEditorObjectAxisMover.AddChild(_sceneEditorObjectAxisMoverZ);

            ParentScene.AddGameElement(_sceneEditorObjectAxisMover);
        }
예제 #6
0
        public override void Load()
        {
            _sceneEditorCamera = new GameElement("camera__sceneEditorElement");
            _cameraControl     = new SceneEditorCameraControl();

            var camera = new GameElement("Main Camera");

            camera.AttachComponent(new Camera()
            {
                ClearColor      = Color4.White,
                ClearScreenType = ClearScreenTypes.Cubemap,
                Cubemap         = ResourcesManager.LoadResource <Cubemap>(ResourceType.CubeMap, "Assets/Skybox/skyX/posx.png Assets/Skybox/skyX/negx.png Assets/Skybox/skyX/posy.png Assets/Skybox/skyX/negy.png Assets/Skybox/skyX/posz.png Assets/Skybox/skyX/negz.png"),
                Far             = 3000,
                FieldOfView     = 45,
                Forward         = VectorHelper.Forward,
                IsPrimary       = true,
                Near            = 0.25f,
                ProjectionType  = ProjectionTypes.Perspective,
                Viewport        = RendererManager.Viewport
            });

            _sceneEditorCamera.AttachComponent(camera.GetComponent <Camera>());

            _sceneEditorCamera.AttachComponent(_cameraControl);

            var box = new GameElement("Box");

            box.AttachComponents(
                new Material()
            {
                ColorAmbient     = Color4.Crimson,
                ColorDiffuse     = Color4.Crimson,
                ColorSpecular    = Color4.White,
                HasColorAmbient  = true,
                HasColorDiffuse  = true,
                HasColorSpecular = true,
                ShaderProgram    = new DiffuseShaderProgram()
            },
                new MeshRenderer()
            {
                MeshFilter = MeshFactory.CreateCube(-Vector3f.One * 5, Vector3f.One * 5),
                Visible    = true
            }
                );

            box.LocalTransform.SetTranslation(0, 0, 50);

            GameElement light = new GameElement("Sun");

            light.AttachComponents(
                new Light()
            {
                AmbientColor = new Color4(255, 244, 214, 255),
                DiffuseColor = new Color4(255, 244, 214, 255),
                // DiffuseColor = new Color4(202, 198, 162, 255),
                SpecularColor = Color4.White,
                Intensity     = 1f,
                Type          = LightType.Directional
            }
                );

            GameElement plane = new GameElement("Plane");

            plane.AttachComponents(
                new MeshRenderer()
            {
                MeshFilter = MeshFactory.CreatePlane(Vector2f.One * -1000, Sizef.One * 2000),
                Visible    = true
            },
                new Material()
            {
                TextureTilling  = 50,
                ColorAmbient    = Color4.White,
                HasColorAmbient = true,
                ColorDiffuse    = Color4.White,
                HasColorDiffuse = true,
                ShaderProgram   = new DiffuseShaderProgram()
            }
                );

            plane.LocalTransform.SetTranslation(VectorHelper.Down * 20);

            AddGameElement(light);
            AddGameElement(plane);
            AddGameElement(box);
            AddGameElement(_sceneEditorCamera);

            AddRenderScript(new GizmoDrawer());

            base.Load();
        }