Exemple #1
0
        public override Mesh decode(MeshInfo minfo, CtmInputStream input)
        {
            Mesh m = base.decode(minfo, input);

            restoreIndices(minfo.getTriangleCount(), m.indices);
            return(m);
        }
Exemple #2
0
        public override Mesh decode(MeshInfo minfo, CtmInputStream input)
        {
            int vc = minfo.getVertexCount();

            checkTag(input.readLittleInt(), MG2_HEADER_TAG);
            float vertexPrecision = input.readLittleFloat();
            float normalPrecision = input.readLittleFloat();

            Grid grid = Grid.fromStream(input);
            if(!grid.checkIntegrity()) {
                throw new InvalidDataException("The vertex size grid is corrupt!");
            }

            float[] vertices = readVertices(input, grid, vc, vertexPrecision);

            int[] indices = readIndices(input, minfo.getTriangleCount(), vc);

            float[] normals = null;
            if (minfo.hasNormals()) {
                normals = readNormals(input, vertices, indices, normalPrecision, vc);
            }

            AttributeData[] uvData = new AttributeData[minfo.getUvMapCount()];
            for (int i = 0; i < uvData.Length; i++) {
                uvData[i] = readUvData(input, vc);
            }

            AttributeData[] attributs = new AttributeData[minfo.getAttrCount()];
            for (int i = 0; i < attributs.Length; i++) {
                attributs[i] = readAttribute(input, vc);
            }

            return new Mesh(vertices, normals, indices, uvData, attributs);
        }
Exemple #3
0
        public override Mesh decode(MeshInfo minfo, CtmInputStream input)
        {
            int vc = minfo.getVertexCount();

            AttributeData[] tex = new AttributeData[minfo.getUvMapCount()];
            AttributeData[] att = new AttributeData[minfo.getAttrCount()];

            checkTag(input.readLittleInt(), INDX);
            int[] indices = readIntArray(input, minfo.getTriangleCount(), 3, false);

            checkTag(input.readLittleInt(), VERT);
            float[] vertices = readFloatArray(input, vc * Mesh.CTM_POSITION_ELEMENT_COUNT, 1);

            float[] normals = null;
            if (minfo.hasNormals()) {
                checkTag(input.readLittleInt(), NORM);
                normals = readFloatArray(input, vc, Mesh.CTM_NORMAL_ELEMENT_COUNT);
            }

            for (int i = 0; i < tex.Length; ++i) {
                checkTag(input.readLittleInt(), TEXC);
                tex[i] = readUVData(vc, input);
            }

            for (int i = 0; i < att.Length; ++i) {
                checkTag(input.readLittleInt(), ATTR);
                att[i] = readAttrData(vc, input);
            }

            return new Mesh(vertices, normals, indices, tex, att);
        }
Exemple #4
0
        public override Mesh decode(MeshInfo minfo, CtmInputStream input)
        {
            int vc = minfo.getVertexCount();

            AttributeData[] tex = new AttributeData[minfo.getUvMapCount()];
            AttributeData[] att = new AttributeData[minfo.getAttrCount()];

            checkTag(input.readLittleInt(), INDX);
            int[] indices = readIntArray(input, minfo.getTriangleCount(), 3, false);

            checkTag(input.readLittleInt(), VERT);
            float[] vertices = readFloatArray(input, vc * Mesh.CTM_POSITION_ELEMENT_COUNT, 1);

            float[] normals = null;
            if (minfo.hasNormals())
            {
                checkTag(input.readLittleInt(), NORM);
                normals = readFloatArray(input, vc, Mesh.CTM_NORMAL_ELEMENT_COUNT);
            }

            for (int i = 0; i < tex.Length; ++i)
            {
                checkTag(input.readLittleInt(), TEXC);
                tex[i] = readUVData(vc, input);
            }

            for (int i = 0; i < att.Length; ++i)
            {
                checkTag(input.readLittleInt(), ATTR);
                att[i] = readAttrData(vc, input);
            }

            return(new Mesh(vertices, normals, indices, tex, att));
        }
