예제 #1
0
        public Entity GenerateTranslationGizmo()
        {
            var entity = new Entity("TranslationGizmo");

            entity.Set(TransformationComponent.Key, new TransformationComponent());

            var gizmoActions        = new[] { GizmoAction.TranslationX, GizmoAction.TranslationY, GizmoAction.TranslationZ };
            var colors              = new[] { Color.Green, Color.Blue, Color.Red };
            var orientationMatrices = new[] { Matrix.Identity, Matrix.RotationZ((float)Math.PI * 0.5f), Matrix.RotationY(-(float)Math.PI * 0.5f) };

            var albedoMaterial = new ShaderMixinSource()
            {
                "AlbedoDiffuseBase",
                "AlbedoSpecularBase",
                new ShaderComposition("albedoDiffuse", new ShaderClassSource("ComputeColorFixed", MaterialKeys.DiffuseColor)),
                new ShaderComposition("albedoSpecular", new ShaderClassSource("ComputeColor")),     // TODO: Default values!
            };

            for (int axis = 0; axis < 3; ++axis)
            {
                // Rendering
                var lineEffectMeshData = new EffectMeshData();
                lineEffectMeshData.Parameters = new ParameterCollection();
                lineEffectMeshData.MeshData   = MeshDataHelper.CreateLine(20.0f, colors[axis]);
                lineEffectMeshData.EffectData = new EffectData("Gizmo")
                {
                    AlbedoMaterial = albedoMaterial
                };

                var lineEntity = new Entity("ArrowCone");
                lineEntity.GetOrCreate(ModelComponent.Key).SubMeshes.Add(lineEffectMeshData);
                lineEntity.Set(TransformationComponent.Key, TransformationMatrix.CreateComponent(orientationMatrices[axis]));

                var coneEffectMeshData = new EffectMeshData();
                coneEffectMeshData.Parameters = new ParameterCollection();
                coneEffectMeshData.MeshData   = MeshDataHelper.CreateCone(2.5f, 10.0f, 10, colors[axis]);
                coneEffectMeshData.EffectData = new EffectData("Gizmo")
                {
                    AlbedoMaterial = albedoMaterial
                };

                var coneEntity = new Entity("ArrowBody");
                coneEntity.GetOrCreate(ModelComponent.Key).SubMeshes.Add(coneEffectMeshData);
                coneEntity.Set(TransformationComponent.Key, TransformationMatrix.CreateComponent(Matrix.Translation(20.0f, 0.0f, 0.0f) * orientationMatrices[axis]));

                lineEntity.Set(GizmoColorKey, colors[axis]);
                coneEntity.Set(GizmoColorKey, colors[axis]);

                lineEntity.Set(GizmoActionKey, gizmoActions[axis]);
                coneEntity.Set(GizmoActionKey, gizmoActions[axis]);

                entity.Transformation.Children.Add(lineEntity.Transformation);
                entity.Transformation.Children.Add(coneEntity.Transformation);
            }

            return(entity);
        }
예제 #2
0
        public Entity GenerateRotationGizmo()
        {
            var entity = new Entity("RotationGizmo");
            entity.Set(TransformationComponent.Key, new TransformationComponent());

            // TODO: Factorize some of this code with GenerateTranslationGizmo?
            var gizmoActions = new[] { GizmoAction.RotationX, GizmoAction.RotationY, GizmoAction.RotationZ };
            var orientationMatrices = new[] { Matrix.Identity, Matrix.RotationZ((float)Math.PI * 0.5f), Matrix.RotationY(-(float)Math.PI * 0.5f) };
            var colors = new[] { Color.Green, Color.Blue, Color.Red };

            var albedoMaterial = new ShaderMixinSource()
                {
                    "AlbedoDiffuseBase",
                    "AlbedoSpecularBase",
                    new ShaderComposition("albedoDiffuse", new ShaderClassSource("ComputeColorFixed", MaterialKeys.DiffuseColor)),
                    new ShaderComposition("albedoSpecular", new ShaderClassSource("ComputeColor")), // TODO: Default values!
                };

            for (int axis = 0; axis < 3; ++axis)
            {
                // Rendering
                var circleEffectMeshData = new EffectMeshData();
                circleEffectMeshData.Parameters = new ParameterCollection();
                circleEffectMeshData.MeshData = MeshDataHelper.CreateCircle(20.0f, 32, colors[axis]);
                circleEffectMeshData.EffectData = new EffectData("Gizmo") { AlbedoMaterial = albedoMaterial };

                var circleEntity = new Entity("ArrowCone");
                circleEntity.GetOrCreate(ModelComponent.Key).SubMeshes.Add(circleEffectMeshData);
                circleEntity.Set(TransformationComponent.Key, TransformationMatrix.CreateComponent(orientationMatrices[axis]));

                circleEntity.Set(GizmoColorKey, colors[axis]);
                circleEntity.Set(GizmoActionKey, gizmoActions[axis]);

                entity.GetOrCreate(TransformationComponent.Key).Children.Add(circleEntity.GetOrCreate(TransformationComponent.Key));
            }

            return entity;
        }