private float[] readNormals(CtmInputStream input, float[] vertices, int[] indices,
                             float normalPrecision, int vcount)
 {
     checkTag(input.readLittleInt(), NORM);
     int[] intNormals = input.readPackedInts(vcount, Mesh.CTM_NORMAL_ELEMENT_COUNT, false);
     return(restoreNormals(intNormals, vertices, indices, normalPrecision));
 }
Exemple #2
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 #3
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);
        }
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 override Mesh decode(MeshInfo minfo, CtmInputStream input)
        {
            Mesh m = base.decode(minfo, input);

            restoreIndices(minfo.getTriangleCount(), m.indices);
            return(m);
        }
Exemple #6
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 #7
0
 protected virtual float[] readFloatArray(CtmInputStream input, int count, int size)
 {
     float[] array = new float[count * size];
     for (int i = 0; i < array.Length; i++) {
         array[i] = input.readLittleFloat();
     }
     return array;
 }
Exemple #8
0
 protected virtual int[] readIntArray(CtmInputStream input, int count, int size, bool signed)
 {
     int[] array = new int[count * size];
     for (int i = 0; i < array.Length; i++) {
         array[i] = input.readLittleInt();
     }
     return array;
 }
        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));
        }
Exemple #10
0
 protected virtual float[] readFloatArray(CtmInputStream input, int count, int size)
 {
     float[] array = new float[count * size];
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = input.readLittleFloat();
     }
     return(array);
 }
Exemple #11
0
 protected virtual int[] readIntArray(CtmInputStream input, int count, int size, bool signed)
 {
     int[] array = new int[count * size];
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = input.readLittleInt();
     }
     return(array);
 }
        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));
        }
Exemple #13
0
 private int[] readIndices(CtmInputStream input, int triCount, int vcount)
 {
     checkTag(input.readLittleInt(), INDX);
     int[] indices = input.readPackedInts(triCount, 3, false);
     restoreIndices(triCount, indices);
     foreach(int i in indices) {
         if (i > vcount) {
             throw new InvalidDataException("One element of the indice array "
                                            + "points to a none existing vertex(id: " + i + ")");
         }
     }
     return indices;
 }
        private float[] readVertices(CtmInputStream input, Grid grid, int vcount, float precision)
        {
            checkTag(input.readLittleInt(), VERT);
            int[] intVertices = input.readPackedInts(vcount, Mesh.CTM_POSITION_ELEMENT_COUNT, false);

            checkTag(input.readLittleInt(), GIDX);
            int[] gridIndices = input.readPackedInts(vcount, 1, false);
            for (int i = 1; i < vcount; i++)
            {
                gridIndices[i] += gridIndices[i - 1];
            }

            return(CommonAlgorithm.restoreVertices(intVertices, gridIndices, grid, precision));
        }
Exemple #15
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);
        }
 private int[] readIndices(CtmInputStream input, int triCount, int vcount)
 {
     checkTag(input.readLittleInt(), INDX);
     int[] indices = input.readPackedInts(triCount, 3, false);
     restoreIndices(triCount, indices);
     foreach (int i in indices)
     {
         if (i > vcount)
         {
             throw new InvalidDataException("One element of the indice array "
                                            + "points to a none existing vertex(id: " + i + ")");
         }
     }
     return(indices);
 }
        protected virtual float[] readFloatArray(CtmInputStream input, int count, int size)
        {
            //   float[] floatArray = new float[count * size];
            //for (int i = 0; i < floatArray.Length; i++) {
            //       floatArray[i] = input.readLittleFloat();
            //}
            //return floatArray;

            int length = count * size;

            for (int i = 0; i < length; i++)
            {
                floatArray.Add(input.readLittleFloat());
            }
            return(floatArray.ToArray());
        }
        public void WriteCompressedData()
        {
            byte[] data = new byte[]{1,2,3,4,5,6,7,8,9,10};
            //write
            MemoryStream memory = new MemoryStream();
            CtmOutputStream outS = new CtmOutputStream(memory);
            outS.writeCompressedData(data);

            //read
            memory.Seek(0, SeekOrigin.Begin);
            Stream readMemory = new MemoryStream(memory.ToArray());
            CtmInputStream inS = new CtmInputStream(readMemory);

            Assert.AreEqual(data, inS.readCompressedData(data.Length));
            Assert.AreEqual(memory.Length, readMemory.Position);
        }
        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));
        }
        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));
        }
        protected virtual int[] readIntArray(CtmInputStream input, int count, int size, bool signed)
        {
            //int[] array = new int[count * size];
            //for (int i = 0; i < array.Length; i++) {
            //    array[i] = input.readLittleInt();
            //}
            //return array;

            intArray.Clear();
            int length = count * size;

            for (int i = 0; i < length; i++)
            {
                intArray.Add(input.readLittleInt());
            }

            return(intArray.ToArray());
        }
        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 #23
0
 public abstract Mesh decode(MeshInfo minfo, CtmInputStream input);
Exemple #24
0
 public abstract Mesh decode(MeshInfo minfo, CtmInputStream input);
Exemple #25
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);
        }
Exemple #26
0
        private float[] readNormals(CtmInputStream input, float[] vertices, int[] indices,
	                                float normalPrecision, int vcount)
        {
            checkTag(input.readLittleInt(), NORM);
            int[] intNormals = input.readPackedInts(vcount, Mesh.CTM_NORMAL_ELEMENT_COUNT, false);
            return restoreNormals(intNormals, vertices, indices, normalPrecision);
        }
Exemple #27
0
        private float[] readVertices(CtmInputStream input, Grid grid, int vcount, float precision)
        {
            checkTag(input.readLittleInt(), VERT);
            int[] intVertices = input.readPackedInts(vcount, Mesh.CTM_POSITION_ELEMENT_COUNT, false);

            checkTag(input.readLittleInt(), GIDX);
            int[] gridIndices = input.readPackedInts(vcount, 1, false);
            for (int i = 1; i < vcount; i++) {
                gridIndices[i] += gridIndices[i - 1];
            }

            return CommonAlgorithm.restoreVertices(intVertices, gridIndices, grid, precision);
        }
Exemple #28
0
        //public static Stopwatch sw = new Stopwatch();

        public CtmFileReader(Stream source)
        {
            input = new CtmInputStream(source);
        }
Exemple #29
0
 public static Grid fromStream(CtmInputStream input)
 {
     return(new Grid(input.readLittleFloatArray(3),
                     input.readLittleFloatArray(3),
                     input.readLittleIntArray(3)));
 }
Exemple #30
0
 public static Grid fromStream(CtmInputStream input)
 {
     return new Grid(input.readLittleFloatArray(3),
                     input.readLittleFloatArray(3),
                     input.readLittleIntArray(3));
 }
Exemple #31
0
 protected override int[] readIntArray(CtmInputStream input, int count, int size, bool signed)
 {
     return(input.readPackedInts(count, size, signed));
 }
Exemple #32
0
 protected override float[] readFloatArray(CtmInputStream input, int count, int size)
 {
     return(input.readPackedFloats(count, size));
 }