Exemple #5
0
        public void  decode(ref List <Mesh> meshList)
        {
            if (decoded)
            {
                throw new Exception("Ctm File got already decoded");
            }
            decoded = true;

            if (input.readLittleInt() != OCTM)
            {
                throw new BadFormatException("The CTM file doesn't start with the OCTM tag!");
            }


            int formatVersion = input.readLittleInt();
            int methodTag     = input.readLittleInt();

            MeshInfo mi = new MeshInfo(input.readLittleInt(),  //vertex count
                                       input.readLittleInt(),  //triangle count
                                       input.readLittleInt(),  //uvmap count
                                       input.readLittleInt(),  //attribute count
                                       input.readLittleInt()); //flags

            comment = input.readString();


            // Uncompress from stream
            Mesh ctmMesh = null;

            foreach (MeshDecoder md in DECODER)
            {
                if (md.isFormatSupported(methodTag, formatVersion))
                {
                    ctmMesh = md.decode(mi, input);
                    break;
                }
            }

            if (ctmMesh == null)
            {
                throw new IOException("No sutible decoder found for Mesh of compression type: " + unpack(methodTag) + ", version " + formatVersion);
            }

            // Check mesh integrity
            ctmMesh.checkIntegrity();

            // Unity only support maximum 65534 vertices per mesh. So large meshes need to be splitted.
            if (ctmMesh.vertices.Length > maxNumVerticesPerMesh * 3)
            {
                SplitMesh(ctmMesh, ref meshList);
            }
            else
            {
                meshList.Add(ctmMesh);
            }

            //return m;
        }
        public Mesh decode()
        {
            if (decoded)
            {
                throw new Exception("Ctm File got already decoded");
            }
            decoded = true;

            if (input.readLittleInt() != OCTM)
            {
                throw new BadFormatException("The CTM file doesn't start with the OCTM tag!");
            }


            int formatVersion = input.readLittleInt();
            int methodTag     = input.readLittleInt();

            MeshInfo mi = new MeshInfo(input.readLittleInt(),  //vertex count
                                       input.readLittleInt(),  //triangle count
                                       input.readLittleInt(),  //uvmap count
                                       input.readLittleInt(),  //attribute count
                                       input.readLittleInt()); //flags

            comment = input.readString();


            // Uncompress from stream
            Mesh ctmMesh = null;

            foreach (MeshDecoder md in DECODER)
            {
                if (md.isFormatSupported(methodTag, formatVersion))
                {
                    ctmMesh = md.decode(mi, input);
                    break;
                }
            }

            if (ctmMesh == null)
            {
                throw new IOException("No sutible decoder found for Mesh of compression type: " + unpack(methodTag) + ", version " + formatVersion);
            }

            // Check mesh integrity
            ctmMesh.checkIntegrity();

            return(ctmMesh);
        }
        public override Mesh decode(MeshInfo minfo, CtmInputStream input)
        {
            int vc = minfo.getVertexCount();

            checkTag(input.readLittleInt(), MG2_HEADER_TAG);
            float vertexPrecision = input.readLittleFloat();
            float normalPrecision = input.readLittleFloat();

            Grid grid = Grid.fromStream(input);

            if (!grid.checkIntegrity())
            {
                throw new InvalidDataException("The vertex size grid is corrupt!");
            }

            float[] vertices = readVertices(input, grid, vc, vertexPrecision);

            int[] indices = readIndices(input, minfo.getTriangleCount(), vc);

            float[] normals = null;
            if (minfo.hasNormals())
            {
                normals = readNormals(input, vertices, indices, normalPrecision, vc);
            }

            AttributeData[] uvData = new AttributeData[minfo.getUvMapCount()];
            for (int i = 0; i < uvData.Length; i++)
            {
                uvData[i] = readUvData(input, vc);
            }

            AttributeData[] attributs = new AttributeData[minfo.getAttrCount()];
            for (int i = 0; i < attributs.Length; i++)
            {
                attributs[i] = readAttribute(input, vc);
            }

            return(new Mesh(vertices, normals, indices, uvData, attributs));
        }
 public abstract Mesh decode(MeshInfo minfo, CtmInputStream input);
 public abstract Mesh decode(MeshInfo minfo, CtmInputStream input);