예제 #1
0
        public static Geometry Polylist(string geoID, string geoName, string matName, float[] positions, float[] normals, float[] texcoords, float[] vertexColors, int[] vCount, int[] primitive)
        {
            int numSources = 1;

            if (normals != null)
            {
                numSources++;
            }
            if (texcoords != null)
            {
                numSources++;
            }
            if (vertexColors != null)
            {
                numSources++;
            }

            if ((positions == null ? true : positions.Length == 0))
            {
                throw new ArgumentException("Missing position data. Provide at least position data to use Polylist()", "positions");
            }
            Mesh mesh = new Mesh()
            {
                source = new Source[numSources]
            };
            Polylist polyList = new Polylist((ulong)vCount.Length, matName, vCount, primitive)
            {
                input = new InputOffset[numSources]
            };

            mesh.primitives = new object[] { polyList };
            ulong sInd = (ulong)0;

            mesh.source[sInd]    = Source.CreatePositions(geoName, positions);
            polyList.input[sInd] = new InputOffset("VERTEX", string.Concat("#", geoName, "-VERTEX", sInd));
            if (normals != null)
            {
                sInd++;
                mesh.source[sInd]    = Source.CreateNormals(geoName, 0, normals);
                polyList.input[sInd] = new InputOffset("NORMAL", string.Concat("#", geoName, "-Normal0", sInd));
            }
            if (texcoords != null)
            {
                sInd++;
                mesh.source[sInd]    = Source.CreateUVs(geoName, 0, texcoords);
                polyList.input[sInd] = new InputOffset("TEXCOORD", string.Concat("#", geoName, "-UV", sInd));
            }
            if (vertexColors != null)
            {
                sInd++;
                mesh.source[sInd]    = Source.CreateVertexColors(geoName, 0, vertexColors);
                polyList.input[sInd] = new InputOffset("COLOR", string.Concat("#", geoName, "-VERTEX_COLOR0", sInd));
            }
            mesh.vertices = DAEGeometry.GenerateVertices(geoName);
            Geometry geo = new Geometry(geoID, geoName, mesh);

            return(geo);
        }
예제 #2
0
        public static Geometry Triangles(string geoID, string geoName, string matName, float[] positions, float[] normals, float[] texcoords, float[] vertexColors, int[] triangles)
        {
            int numSources = 1;

            if (normals != null)
            {
                numSources++;
            }
            if (texcoords != null)
            {
                numSources++;
            }
            if (vertexColors != null)
            {
                numSources++;
            }
            Mesh mesh = new Mesh()
            {
                source = new Source[numSources]
            };
            Triangles tris = new Triangles((ulong)((long)triangles.Length / (long)(3 * numSources)), matName, triangles)
            {
                input = new InputOffset[numSources]
            };

            mesh.primitives = new object[] { tris };
            ulong sInd = 0;

            mesh.source[sInd] = Source.CreatePositions(geoName, positions);
            tris.input[sInd]  = new InputOffset("VERTEX", string.Concat("#", geoName, "-VERTEX", sInd));
            if (normals != null)
            {
                sInd++;
                mesh.source[sInd] = Source.CreateNormals(geoName, 0, normals);
                tris.input[sInd]  = new InputOffset("NORMAL", string.Concat("#", geoName, "-Normal0", sInd));
            }
            if (texcoords != null)
            {
                sInd++;
                mesh.source[sInd] = Source.CreateUVs(geoName, 0, texcoords);
                tris.input[sInd]  = new InputOffset("TEXCOORD", string.Concat("#", geoName, "-UV0", sInd));
            }
            if (vertexColors != null)
            {
                sInd++;
                mesh.source[sInd] = Source.CreateVertexColors(geoName, 0, vertexColors);
                tris.input[sInd]  = new InputOffset("COLOR", string.Concat("#", geoName, "-VERTEX_COLOR0", sInd));
            }
            mesh.vertices = DAEGeometry.GenerateVertices(geoName);
            Geometry geo = new Geometry(geoID, geoName, mesh);

            return(geo);
        }