Esempio n. 1
0
            public static List <Runtime.Node> CreatePlaneWithSkinB()
            {
                var colorInner = new Vector4(0.8f, 0.8f, 0.8f, 1.0f);
                var colorOuter = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);

                var nodeInnerPrism = new Runtime.Node
                {
                    Name = "innerPrism",
                    Skin = new Runtime.Skin()
                    {
                        Name = "innerPrismSkinB",
                    },
                    Mesh = Mesh.CreatePrism(colorInner),
                };

                var nodeOuterPrism = new Runtime.Node
                {
                    Name = "outerPrism",
                    Skin = new Runtime.Skin()
                    {
                        Name = "outerPrismSkinB",
                    },
                    Mesh = Mesh.CreatePrism(colorOuter, Scale: new Vector3(1.6f, 1.6f, 0.3f)),
                };

                Matrix4x4 rotation = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(90.0f), 0.0f);
                var       translationVectorJoint1 = new Vector3(0.0f, 0.0f, -0.6f);
                var       translationVectorJoint0 = new Vector3(0.0f, 0.0f, 0.3f);
                Matrix4x4 matrixJoint1            = Matrix4x4.CreateTranslation(translationVectorJoint1);
                Matrix4x4 matrixJoint0            = Matrix4x4.CreateTranslation(translationVectorJoint0);

                matrixJoint1 = Matrix4x4.Multiply(matrixJoint0, matrixJoint1);
                Matrix4x4.Invert(matrixJoint1, out Matrix4x4 invertedJoint1);
                Matrix4x4.Invert(matrixJoint0, out Matrix4x4 invertedJoint0);

                var nodeJoint1 = new Runtime.Node
                {
                    Name        = "joint1",
                    Translation = translationVectorJoint1,
                };
                var nodeJoint0 = new Runtime.Node
                {
                    Name        = "joint0",
                    Rotation    = Quaternion.CreateFromRotationMatrix(rotation),
                    Translation = new Vector3(0.0f, -0.3f, 0.0f),
                    Children    = new[]
                    {
                        nodeJoint1
                    },
                };

                var joint1 = new Runtime.SkinJoint
                             (
                    inverseBindMatrix: invertedJoint1,
                    node: nodeJoint1
                             );
                var joint0 = new Runtime.SkinJoint
                             (
                    inverseBindMatrix: invertedJoint0,
                    node: nodeJoint0
                             );

                nodeInnerPrism.Skin.SkinJoints = new[]
                {
                    joint0,
                    joint1,
                };
                nodeOuterPrism.Skin.SkinJoints = new[]
                {
                    joint0,
                    joint1,
                };

                var weightsListInnerPrism = new List <List <Runtime.JointWeight> >();
                var weightsListOuterPrism = new List <List <Runtime.JointWeight> >();

                for (var vertexIndex = 0; vertexIndex < 3; vertexIndex++)
                {
                    var weight = new List <Runtime.JointWeight>()
                    {
                        new Runtime.JointWeight
                        {
                            Joint  = joint0,
                            Weight = 1,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint1,
                            Weight = 0,
                        },
                    };
                    weightsListInnerPrism.Add(weight);
                    weightsListOuterPrism.Add(weight);
                }
                for (var vertexIndex = 0; vertexIndex < 3; vertexIndex++)
                {
                    var weight = new List <Runtime.JointWeight>()
                    {
                        new Runtime.JointWeight
                        {
                            Joint  = joint0,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint1,
                            Weight = 1,
                        },
                    };
                    weightsListInnerPrism.Add(weight);
                    weightsListOuterPrism.Add(weight);
                }
                nodeInnerPrism.Mesh.MeshPrimitives.First().VertexJointWeights = weightsListInnerPrism;
                nodeOuterPrism.Mesh.MeshPrimitives.First().VertexJointWeights = weightsListOuterPrism;

                return(new List <Runtime.Node>
                {
                    nodeInnerPrism,
                    nodeJoint0,
                    nodeOuterPrism
                });
            }
