コード例 #1
0
        public ModelRenderer(IGameWindow control, File3di file)
        {
            _viewport = control;
            _file = file;

            _viewport.MakeCurrent();
            OnLoad(EventArgs.Empty);

            _viewport.UpdateFrame += OnUpdateFrame;
            _viewport.RenderFrame += OnRenderFrame;
        }
コード例 #2
0
        private static IEnumerable<GlMesh> BuildMeshes(File3di.ModelLod lod)
        {
            var meshes = new List<GlMesh>();

            for (var iBones = 0; iBones < lod.SubObjects.Count; iBones++)
            {
                var subObj = lod.SubObjects[iBones];

                //sub.BoneDiffOffset = sub.BoneDiffOffset - SubObjects[sub.parentBone].BoneDiffOffset;

                var foff = lod.FaceOffset(iBones);
                var voff = lod.VecOffset(iBones);

                for (var i = 0; i < subObj.nFaces; i++)
                {
                    var face = lod.Faces[i + foff];

                    var mesh = meshes.Find(g => g.MatIndex == face.MaterialIndex);
                    if (mesh == null)
                    {
                        mesh = new GlMesh {MatIndex = face.MaterialIndex};
                        meshes.Add(mesh);
                    }

                    var vec4 = lod.Vertices[face.Vertex1 + voff];
                    mesh.CoordVerts.Add(vec4 - subObj.BoneOffset);
                    vec4 = lod.Vertices[face.Vertex2 + voff];
                    mesh.CoordVerts.Add(vec4 - subObj.BoneOffset);
                    vec4 = lod.Vertices[face.Vertex3 + voff];
                    mesh.CoordVerts.Add(vec4 - subObj.BoneOffset);

                    mesh.CoordTex.Add(new Vector2(face.tu1/65536.0f, face.tv1/65536.0f));
                    mesh.CoordTex.Add(new Vector2(face.tu2/65536.0f, face.tv2/65536.0f));
                    mesh.CoordTex.Add(new Vector2(face.tu3/65536.0f, face.tv3/65536.0f));

                    vec4 = lod.Normals[face.Normal1];
                    mesh.CoordNorms.Add(vec4);
                    vec4 = lod.Normals[face.Normal2];
                    mesh.CoordNorms.Add(vec4);
                    vec4 = lod.Normals[face.Normal3];
                    mesh.CoordNorms.Add(vec4);
                }
            }

            return meshes;
        }