Ejemplo n.º 1
0
        public override void ProcessVertexData()
        {
#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);
                    }
                    if (NormalBuffer.Length < chunk.IndexOffset + chunk.VertexCount)
                    {
                        Array.Resize(ref NormalBuffer, chunk.IndexOffset + chunk.VertexCount);
                    }
                    Array.Copy(chunk.Vertices.ToArray(), 0, VertexBuffer, chunk.IndexOffset, chunk.Vertices.Count);
                    Array.Copy(chunk.Normals.ToArray(), 0, NormalBuffer, chunk.IndexOffset, chunk.Normals.Count);
                }
            }
            List <MeshInfo> result = new List <MeshInfo>();
            if (Poly != null)
            {
                result = ProcessPolyList(PolyName, Poly, 0);
            }
            MeshInfo = result.ToArray();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        public void ProcessVertexData()
        {
#if modellog
            Extensions.Log("Processing Object " + Name + Environment.NewLine);
#endif
            if (Attach != null)
            {
                Attach.ProcessVertexData();
            }
            foreach (NJS_OBJECT item in Children)
            {
                item.ProcessVertexData();
            }
        }
Ejemplo n.º 4
0
        public override void ProcessVertexData()
        {
#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);
                    }
                    for (int i = 0; i < chunk.VertexCount; i++)
                    {
                        VertexBuffer[i + chunk.IndexOffset] = new VertexData(chunk.Vertices[i]);
                        if (chunk.Normals.Count > 0)
                        {
                            VertexBuffer[i + chunk.IndexOffset].Normal = chunk.Normals[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();
        }
Ejemplo n.º 5
0
        private List <MeshInfo> ProcessPolyList(string name, List <PolyChunk> strips, int start)
        {
            List <MeshInfo> result = new List <MeshInfo>();

            for (int i = start; i < strips.Count; i++)
            {
                PolyChunk chunk = strips[i];
                MaterialBuffer.UpdateFromPolyChunk(chunk);
                switch (chunk.Type)
                {
                case ChunkType.Bits_CachePolygonList:
                    byte cachenum = ((PolyChunkBitsCachePolygonList)chunk).List;
#if modellog
                    Extensions.Log("Caching Poly List " + name + "[" + (i + 1) + "] to cache #" + cachenum + Environment.NewLine);
#endif
                    PolyCache[cachenum] = new CachedPoly(name, strips, i + 1);
                    return(result);

                case ChunkType.Bits_DrawPolygonList:
                    cachenum = ((PolyChunkBitsDrawPolygonList)chunk).List;
                    CachedPoly cached = PolyCache[cachenum];
#if modellog
                    Extensions.Log("Drawing Poly List " + cached.Name + "[" + cached.Index + "] from cache #" + cachenum + Environment.NewLine);
#endif
                    result.AddRange(ProcessPolyList(cached.Name, cached.Polys, cached.Index));
                    break;

                case ChunkType.Strip_Strip:
                case ChunkType.Strip_StripUVN:
                case ChunkType.Strip_StripUVH:
                case ChunkType.Strip_StripNormal:
                case ChunkType.Strip_StripUVNNormal:
                case ChunkType.Strip_StripUVHNormal:
                case ChunkType.Strip_StripColor:
                case ChunkType.Strip_StripUVNColor:
                case ChunkType.Strip_StripUVHColor:
                case ChunkType.Strip_Strip2:
                case ChunkType.Strip_StripUVN2:
                case ChunkType.Strip_StripUVH2:
                {
                    PolyChunkStrip c2 = (PolyChunkStrip)chunk;
#if modellog
                    Extensions.Log("Strip " + c2.Type + Environment.NewLine);
#endif
                    bool hasVColor = false;
                    switch (chunk.Type)
                    {
                    case ChunkType.Strip_StripColor:
                    case ChunkType.Strip_StripUVNColor:
                    case ChunkType.Strip_StripUVHColor:
                        hasVColor = true;
                        break;
                    }
                    bool hasUV = false;
                    switch (chunk.Type)
                    {
                    case ChunkType.Strip_StripUVN:
                    case ChunkType.Strip_StripUVH:
                    case ChunkType.Strip_StripUVNColor:
                    case ChunkType.Strip_StripUVHColor:
                    case ChunkType.Strip_StripUVN2:
                    case ChunkType.Strip_StripUVH2:
                        hasUV = true;
                        break;
                    }
                    List <Poly>       polys = new List <Poly>();
                    List <VertexData> verts = new List <VertexData>();
#if modellog
                    List <ushort> indexes = new List <ushort>();
#endif
                    foreach (PolyChunkStrip.Strip strip in c2.Strips)
                    {
#if modellog
                        indexes.AddRange(strip.Indexes);
#endif
                        Strip str = new Strip(strip.Indexes.Length, strip.Reversed);
                        for (int k = 0; k < strip.Indexes.Length; k++)
                        {
                            str.Indexes[k] = (ushort)verts.Count;
                            verts.Add(new VertexData(
                                          VertexBuffer[strip.Indexes[k]].Position,
                                          VertexBuffer[strip.Indexes[k]].Normal,
                                          hasVColor ? (Color?)strip.VColors[k] : VertexBuffer[strip.Indexes[k]].Color,
                                          hasUV ? strip.UVs[k] : null));
                        }
                        polys.Add(str);
                    }
                    if (!hasVColor)
                    {
                        hasVColor = verts.Any(a => a.Color.HasValue && a.Color.Value != Color.White);
                    }
#if modellog
                    indexes = new List <ushort>(System.Linq.Enumerable.Distinct(indexes));
                    indexes.Sort();
                    StringBuilder sb  = new StringBuilder("Vertex Usage: ");
                    ushort        ist = indexes[0];
                    for (int k = 0; k < indexes.Count - 1; k++)
                    {
                        if (indexes[k + 1] != indexes[k] + 1)
                        {
                            sb.Append(" " + ist);
                            if (indexes[k] != ist)
                            {
                                sb.Append("-" + indexes[k]);
                            }
                            ist = indexes[++k];
                        }
                    }
                    sb.Append(" " + ist);
                    if (indexes[indexes.Count - 1] != ist)
                    {
                        sb.Append("-" + indexes[indexes.Count - 1]);
                    }
                    sb.Append(Environment.NewLine);
                    Extensions.Log(sb.ToString());
#endif
                    result.Add(new MeshInfo(MaterialBuffer, polys.ToArray(), verts.ToArray(), hasUV, hasVColor));
                    MaterialBuffer = new NJS_MATERIAL(MaterialBuffer);
                }
                break;
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
        private List <MeshInfo> ProcessPolyList(string name, List <PolyChunk> strips, int start)
        {
            List <MeshInfo> result = new List <MeshInfo>();

            for (int i = start; i < strips.Count; i++)
            {
                PolyChunk chunk = strips[i];
                switch (chunk.Type)
                {
                case ChunkType.Bits_BlendAlpha:
                {
                    PolyChunkBitsBlendAlpha c2 = (PolyChunkBitsBlendAlpha)chunk;
                    MaterialBuffer.SourceAlpha      = c2.SourceAlpha;
                    MaterialBuffer.DestinationAlpha = c2.DestinationAlpha;
                }
                break;

                case ChunkType.Bits_MipmapDAdjust:
                    break;

                case ChunkType.Bits_SpecularExponent:
                    MaterialBuffer.Exponent = ((PolyChunkBitsSpecularExponent)chunk).SpecularExponent;
                    break;

                case ChunkType.Bits_CachePolygonList:
                    byte cachenum = ((PolyChunkBitsCachePolygonList)chunk).List;
#if modellog
                    Extensions.Log("Caching Poly List " + name + "[" + (i + 1) + "] to cache #" + cachenum + Environment.NewLine);
#endif
                    PolyCache[cachenum] = new CachedPoly(name, strips, i + 1);
                    return(result);

                case ChunkType.Bits_DrawPolygonList:
                    cachenum = ((PolyChunkBitsDrawPolygonList)chunk).List;
                    CachedPoly cached = PolyCache[cachenum];
#if modellog
                    Extensions.Log("Drawing Poly List " + cached.Name + "[" + cached.Index + "] from cache #" + cachenum + Environment.NewLine);
#endif
                    result.AddRange(ProcessPolyList(cached.Name, cached.Polys, cached.Index));
                    break;

                case ChunkType.Tiny_TextureID:
                case ChunkType.Tiny_TextureID2:
                {
                    PolyChunkTinyTextureID c2 = (PolyChunkTinyTextureID)chunk;
                    MaterialBuffer.ClampU      = c2.ClampU;
                    MaterialBuffer.ClampV      = c2.ClampV;
                    MaterialBuffer.FilterMode  = c2.FilterMode;
                    MaterialBuffer.FlipU       = c2.FlipU;
                    MaterialBuffer.FlipV       = c2.FlipV;
                    MaterialBuffer.SuperSample = c2.SuperSample;
                    MaterialBuffer.TextureID   = c2.TextureID;
                }
                break;

                case ChunkType.Material_Diffuse:
                case ChunkType.Material_Ambient:
                case ChunkType.Material_DiffuseAmbient:
                case ChunkType.Material_Specular:
                case ChunkType.Material_DiffuseSpecular:
                case ChunkType.Material_AmbientSpecular:
                case ChunkType.Material_DiffuseAmbientSpecular:
                case ChunkType.Material_Diffuse2:
                case ChunkType.Material_Ambient2:
                case ChunkType.Material_DiffuseAmbient2:
                case ChunkType.Material_Specular2:
                case ChunkType.Material_DiffuseSpecular2:
                case ChunkType.Material_AmbientSpecular2:
                case ChunkType.Material_DiffuseAmbientSpecular2:
                {
                    PolyChunkMaterial c2 = (PolyChunkMaterial)chunk;
                    MaterialBuffer.SourceAlpha      = c2.SourceAlpha;
                    MaterialBuffer.DestinationAlpha = c2.DestinationAlpha;
                    if (c2.Diffuse.HasValue)
                    {
                        MaterialBuffer.DiffuseColor = c2.Diffuse.Value;
                    }
                    if (c2.Specular.HasValue)
                    {
                        MaterialBuffer.SpecularColor = c2.Specular.Value;
                        MaterialBuffer.Exponent      = c2.SpecularExponent;
                    }
                }
                break;

                case ChunkType.Strip_Strip:
                case ChunkType.Strip_StripUVN:
                case ChunkType.Strip_StripUVH:
                case ChunkType.Strip_StripNormal:
                case ChunkType.Strip_StripUVNNormal:
                case ChunkType.Strip_StripUVHNormal:
                case ChunkType.Strip_StripColor:
                case ChunkType.Strip_StripUVNColor:
                case ChunkType.Strip_StripUVHColor:
                case ChunkType.Strip_Strip2:
                case ChunkType.Strip_StripUVN2:
                case ChunkType.Strip_StripUVH2:
                {
                    PolyChunkStrip c2 = (PolyChunkStrip)chunk;
#if modellog
                    Extensions.Log("Strip " + c2.Type + Environment.NewLine);
#endif
                    MaterialBuffer.DoubleSided    = c2.DoubleSide;
                    MaterialBuffer.EnvironmentMap = c2.EnvironmentMapping;
                    MaterialBuffer.FlatShading    = c2.FlatShading;
                    MaterialBuffer.IgnoreLighting = c2.IgnoreLight;
                    MaterialBuffer.IgnoreSpecular = c2.IgnoreSpecular;
                    MaterialBuffer.UseAlpha       = c2.UseAlpha;
                    bool hasVColor = false;
                    switch (chunk.Type)
                    {
                    case ChunkType.Strip_StripColor:
                    case ChunkType.Strip_StripUVNColor:
                    case ChunkType.Strip_StripUVHColor:
                        hasVColor = true;
                        break;
                    }
                    bool hasUV = false;
                    switch (chunk.Type)
                    {
                    case ChunkType.Strip_StripUVN:
                    case ChunkType.Strip_StripUVH:
                    case ChunkType.Strip_StripUVNColor:
                    case ChunkType.Strip_StripUVHColor:
                    case ChunkType.Strip_StripUVN2:
                    case ChunkType.Strip_StripUVH2:
                        hasUV = true;
                        break;
                    }
                    List <Poly>       polys = new List <Poly>();
                    List <VertexData> verts = new List <VertexData>();
#if modellog
                    List <ushort> indexes = new List <ushort>();
#endif
                    foreach (PolyChunkStrip.Strip strip in c2.Strips)
                    {
#if modellog
                        indexes.AddRange(strip.Indexes);
#endif
                        Strip str = new Strip(strip.Indexes.Length, strip.Reversed);
                        for (int k = 0; k < strip.Indexes.Length; k++)
                        {
                            str.Indexes[k] = (ushort)verts.Count;
                            verts.Add(new VertexData(
                                          VertexBuffer[strip.Indexes[k]].Position,
                                          VertexBuffer[strip.Indexes[k]].Normal,
                                          hasVColor ? (Color?)strip.VColors[k] : VertexBuffer[strip.Indexes[k]].Color,
                                          hasUV ? strip.UVs[k] : null));
                        }
                        polys.Add(str);
                    }
#if modellog
                    indexes = new List <ushort>(System.Linq.Enumerable.Distinct(indexes));
                    indexes.Sort();
                    StringBuilder sb  = new StringBuilder("Vertex Usage: ");
                    ushort        ist = indexes[0];
                    for (int k = 0; k < indexes.Count - 1; k++)
                    {
                        if (indexes[k + 1] != indexes[k] + 1)
                        {
                            sb.Append(" " + ist);
                            if (indexes[k] != ist)
                            {
                                sb.Append("-" + indexes[k]);
                            }
                            ist = indexes[++k];
                        }
                    }
                    sb.Append(" " + ist);
                    if (indexes[indexes.Count - 1] != ist)
                    {
                        sb.Append("-" + indexes[indexes.Count - 1]);
                    }
                    sb.Append(Environment.NewLine);
                    Extensions.Log(sb.ToString());
#endif
                    result.Add(new MeshInfo(MaterialBuffer, polys.ToArray(), verts.ToArray(), hasUV, hasVColor));
                    MaterialBuffer = new NJS_MATERIAL(MaterialBuffer);
                }
                break;
                }
            }
            return(result);
        }