Exemplo n.º 1
0
        // init with factory node info & binary reader
        internal RwMeshListNode(RwNodeFactory.RwNodeHeader header, BinaryReader reader)
            : base(header)
        {
            mPrimitiveType = (RwPrimitiveType)reader.ReadUInt32();
            int numSplits = reader.ReadInt32();

            mPrimitiveCount = reader.ReadInt32();

            mMeshes = new RwMesh[numSplits];
            for (int i = 0; i < numSplits; i++)
            {
                mMeshes[i] = new RwMesh(reader);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize a new <see cref="RwMeshListNode"/> using a <see cref="RwGeometryNode"/> and the primitive id for the split data.
        /// </summary>
        /// <param name="geometryNode"></param>
        /// <param name="primitiveType"></param>
        public RwMeshListNode(RwGeometryNode geometryNode, RwPrimitiveType primitiveType = RwPrimitiveType.TriangleStrip, RwNode parent = null)
            : base(RwNodeId.RwMeshListNode, parent)
        {
            // set id and prim count
            mPrimitiveType = primitiveType;
            //mPrimitiveCount = geometryNode.TriangleCount;

            // pass 1: order the triangles by ascending material id
            var sortedTriangles = geometryNode.Triangles.OrderBy(tri => tri.MatId);

            // pass 2: split the indices
            List <ushort>[] matSplitsIndices   = new List <ushort> [geometryNode.MaterialCount];
            List <ushort>   curMatSplitIndices = null;
            int             curMatIdx          = -1;

            foreach (var tri in sortedTriangles)
            {
                if (tri.MatId != curMatIdx)
                {
                    if (curMatIdx != -1)
                    {
                        matSplitsIndices[curMatIdx] = curMatSplitIndices;
                    }

                    curMatIdx          = tri.MatId;
                    curMatSplitIndices = new List <ushort>();
                }

                curMatSplitIndices.Add(tri.A);
                curMatSplitIndices.Add(tri.B);
                curMatSplitIndices.Add(tri.C);
            }

            matSplitsIndices[curMatIdx] = curMatSplitIndices;

            // pass 3: create the split data
            mMeshes = new RwMesh[geometryNode.MaterialCount];
            for (int i = 0; i < mMeshes.Length; i++)
            {
                ushort[] matSplitIndices = matSplitsIndices[i].ToArray();
                int      triangleCount;

                if (primitiveType == RwPrimitiveType.TriangleStrip)
                {
                    if (NvTriStripUtility.GenerateStrips(matSplitIndices, out PrimitiveGroup[] primitives) && primitives[0].Type == ManagedNvTriStrip.PrimitiveType.TriangleStrip)
Exemplo n.º 3
0
        /// <summary>
        /// Initialize a new <see cref="RwMeshListNode"/> using a <see cref="RwGeometryNode"/> and the primitive id for the split data.
        /// </summary>
        /// <param name="geometryNode"></param>
        /// <param name="primitiveType"></param>
        public RwMeshListNode(RwGeometryNode geometryNode, RwPrimitiveType primitiveType = RwPrimitiveType.TriangleStrip, RwNode parent = null)
            : base(RwNodeId.RwMeshListNode, parent)
        {
            // set id and prim count
            mPrimitiveType = primitiveType;
            //mPrimitiveCount = geometryNode.TriangleCount;

            // pass 1: order the triangles by ascending material id
            var sortedTriangles = geometryNode.Triangles.OrderBy(tri => tri.MatId);

            // pass 2: split the indices
            List <ushort>[] matSplitsIndices   = new List <ushort> [geometryNode.MaterialCount];
            List <ushort>   curMatSplitIndices = null;
            int             curMatIdx          = -1;

            foreach (var tri in sortedTriangles)
            {
                if (tri.MatId != curMatIdx)
                {
                    if (curMatIdx != -1)
                    {
                        matSplitsIndices[curMatIdx] = curMatSplitIndices;
                    }

                    curMatIdx          = tri.MatId;
                    curMatSplitIndices = new List <ushort>();
                }

                curMatSplitIndices.Add(tri.A);
                curMatSplitIndices.Add(tri.B);
                curMatSplitIndices.Add(tri.C);
            }

            matSplitsIndices[curMatIdx] = curMatSplitIndices;

            // pass 3: create the split data
            mMeshes = new RwMesh[geometryNode.MaterialCount];
            for (int i = 0; i < mMeshes.Length; i++)
            {
                ushort[] matSplitIndices = matSplitsIndices[i].ToArray();
                int      triangleCount;

                if (primitiveType == RwPrimitiveType.TriangleStrip)
                {
                    if (sStripifier.GenerateStrips(matSplitIndices, out var primitives) && primitives[0].Type == NvTriStripDotNet.PrimitiveType.TriangleStrip)
                    {
                        matSplitIndices     = primitives[0].Indices;
                        geometryNode.Flags |= RwGeometryFlags.CanTriStrip;
                        triangleCount       = matSplitIndices.Length - 2;
                    }
                    else
                    {
                        mPrimitiveType = RwPrimitiveType.TriangleList;
                        triangleCount  = matSplitIndices.Length / 3;
                        //throw new System.Exception("Failed to generate strips.");
                    }

                    /*
                     * NvTriStripDotNet.PrimitiveGroup[] primitives;
                     * var tristripper = new NvTriStripDotNet.NvTriStrip();
                     * if (tristripper.GenerateStrips(matSplitIndices, out primitives))
                     * {
                     *  matSplitIndices = primitives[0].indices.Cast<ushort>().ToArray();
                     * }
                     */
                }
                else
                {
                    triangleCount = matSplitIndices.Length / 3;
                }

                mPrimitiveCount += triangleCount;
                mMeshes[i]       = new RwMesh(i, matSplitIndices);
            }
        }