示例#1
0
        private static void updateMatrix(ref List <mat44> result, MeshDef.Bone bone, Pose pose, List <MeshDef.Bone> list)
        {
            mat44 parent;

            if (bone.parentBone == null)
            {
                parent = mat44.Identity;
            }
            else
            {
                parent = result[bone.parent];
            }
            vec3 loc = pose.bones[bone.index].location;
            quat rot = pose.bones[bone.index].rotation;

            // bone.pos Rotate(-bone.rot).
            result[bone.index] = new MatrixHelper(parent).Rotate(bone.rot).Translate(bone.pos).Translate(loc).Rotate(-rot).mat44;
            foreach (MeshDef.Bone b in bone.childs)
            {
                updateMatrix(ref result, b, pose, list);
            }
        }
示例#2
0
            internal static MeshDef Load(FileSystem fs, string path)
            {
                MeshDef def = new MeshDef();

                using (Stream s = fs.open(path))
                {
                    BinaryReader br        = new BinaryReader(s);
                    int          version   = br.ReadInt32();
                    int          materials = br.ReadInt32();
                    for (int materialid = 0; materialid < materials; ++materialid)
                    {
                        MeshDef.MaterialDef m = def.addMaterial("m" + materialid.ToString());
                        m.texture   = br.ReadString();
                        m.ambient   = vec3.Read(br);
                        m.diffuse   = vec3.Read(br);
                        m.specular  = vec3.Read(br);
                        m.emissive  = vec3.Read(br);
                        m.alpha     = br.ReadSingle();
                        m.shininess = br.ReadSingle();
                    }
                    int bonecount = br.ReadInt32();
                    for (int boneid = 0; boneid < bonecount; ++boneid)
                    {
                        MeshDef.Bone bone = def.newBone();
                        bone.name   = br.ReadString();
                        bone.parent = br.ReadInt32();
                        bone.pos    = vec3.Read(br);
                        vec3 qv = vec3.Read(br);
                        bone.rot = new quat(br.ReadSingle(), qv);
                    }
                    int pointcount = br.ReadInt32();
                    for (int pointid = 0; pointid < pointcount; ++pointid)
                    {
                        int  boneid = br.ReadInt32();
                        vec3 p      = new vec3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        def.addPoint(p, boneid);
                    }
                    int uvcount = br.ReadInt32();
                    for (int uvid = 0; uvid < uvcount; ++uvid)
                    {
                        vec2 v = new vec2(br.ReadSingle(), br.ReadSingle());
                        def.AddUv(v);
                    }
                    int normalcount = br.ReadInt32();
                    for (int normalid = 0; normalid < normalcount; ++normalid)
                    {
                        vec3 p = new vec3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        def.addNomal(p);
                    }

                    for (int materialid = 0; materialid < materials; ++materialid)
                    {
                        def.selectMaterial("m" + materialid.ToString());
                        int tricount = br.ReadInt32();
                        for (int triid = 0; triid < tricount; ++triid)
                        {
                            MeshDef.VertexData[] data = new MeshDef.VertexData[3];
                            for (int i = 0; i < 3; ++i)
                            {
                                data[i].vertex = br.ReadInt32();
                                data[i].uv     = br.ReadInt32();
                                data[i].normal = br.ReadInt32();
                            }
                            def.addTri(new MeshDef.Tri(data));
                        }
                    }
                }
                return(def);
            }