示例#1
0
        public static AnimationNode Create(AnimationModel model)
        {
            var vs    = new VertexShader(vertexCode);
            var fs    = new FragmentShader(fragmentCode);
            var array = new ShaderArray(vs, fs);
            var map   = new AttributeMap();

            map.Add("inPosition", AnimationModel.strPosition);
            map.Add("inNormal", AnimationModel.strNormal);
            map.Add("inTexCoord", AnimationModel.strTexCoord);
            map.Add("inBoneIDs", AnimationModel.strBoneIDs);
            map.Add("inWeights", AnimationModel.strWeights);
            var builder = new RenderMethodBuilder(array, map);
            var node    = new AnimationNode(model, builder);

            node.Initialize();

            return(node);
        }
示例#2
0
        private void BuildNode(Assimp.Node aiNode, mat4 parentTransform, AnimationModel[] models, SceneNodeBase rootElement, ref vec3 max, ref vec3 min, ref bool first)
        {
            mat4 thisTransform = parentTransform * aiNode.Transform.ToMat4();

            if (aiNode.HasMeshes)
            {
                vec3 worldPosition, scale; vec4 rotation;
                thisTransform.ParseRST(out worldPosition, out scale, out rotation);
                foreach (int meshIndex in aiNode.MeshIndices)
                {
                    AnimationModel model = models[meshIndex];
                    GetBound(model.mesh, ref max, ref min, ref first);
                    var node   = AnimationNode.Create(model);
                    var random = new Random();
                    node.DiffuseColor = Color.FromArgb(
                        (byte)random.Next(0, 256),
                        (byte)random.Next(0, 256),
                        (byte)random.Next(0, 256),
                        (byte)random.Next(0, 256)
                        );
                    node.WorldPosition = worldPosition;
                    node.Scale         = scale;
                    node.RotationAxis  = new vec3(rotation.x, rotation.y, rotation.z);
                    node.RotationAngle = rotation.w;
                    rootElement.Children.Add(node);
                }
            }

            if (aiNode.HasChildren)
            {
                foreach (Assimp.Node child in aiNode.Children)
                {
                    BuildNode(child, thisTransform, models, rootElement, ref max, ref min, ref first);
                }
            }
        }