Exemplo n.º 1
0
        public override void ProcessShapeMotionVertexData(NJS_MOTION motion, int frame, int animindex)
        {
            if (!motion.Models.ContainsKey(animindex))
            {
                ProcessVertexData();
                return;
            }
#if modellog
            Extensions.Log("Processing Chunk Attach " + Name + Environment.NewLine);
#endif
            if (Vertex != null)
            {
                foreach (VertexChunk chunk in Vertex)
                {
#if modellog
                    Extensions.Log("Vertex Declaration: " + chunk.IndexOffset + "-" + (chunk.IndexOffset + chunk.VertexCount - 1) + Environment.NewLine);
#endif
                    if (VertexBuffer.Length < chunk.IndexOffset + chunk.VertexCount)
                    {
                        Array.Resize(ref VertexBuffer, chunk.IndexOffset + chunk.VertexCount);
                    }
                    Vertex[]      vertdata = chunk.Vertices.ToArray();
                    Vertex[]      normdata = chunk.Normals.ToArray();
                    AnimModelData data     = motion.Models[animindex];
                    if (data.Vertex.Count > 0)
                    {
                        vertdata = data.GetVertex(frame);
                    }
                    if (data.Normal.Count > 0)
                    {
                        normdata = data.GetNormal(frame);
                    }
                    for (int i = 0; i < chunk.VertexCount; i++)
                    {
                        VertexBuffer[i + chunk.IndexOffset] = new VertexData(vertdata[i]);
                        if (normdata.Length > 0)
                        {
                            VertexBuffer[i + chunk.IndexOffset].Normal = normdata[i];
                        }
                        if (chunk.Diffuse.Count > 0)
                        {
                            VertexBuffer[i + chunk.IndexOffset].Color = chunk.Diffuse[i];
                        }
                    }
                }
            }
            List <MeshInfo> result = new List <MeshInfo>();
            if (Poly != null)
            {
                result = ProcessPolyList(PolyName, Poly, 0);
            }
            MeshInfo = result.ToArray();
        }
Exemplo n.º 2
0
        public override void ProcessShapeMotionVertexData(NJS_MOTION motion, int frame, int animindex)
        {
            if (!motion.Models.ContainsKey(animindex))
            {
                ProcessVertexData();
                return;
            }
            Vertex[]      vertdata = Vertex;
            Vertex[]      normdata = Normal;
            AnimModelData data     = motion.Models[animindex];

            if (data.Vertex.Count > 0)
            {
                vertdata = data.GetVertex(frame);
            }
            if (data.Normal.Count > 0)
            {
                normdata = data.GetNormal(frame);
            }
            List <MeshInfo> result = new List <MeshInfo>();

            foreach (NJS_MESHSET mesh in Mesh)
            {
                bool              hasVColor = mesh.VColor != null;
                bool              hasUV     = mesh.UV != null;
                List <Poly>       polys     = new List <Poly>();
                List <VertexData> verts     = new List <VertexData>();
                int currentstriptotal       = 0;
                foreach (Poly poly in mesh.Poly)
                {
                    Poly newpoly = null;
                    switch (mesh.PolyType)
                    {
                    case Basic_PolyType.Triangles:
                        newpoly = new Triangle();
                        break;

                    case Basic_PolyType.Quads:
                        newpoly = new Quad();
                        break;

                    case Basic_PolyType.NPoly:
                    case Basic_PolyType.Strips:
                        newpoly = new Strip(poly.Indexes.Length, ((Strip)poly).Reversed);
                        break;
                    }
                    for (int i = 0; i < poly.Indexes.Length; i++)
                    {
                        newpoly.Indexes[i] = (ushort)verts.Count;
                        verts.Add(new VertexData(
                                      vertdata[poly.Indexes[i]],
                                      normdata[poly.Indexes[i]],
                                      hasVColor ? (Color?)mesh.VColor[currentstriptotal] : null,
                                      hasUV ? mesh.UV[currentstriptotal++] : null));
                    }
                    polys.Add(newpoly);
                }
                NJS_MATERIAL mat = null;
                if (Material != null && mesh.MaterialID < Material.Count)
                {
                    mat = Material[mesh.MaterialID];
                }
                result.Add(new MeshInfo(mat, polys.ToArray(), verts.ToArray(), hasUV, hasVColor));
            }
            MeshInfo = result.ToArray();
        }