Esempio n. 1
0
        private void AddS3DMesh(Model3DGroup group, Node obj, Node.Submesh submesh, bool force)
        {
            try
            {
                var geom = new MeshGeometry3D();

                int[]    indcs = obj.Indices.Data;
                Vertex[] vrtcs = obj.Vertices.Data;

                var iList = ModelFunctions.GetTriangleList(indcs, submesh.FaceStart * 3, submesh.FaceLength * 3, 3);

                int min = iList.Min();
                int max = iList.Max();

                for (int i = 0; i < iList.Count; i++)
                {
                    iList[i] -= min;
                }

                var vArray = new Vertex[(max - min) + 1];
                Array.Copy(ModelFunctions.DeepClone(vrtcs), min, vArray, 0, (max - min) + 1);

                foreach (var vertex in vArray)
                {
                    if (vertex == null)
                    {
                        continue;
                    }
                    VertexValue pos, tex, norm;
                    vertex.TryGetValue("position", 0, out pos);
                    vertex.TryGetValue("texcoords", 0, out tex);

                    var texSize = (obj._2F01 != null) ? obj._2F01.unkC0 : 1;

                    geom.Positions.Add(new Point3D(pos.Data.x, pos.Data.y, pos.Data.z));
                    geom.TextureCoordinates.Add(new System.Windows.Point(tex.Data.x * texSize, tex.Data.y * texSize));
                    if (vertex.TryGetValue("normal", 0, out norm))
                    {
                        geom.Normals.Add(new Vector3D(norm.Data.x, norm.Data.y, norm.Data.z));
                    }
                }

                foreach (var index in iList)
                {
                    geom.TriangleIndices.Add(index);
                }

                GeometryModel3D modeld = new GeometryModel3D(geom, shaders[submesh.MaterialIndex + 1])
                {
                    BackMaterial = shaders[submesh.MaterialIndex + 1]
                };

                group.Children.Add(modeld);
            }
            catch (Exception ex) { if (!force)
                                   {
                                       throw ex;
                                   }
            }
        }
Esempio n. 2
0
        private void AddS3DMesh(Model3DGroup group, Node obj, Node.Submesh submesh, bool force)
        {
            try
            {
                var pObj    = (obj._2901 == null) ? obj : atpl.ObjectByID(obj._2901.InheritID);
                var iOffset = (obj._2901 == null) ? 0 : obj._2901.IndexOffset;
                var vOffset = (obj._2901 == null) ? 0 : obj._2901.VertexOffset;

                var geom  = new MeshGeometry3D();
                var iList = ModelFunctions.GetTriangleList(pObj.Indices.Data, (iOffset + submesh.FaceStart) * 3, submesh.FaceLength * 3, 3);

                var vArray = new Vertex[submesh.VertLength];
                Array.Copy(pObj.Vertices.Data, (vOffset + submesh.VertStart), vArray, 0, submesh.VertLength);

                foreach (var vertex in vArray)
                {
                    if (vertex == null)
                    {
                        continue;
                    }
                    VertexValue pos, tex, norm;
                    vertex.TryGetValue("position", 0, out pos);
                    vertex.TryGetValue("texcoords", 0, out tex);

                    var texSize = (obj._2F01 != null) ? obj._2F01.unkC0 : 1;

                    geom.Positions.Add(new Point3D(pos.Data.x, pos.Data.y, pos.Data.z));
                    geom.TextureCoordinates.Add(new System.Windows.Point(tex.Data.x * texSize, tex.Data.y * texSize));
                    if (vertex.TryGetValue("normal", 0, out norm))
                    {
                        geom.Normals.Add(new Vector3D(norm.Data.x, norm.Data.y, norm.Data.z));
                    }
                }

                foreach (var index in iList)
                {
                    geom.TriangleIndices.Add(index);
                }

                GeometryModel3D modeld = new GeometryModel3D(geom, shaders[submesh.MaterialIndex + 1])
                {
                    //BackMaterial = shaders[submesh.MaterialIndex + 1]
                };

                group.Children.Add(modeld);
            }
            catch (Exception ex) { if (!force)
                                   {
                                       throw ex;
                                   }
            }
        }