Esempio n. 2
0
            private static List <Runtime.Node> CreateJointsAndWeightsForCommonRoot(Runtime.Node nodePlane)
            {
                Matrix4x4 baseRotation                    = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-90.0f), 0.0f);
                Matrix4x4 jointRotation                   = Matrix4x4.CreateFromYawPitchRoll(0.0f, FloatMath.ConvertDegreesToRadians(-15.0f), 0.0f);
                var       translationVectorJoint3         = new Vector3(0.1875f, 0.0f, 0.25f);
                var       translationVectorJoint2         = new Vector3(-0.1875f, 0.0f, 0.25f);
                var       translationVectorJoint1         = new Vector3(0.0f, 0.0f, 0.25f);
                var       translationVectorJoint0         = new Vector3(0.0f, -0.25f, 0.0f);
                Matrix4x4 invertedTranslationMatrixJoint3 = Matrix4x4.CreateTranslation(-translationVectorJoint3);
                Matrix4x4 invertedTranslationMatrixJoint2 = Matrix4x4.CreateTranslation(-translationVectorJoint2);

                var matrixJoint1 = jointRotation;

                Matrix4x4.Invert(matrixJoint1, out Matrix4x4 invertedJoint1);

                var matrixJoint0 = Matrix4x4.CreateTranslation(new Vector3(0, 0.0f, -0.25f));

                Matrix4x4.Invert(matrixJoint0, out Matrix4x4 invertedJoint0);

                var nodeJoint3 = new Runtime.Node
                {
                    Name        = "joint3",
                    Rotation    = Quaternion.CreateFromRotationMatrix(jointRotation),
                    Translation = translationVectorJoint3,
                };
                var nodeJoint2 = new Runtime.Node
                {
                    Name        = "joint2",
                    Rotation    = Quaternion.CreateFromRotationMatrix(jointRotation),
                    Translation = translationVectorJoint2,
                };
                var nodeJoint1 = new Runtime.Node
                {
                    Name        = "joint1",
                    Rotation    = Quaternion.CreateFromRotationMatrix(jointRotation),
                    Translation = translationVectorJoint1,
                    Children    = new[]
                    {
                        nodeJoint2,
                        nodeJoint3
                    }
                };
                var nodeJoint0 = new Runtime.Node
                {
                    Name        = "joint0",
                    Rotation    = Quaternion.CreateFromRotationMatrix(baseRotation),
                    Translation = translationVectorJoint0,
                    Children    = new[]
                    {
                        nodeJoint1
                    }
                };

                var joint3 = new Runtime.SkinJoint
                             (
                    inverseBindMatrix: invertedTranslationMatrixJoint3,
                    node: nodeJoint3
                             );
                var joint2 = new Runtime.SkinJoint
                             (
                    inverseBindMatrix: invertedTranslationMatrixJoint2,
                    node: nodeJoint2
                             );
                var joint1 = new Runtime.SkinJoint
                             (
                    inverseBindMatrix: invertedJoint1,
                    node: nodeJoint1
                             );
                var joint0 = new Runtime.SkinJoint
                             (
                    inverseBindMatrix: invertedJoint0,
                    node: nodeJoint0
                             );

                nodePlane.Skin.SkinJoints = new[]
                {
                    joint0,
                    joint1,
                    joint2,
                    joint3
                };

                // Top four vertexes of each arm have a weight for the relevant joint. Otherwise the vertex has a weight from the root
                var jointWeights = new List <List <Runtime.JointWeight> >();

                // Base of trunk
                for (int vertexIndex = 0; vertexIndex < 2; vertexIndex++)
                {
                    jointWeights.Add(new List <Runtime.JointWeight>()
                    {
                        new Runtime.JointWeight
                        {
                            Joint  = joint0,
                            Weight = 1,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint1,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint2,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint3,
                            Weight = 0,
                        }
                    });
                }
                // Top of trunk
                for (int vertexIndex = 0; vertexIndex < 3; vertexIndex++)
                {
                    jointWeights.Add(new List <Runtime.JointWeight>()
                    {
                        new Runtime.JointWeight
                        {
                            Joint  = joint0,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint1,
                            Weight = 1,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint2,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint3,
                            Weight = 0,
                        }
                    });
                }
                // Left arm
                for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++)
                {
                    jointWeights.Add(new List <Runtime.JointWeight>()
                    {
                        new Runtime.JointWeight
                        {
                            Joint  = joint0,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint1,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint2,
                            Weight = 1,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint3,
                            Weight = 0,
                        }
                    });
                }
                // Right arm
                for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++)
                {
                    jointWeights.Add(new List <Runtime.JointWeight>()
                    {
                        new Runtime.JointWeight
                        {
                            Joint  = joint0,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint1,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint2,
                            Weight = 0,
                        },
                        new Runtime.JointWeight
                        {
                            Joint  = joint3,
                            Weight = 1,
                        }
                    });
                }
                nodePlane.Mesh.MeshPrimitives.First().VertexJointWeights = jointWeights;

                return(new List <Runtime.Node>
                {
                    nodePlane,
                    nodeJoint0
                });
            }