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;
        }
Beispiel #2
0
        private AttributeData readUVData(int vertCount, CtmInputStream input)
        {
            String name    = input.readString();
            String matname = input.readString();

            float[] data = readFloatArray(input, vertCount, Mesh.CTM_UV_ELEMENT_COUNT);

            return(new AttributeData(name, matname, AttributeData.STANDARD_UV_PRECISION, data));
        }
        private AttributeData readUVData(int vertCount, CtmInputStream input)
        {
            name    = input.readString();
            matname = input.readString();

            // Array.Clear(UVdataArray, 0, UVdataArray.Length);
            UVdataArray = readFloatArray(input, vertCount, Mesh.CTM_UV_ELEMENT_COUNT);

            return(new AttributeData(name, matname, AttributeData.STANDARD_UV_PRECISION, UVdataArray));
        }
Beispiel #4
0
        private AttributeData readAttrData(int vertCount, CtmInputStream input)
        {
            String name = input.readString();
            float[] data = readFloatArray(input, vertCount, Mesh.CTM_ATTR_ELEMENT_COUNT);

            return new AttributeData(name, null, AttributeData.STANDARD_PRECISION, data);
        }
        private AttributeData readUvData(CtmInputStream input, int vcount)
        {
            checkTag(input.readLittleInt(), TEXC);
            String name      = input.readString();
            String material  = input.readString();
            float  precision = input.readLittleFloat();

            if (precision <= 0f)
            {
                throw new InvalidDataException("A uv precision value <= 0.0 was read");
            }

            int[]   intCoords = input.readPackedInts(vcount, Mesh.CTM_UV_ELEMENT_COUNT, true);
            float[] data      = restoreUVCoords(precision, intCoords);

            return(new AttributeData(name, material, precision, data));
        }
Beispiel #6
0
        private AttributeData readAttribute(CtmInputStream input, int vc)
        {
            checkTag(input.readLittleInt(), ATTR);

            String name = input.readString();
            float precision = input.readLittleFloat();
            if (precision <= 0f) {
                throw new InvalidDataException("An attribute precision value <= 0.0 was read");
            }

            int[] intData = input.readPackedInts(vc, Mesh.CTM_ATTR_ELEMENT_COUNT, true);
            float[] data = restoreAttribs(precision, intData);

            return new AttributeData(name, null, precision, data);
        }
Beispiel #7
0
        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 m = null;

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

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

            // Check mesh integrity
            m.checkIntegrity();

            return(m);
        }
        private AttributeData readAttribute(CtmInputStream input, int vc)
        {
            checkTag(input.readLittleInt(), ATTR);

            String name      = input.readString();
            float  precision = input.readLittleFloat();

            if (precision <= 0f)
            {
                throw new InvalidDataException("An attribute precision value <= 0.0 was read");
            }

            int[]   intData = input.readPackedInts(vc, Mesh.CTM_ATTR_ELEMENT_COUNT, true);
            float[] data    = restoreAttribs(precision, intData);

            return(new AttributeData(name, null, precision, data));
        }
Beispiel #9
0
        private AttributeData readUvData(CtmInputStream input, int vcount)
        {
            checkTag(input.readLittleInt(), TEXC);
            String name = input.readString();
            String material = input.readString();
            float precision = input.readLittleFloat();
            if (precision <= 0f) {
                throw new InvalidDataException("A uv precision value <= 0.0 was read");
            }

            int[] intCoords = input.readPackedInts(vcount, Mesh.CTM_UV_ELEMENT_COUNT, true);
            float[] data = restoreUVCoords(precision, intCoords);

            return new AttributeData(name, material, precision, data);
        }