Example #1
0
        public virtual void encode(Mesh m, CtmOutputStream output)
        {
            int vc = m.getVertexCount();

            output.writeLittleInt(MeshDecoder.INDX);
            writeIndicies(m.indices, output);

            output.writeLittleInt(MeshDecoder.VERT);
            writeFloatArray(m.vertices, output, vc * 3, 1);

            // Write normals
            if (m.normals != null)
            {
                output.writeLittleInt(MeshDecoder.NORM);
                writeFloatArray(m.normals, output, vc, 3);
            }

            foreach (AttributeData ad in m.texcoordinates)
            {
                output.writeLittleInt(MeshDecoder.TEXC);
                output.writeString(ad.name);
                output.writeString(ad.materialName);
                writeFloatArray(ad.values, output, vc, 2);
            }

            foreach (AttributeData ad in m.attributs)
            {
                output.writeLittleInt(MeshDecoder.ATTR);
                output.writeString(ad.name);
                writeFloatArray(ad.values, output, vc, 4);
            }
        }
Example #2
0
        public virtual void encode(Mesh m, CtmOutputStream output)
        {
            int vc = m.getVertexCount();

            output.writeLittleInt(MeshDecoder.INDX);
            writeIndicies(m.indices, output);

            output.writeLittleInt(MeshDecoder.VERT);
            writeFloatArray(m.vertices, output, vc * 3, 1);

            // Write normals
            if (m.normals != null) {
                output.writeLittleInt(MeshDecoder.NORM);
                writeFloatArray(m.normals, output, vc, 3);
            }

            foreach (AttributeData ad in m.texcoordinates) {
                output.writeLittleInt(MeshDecoder.TEXC);
                output.writeString(ad.name);
                output.writeString(ad.materialName);
                writeFloatArray(ad.values, output, vc, 2);
            }

            foreach (AttributeData ad in m.attributs) {
                output.writeLittleInt(MeshDecoder.ATTR);
                output.writeString(ad.name);
                writeFloatArray(ad.values, output, vc, 4);
            }
        }
Example #3
0
 protected override void writeIndicies(int[] indices, CtmOutputStream output)
 {
     int[] tmp = new int[indices.Length];
     Array.Copy(indices, tmp, tmp.Length);
     rearrangeTriangles(tmp);
     makeIndexDeltas(tmp);
     output.writePackedInts(tmp, tmp.Length / 3, 3, false);
 }
Example #4
0
        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);
        }
Example #5
0
 protected virtual void writeFloatArray(float[] array, CtmOutputStream output, int count, int size)
 {
     output.writeLittleFloatArray(array);
 }
Example #6
0
        public override void encode(Mesh m, CtmOutputStream output)
        {
            Grid grid = setupGrid (m.vertices);
            SortableVertex[] sorted = sortVertices (grid, m.vertices);
            int[] vdeltas = makeVertexDeltas (m.vertices, sorted, grid);

            int[] gridIndicies = new int[m.getVertexCount ()];
            gridIndicies [0] = sorted [0].gridIndex;
            for (int i = 1; i < m.getVertexCount(); ++i) {
                gridIndicies [i] = sorted [i].gridIndex - sorted [i - 1].gridIndex;
            }

            output.writeLittleInt (MG2Decoder.MG2_HEADER_TAG);

            output.writeLittleFloat (vertexPrecision);
            output.writeLittleFloat (normalPrecision);

            grid.writeToStream (output);

            output.writeLittleInt (MeshDecoder.VERT);
            output.writePackedInts (vdeltas, m.getVertexCount (), Mesh.CTM_POSITION_ELEMENT_COUNT, false);

            output.writeLittleInt (MG2Decoder.GIDX);
            output.writePackedInts (gridIndicies, m.getVertexCount (), 1, false);

            output.writeLittleInt (MeshDecoder.INDX);
            int[] indices = reIndexIndices (sorted, m.indices);
            rearrangeTriangles (indices);

            //write indicies
            {
                int[] deltas = new int[indices.Length];
                Array.Copy(indices, deltas, indices.Length);
                makeIndexDeltas (deltas);
                output.writePackedInts (deltas, m.getTriangleCount (), 3, false);
            }

            if (m.hasNormals ()) {

                for (int i = 1; i < m.getVertexCount(); i++) {
                    gridIndicies [i] += gridIndicies [i - 1];
                }
                float[] restoredv = CommonAlgorithm.restoreVertices (vdeltas, gridIndicies, grid, vertexPrecision);

                output.writeLittleInt (MeshDecoder.NORM);
                int[] intNormals = makeNormalDeltas (restoredv, m.normals, indices, sorted);
                output.writePackedInts (intNormals, m.getVertexCount (), Mesh.CTM_NORMAL_ELEMENT_COUNT, false);
            }

            foreach (AttributeData ad in m.texcoordinates) {
                output.writeLittleInt (MeshDecoder.TEXC);
                output.writeString (ad.name);
                output.writeString (ad.materialName);
                output.writeLittleFloat (ad.precision);
                int[] deltas = makeUVCoordDeltas (ad, sorted);
                output.writePackedInts (deltas, m.getVertexCount (), Mesh.CTM_UV_ELEMENT_COUNT, true);
            }

            foreach (AttributeData ad in m.attributs) {
                output.writeLittleInt (MeshDecoder.ATTR);
                output.writeString (ad.name);
                output.writeLittleFloat (ad.precision);
                int[] deltas = makeAttribDeltas (ad, sorted);
                output.writePackedInts (deltas, m.getVertexCount (), Mesh.CTM_ATTR_ELEMENT_COUNT, true);
            }
        }
