static PrimitiveManager DecodePrimitivesUnweighted(GeometryEntry geo) { PrimitiveManager manager = DecodePrimitives(geo); Vector3 * pVert = null; ushort * pVInd = (ushort *)manager._indices.Address; int vCount = 0; List <Vertex3> vertList = new List <Vertex3>(manager._pointCount); manager._vertices = vertList; //Find vertex source foreach (SourceEntry s in geo._sources) { if (s._id == geo._verticesInput._source) { UnsafeBuffer b = s._arrayData as UnsafeBuffer; pVert = (Vector3 *)b.Address; vCount = b.Length / 12; break; } } UnsafeBuffer remap = new UnsafeBuffer(vCount * 2); ushort * pRemap = (ushort *)remap.Address; //Create remap table for (int i = 0; i < vCount; i++) { //Create Vertex and look for match Vertex3 v = new Vertex3(pVert[i]); int index = 0; while (index < vertList.Count) { if (v.Equals(vertList[index])) { break; } index++; } if (index == vertList.Count) { vertList.Add(v); } pRemap[i] = (ushort)index; } //Remap vertex indices for (int i = 0; i < manager._pointCount; i++, pVInd++) { *pVInd = pRemap[*pVInd]; } remap.Dispose(); //manager.MergeTempData(); return(manager); }
static void NullWeight(PrimitiveManager manager, GeometryEntry geo) { Vector3 * pVert = null; ushort * pVInd = (ushort *)manager._indices.Address; List <Vertex3> vertList = new List <Vertex3>(manager._pointCount); //Find vertex source foreach (SourceEntry s in geo._sources) { if (s._id == geo._verticesInput._source) { pVert = (Vector3 *)((UnsafeBuffer)s._arrayData).Address; break; } } //Construct Vertex from new weight for (int i = 0; i < manager._pointCount; i++) { //Create Vertex and look for match Vertex3 v = new Vertex3(pVert[*pVInd]); int index = 0; while (index < vertList.Count) { if (v.Equals(vertList[i])) { break; } index++; } if (index == vertList.Count) { vertList.Add(v); } //Assign new index *pVInd++ = (ushort)index; } }
static PrimitiveManager DecodePrimitivesUnweighted(NodeEntry n, GeometryEntry geo) { PrimitiveManager manager = DecodePrimitives(n._matrix, geo); Vector3* pVert = null; ushort* pVInd = (ushort*)manager._indices.Address; int vCount = 0; List<Vertex3> vertList = new List<Vertex3>(manager._pointCount); manager._vertices = vertList; //Find vertex source foreach (SourceEntry s in geo._sources) if (s._id == geo._verticesInput._source) { UnsafeBuffer b = s._arrayData as UnsafeBuffer; pVert = (Vector3*)b.Address; vCount = b.Length / 12; break; } UnsafeBuffer remap = new UnsafeBuffer(vCount * 2); ushort* pRemap = (ushort*)remap.Address; //Create remap table for (int i = 0; i < vCount; i++) { //Create Vertex and look for match Vertex3 v = new Vertex3(n._matrix * pVert[i]); int index = 0; while (index < vertList.Count) { if (v.Equals(vertList[index])) break; index++; } if (index == vertList.Count) vertList.Add(v); pRemap[i] = (ushort)index; } //Remap vertex indices for (int i = 0; i < manager._pointCount; i++, pVInd++) *pVInd = pRemap[*pVInd]; remap.Dispose(); return manager; }
static void Weight(PrimitiveManager manager, SkinEntry skin, DecoderShell shell, GeometryEntry geo, InfluenceManager iMan) { MDL0BoneNode[] boneList; MDL0BoneNode bone = null; int boneCount; string[] jointStrings = null; byte * pCmd = stackalloc byte[4]; int cmdCount = skin._weightInputs.Count; float weight = 0; float * pWeights = null; Vector3 * pVert = null; ushort * pVInd = (ushort *)manager._indices.Address; List <Vertex3> vertList = new List <Vertex3>(skin._weightCount); manager._vertices = vertList; //Find vertex source foreach (SourceEntry s in geo._sources) { if (s._id == geo._verticesInput._source) { pVert = (Vector3 *)((UnsafeBuffer)s._arrayData).Address; break; } } //Find joint source foreach (InputEntry inp in skin._jointInputs) { if (inp._semantic == SemanticType.JOINT) { foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { jointStrings = src._arrayData as string[]; break; } } break; } } //Populate bone list boneCount = jointStrings.Length; boneList = new MDL0BoneNode[boneCount]; for (int i = 0; i < boneCount; i++) { boneList[i] = shell.FindNode(jointStrings[i])._node as MDL0BoneNode; } //Build command list foreach (InputEntry inp in skin._weightInputs) { switch (inp._semantic) { case SemanticType.JOINT: pCmd[inp._offset] = 1; break; case SemanticType.WEIGHT: pCmd[inp._offset] = 2; //Get weight source foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { pWeights = (float *)((UnsafeBuffer)src._arrayData).Address; break; } } break; default: pCmd[inp._offset] = 0; break; } } //Construct Vertex from new weight for (int i = 0; i < skin._weightCount; i++) { //Create influence int iCount = skin._weights.Length / cmdCount; Influence inf = new Influence(iCount); fixed(int *p = skin._weights[i]) { int *iPtr = p; for (int x = 0; x < iCount; x++) { for (int z = 0; z < cmdCount; z++, iPtr++) { if (pCmd[z] == 1) { bone = boneList[*iPtr]; } else if (pCmd[z] == 2) { weight = pWeights[*iPtr]; } } inf._weights[x] = new BoneWeight(bone, weight); } } //Match with manager inf = iMan.AddOrCreateInf(inf); //Create Vertex and look for match Vertex3 v = new Vertex3(pVert[*pVInd], inf); int index = 0; while (index < vertList.Count) { if (v.Equals(vertList[i])) { break; } index++; } if (index == vertList.Count) { vertList.Add(v); } //Assign new index *pVInd++ = (ushort)index; } }