Example #7
0
        protected override void writeFloatArray(float[] array, CtmOutputStream output,
	                                   int count, int size)
        {
            output.writePackedFloats(array, count, size);
        }
Example #8
0
 protected override void writeIndicies(int[] indices, CtmOutputStream output)
 {
     int[] tmp = new int[indices.Length];
     Array.Copy(indices, tmp, tmp.Length);
     rearrangeTriangles(tmp);
     makeIndexDeltas(tmp);
     output.writePackedInts(tmp, tmp.Length / 3, 3, false);
 }
Example #9
0
 public CtmFileWriter(Stream o, MeshEncoder e)
 {
     output = new CtmOutputStream(o);
     encoder = e;
 }
Example #10
0
 public CtmFileWriter(Stream o, MeshEncoder e, int compressionLevel)
 {
     output = new CtmOutputStream(compressionLevel, o);
     encoder = e;
 }
Example #11
0
 protected virtual void writeIndicies(int[] indices, CtmOutputStream output)
 {
     output.writeLittleIntArray(indices);
 }
Example #12
0
 public CtmFileWriter(Stream o, MeshEncoder e, int compressionLevel)
 {
     output  = new CtmOutputStream(compressionLevel, o);
     encoder = e;
 }
Example #13
0
 protected override void writeFloatArray(float[] array, CtmOutputStream output,
                                         int count, int size)
 {
     output.writePackedFloats(array, count, size);
 }
 protected virtual void writeFloatArray(float[] array, CtmOutputStream output, int count, int size)
 {
     output.writeLittleFloatArray(array);
 }
 protected virtual void writeIndicies(int[] indices, CtmOutputStream output)
 {
     output.writeLittleIntArray(indices);
 }
Example #16
0
 public void writeToStream(CtmOutputStream output)
 {
     output.writeLittleFloatArray(min);
     output.writeLittleFloatArray(max);
     output.writeLittleIntArray(division);
 }
Example #17
0
 public void writeToStream(CtmOutputStream output)
 {
     output.writeLittleFloatArray(min);
     output.writeLittleFloatArray(max);
     output.writeLittleIntArray(division);
 }
        public override void encode(Mesh m, CtmOutputStream output)
        {
            Grid grid = setupGrid(m.vertices);

            SortableVertex[] sorted  = sortVertices(grid, m.vertices);
            int[]            vdeltas = makeVertexDeltas(m.vertices, sorted, grid);

            int[] gridIndicies = new int[m.getVertexCount()];
            gridIndicies [0] = sorted [0].gridIndex;
            for (int i = 1; i < m.getVertexCount(); ++i)
            {
                gridIndicies [i] = sorted [i].gridIndex - sorted [i - 1].gridIndex;
            }

            output.writeLittleInt(MG2Decoder.MG2_HEADER_TAG);

            output.writeLittleFloat(vertexPrecision);
            output.writeLittleFloat(normalPrecision);

            grid.writeToStream(output);

            output.writeLittleInt(MeshDecoder.VERT);
            output.writePackedInts(vdeltas, m.getVertexCount(), Mesh.CTM_POSITION_ELEMENT_COUNT, false);

            output.writeLittleInt(MG2Decoder.GIDX);
            output.writePackedInts(gridIndicies, m.getVertexCount(), 1, false);

            output.writeLittleInt(MeshDecoder.INDX);
            int[] indices = reIndexIndices(sorted, m.indices);
            rearrangeTriangles(indices);

            //write indicies
            {
                int[] deltas = new int[indices.Length];
                Array.Copy(indices, deltas, indices.Length);
                makeIndexDeltas(deltas);
                output.writePackedInts(deltas, m.getTriangleCount(), 3, false);
            }

            if (m.hasNormals())
            {
                for (int i = 1; i < m.getVertexCount(); i++)
                {
                    gridIndicies [i] += gridIndicies [i - 1];
                }
                float[] restoredv = CommonAlgorithm.restoreVertices(vdeltas, gridIndicies, grid, vertexPrecision);

                output.writeLittleInt(MeshDecoder.NORM);
                int[] intNormals = makeNormalDeltas(restoredv, m.normals, indices, sorted);
                output.writePackedInts(intNormals, m.getVertexCount(), Mesh.CTM_NORMAL_ELEMENT_COUNT, false);
            }

            foreach (AttributeData ad in m.texcoordinates)
            {
                output.writeLittleInt(MeshDecoder.TEXC);
                output.writeString(ad.name);
                output.writeString(ad.materialName);
                output.writeLittleFloat(ad.precision);
                int[] deltas = makeUVCoordDeltas(ad, sorted);
                output.writePackedInts(deltas, m.getVertexCount(), Mesh.CTM_UV_ELEMENT_COUNT, true);
            }

            foreach (AttributeData ad in m.attributs)
            {
                output.writeLittleInt(MeshDecoder.ATTR);
                output.writeString(ad.name);
                output.writeLittleFloat(ad.precision);
                int[] deltas = makeAttribDeltas(ad, sorted);
                output.writePackedInts(deltas, m.getVertexCount(), Mesh.CTM_ATTR_ELEMENT_COUNT, true);
            }
        }
Example #19
0
 public CtmFileWriter(Stream o, MeshEncoder e)
 {
     output  = new CtmOutputStream(o);
     encoder = e;
 }