ClearCollisionData() public method

public ClearCollisionData ( ) : void
return void
Exemplo n.º 1
0
        private static void TransformWMO(MapObjectDefinition currentMODF, WMORoot currentWMO)
        {
            currentWMO.ClearCollisionData();
            var position = currentMODF.Position;
            var posX     = (position.X - TerrainConstants.CenterPoint) * -1;
            var posY     = (position.Y - TerrainConstants.CenterPoint) * -1;
            var origin   = new Vector3(posX, posY, position.Z);
            //origin = new Vector3(0.0f);

            //DrawWMOPositionPoint(origin, currentWMO);
            //DrawBoundingBox(currentMODF.Extents, Color.Purple, currentWMO);

            //var rotateZ = Matrix.CreateRotationZ(0*RadiansPerDegree);
            var rotateZ = Matrix.CreateRotationZ((currentMODF.OrientationB + 180) * RadiansPerDegree);
            //var rotateX = Matrix.CreateRotationX(currentMODF.OrientationC * RadiansPerDegree);
            //var rotateY = Matrix.CreateRotationY(currentMODF.OrientationA * RadiansPerDegree);

            int offset;


            foreach (var currentGroup in currentWMO.Groups)
            {
                if (currentGroup == null)
                {
                    continue;
                }
                //if (!currentGroup.Header.HasMLIQ) continue;

                var usedTris      = new Dictionary <Index3, int>();
                var wmoTrisUnique = new List <Index3>();

                foreach (var node in currentGroup.BSPNodes)
                {
                    if (node.TriIndices == null)
                    {
                        continue;
                    }
                    foreach (var index3 in node.TriIndices)
                    {
                        if (usedTris.ContainsKey(index3))
                        {
                            continue;
                        }

                        usedTris.Add(index3, 0);
                        wmoTrisUnique.Add(index3);
                    }
                }

                var newIndices = new Dictionary <int, int>();
                foreach (var tri in wmoTrisUnique)
                {
                    int newIndex;
                    if (!newIndices.TryGetValue(tri.Index0, out newIndex))
                    {
                        newIndex = currentWMO.WmoVertices.Count;
                        newIndices.Add(tri.Index0, newIndex);

                        var basePosVec     = currentGroup.Vertices[tri.Index0];
                        var rotatedPosVec  = Vector3.Transform(basePosVec, rotateZ);
                        var finalPosVector = rotatedPosVec + origin;
                        currentWMO.WmoVertices.Add(finalPosVector);
                    }
                    currentWMO.WmoIndices.Add(newIndex);

                    if (!newIndices.TryGetValue(tri.Index1, out newIndex))
                    {
                        newIndex = currentWMO.WmoVertices.Count;
                        newIndices.Add(tri.Index1, newIndex);

                        var basePosVec     = currentGroup.Vertices[tri.Index1];
                        var rotatedPosVec  = Vector3.Transform(basePosVec, rotateZ);
                        var finalPosVector = rotatedPosVec + origin;
                        currentWMO.WmoVertices.Add(finalPosVector);
                    }
                    currentWMO.WmoIndices.Add(newIndex);

                    if (!newIndices.TryGetValue(tri.Index2, out newIndex))
                    {
                        newIndex = currentWMO.WmoVertices.Count;
                        newIndices.Add(tri.Index2, newIndex);

                        var basePosVec     = currentGroup.Vertices[tri.Index2];
                        var rotatedPosVec  = Vector3.Transform(basePosVec, rotateZ);
                        var finalPosVector = rotatedPosVec + origin;
                        currentWMO.WmoVertices.Add(finalPosVector);
                    }
                    currentWMO.WmoIndices.Add(newIndex);
                }

                //for (var i = 0; i < currentGroup.Vertices.Count; i++)
                //{
                //    var basePosVector = currentGroup.Vertices[i];
                //    var rotatedPosVector = Vector3.Transform(basePosVector, rotateZ);
                //    var finalPosVector = rotatedPosVector + origin;

                //    //var baseNormVector = currentGroup.Normals[i];
                //    //var rotatedNormVector = Vector3.Transform(baseNormVector, rotateZ);

                //    currentWMO.WmoVertices.Add(finalPosVector);
                //}

                //for (var index = 0; index < currentGroup.Indices.Count; index++)
                //{
                //    currentWMO.WmoIndices.Add(currentGroup.Indices[index].Index0 + offset);
                //    currentWMO.WmoIndices.Add(currentGroup.Indices[index].Index1 + offset);
                //    currentWMO.WmoIndices.Add(currentGroup.Indices[index].Index2 + offset);
                //}

                // WMO Liquids
                if (!currentGroup.Header.HasMLIQ)
                {
                    continue;
                }

                var liqInfo   = currentGroup.LiquidInfo;
                var liqOrigin = liqInfo.BaseCoordinates;

                offset = currentWMO.WmoVertices.Count;
                for (var xStep = 0; xStep < liqInfo.XVertexCount; xStep++)
                {
                    for (var yStep = 0; yStep < liqInfo.YVertexCount; yStep++)
                    {
                        var xPos    = liqOrigin.X + xStep * TerrainConstants.UnitSize;
                        var yPos    = liqOrigin.Y + yStep * TerrainConstants.UnitSize;
                        var zPosTop = liqInfo.HeightMapMax[xStep, yStep];

                        var liqVecTop = new Vector3(xPos, yPos, zPosTop);

                        var rotatedTop = Vector3.Transform(liqVecTop, rotateZ);
                        var vecTop     = rotatedTop + origin;

                        currentWMO.WmoLiquidVertices.Add(vecTop);
                    }
                }

                for (var row = 0; row < liqInfo.XTileCount; row++)
                {
                    for (var col = 0; col < liqInfo.YTileCount; col++)
                    {
                        if ((liqInfo.LiquidTileFlags[row, col] & 0x0F) == 0x0F)
                        {
                            continue;
                        }

                        var index = ((row + 1) * (liqInfo.YVertexCount) + col);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = (row * (liqInfo.YVertexCount) + col);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = (row * (liqInfo.YVertexCount) + col + 1);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = ((row + 1) * (liqInfo.YVertexCount) + col + 1);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = ((row + 1) * (liqInfo.YVertexCount) + col);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = (row * (liqInfo.YVertexCount) + col + 1);
                        currentWMO.WmoLiquidIndices.Add(offset + index);
                    }
                }
            }

            //Rotate the M2s to the new orientation
            if (currentWMO.WMOM2s != null)
            {
                foreach (var currentM2 in currentWMO.WMOM2s)
                {
                    offset = currentWMO.WmoVertices.Count;
                    for (var i = 0; i < currentM2.Vertices.Count; i++)
                    {
                        var basePosition    = currentM2.Vertices[i];
                        var rotatedPosition = Vector3.Transform(basePosition, rotateZ);
                        var finalPosition   = rotatedPosition + origin;

                        //var rotatedNormal = Vector3.Transform(basePosition, rotateZ);

                        currentWMO.WmoM2Vertices.Add(finalPosition);
                    }

                    foreach (var index in currentM2.Indices)
                    {
                        currentWMO.WmoM2Indices.Add(index + offset);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void TransformWMO(MapObjectDefinition currentMODF, WMORoot currentWMO)
        {
            currentWMO.ClearCollisionData();
            var position = currentMODF.Position;
            var posX = (position.X - TerrainConstants.CenterPoint)*-1;
            var posY = (position.Y - TerrainConstants.CenterPoint)*-1;
            var origin = new Vector3(posX, posY, position.Z);
            //origin = new Vector3(0.0f);

            //DrawWMOPositionPoint(origin, currentWMO);
            //DrawBoundingBox(currentMODF.Extents, Color.Purple, currentWMO);

            //var rotateZ = Matrix.CreateRotationZ(0*RadiansPerDegree);
            var rotateZ = Matrix.CreateRotationZ((currentMODF.OrientationB + 180)*RadiansPerDegree);
            //var rotateX = Matrix.CreateRotationX(currentMODF.OrientationC * RadiansPerDegree);
            //var rotateY = Matrix.CreateRotationY(currentMODF.OrientationA * RadiansPerDegree);

            int offset;

            foreach (var currentGroup in currentWMO.Groups)
            {
                if (currentGroup == null) continue;
                //if (!currentGroup.Header.HasMLIQ) continue;

                var usedTris = new Dictionary<Index3, int>();
                var wmoTrisUnique = new List<Index3>();

                foreach (var node in currentGroup.BSPNodes)
                {
                    if (node.TriIndices == null) continue;
                    foreach (var index3 in node.TriIndices)
                    {
                        if (usedTris.ContainsKey(index3)) continue;

                        usedTris.Add(index3, 0);
                        wmoTrisUnique.Add(index3);
                    }
                }

                var newIndices = new Dictionary<int, int>();
                foreach (var tri in wmoTrisUnique)
                {
                    int newIndex;
                    if (!newIndices.TryGetValue(tri.Index0, out newIndex))
                    {
                        newIndex = currentWMO.WmoVertices.Count;
                        newIndices.Add(tri.Index0, newIndex);

                        var basePosVec = currentGroup.Vertices[tri.Index0];
                        var rotatedPosVec = Vector3.Transform(basePosVec, rotateZ);
                        var finalPosVector = rotatedPosVec + origin;
                        currentWMO.WmoVertices.Add(finalPosVector);
                    }
                    currentWMO.WmoIndices.Add(newIndex);

                    if (!newIndices.TryGetValue(tri.Index1, out newIndex))
                    {
                        newIndex = currentWMO.WmoVertices.Count;
                        newIndices.Add(tri.Index1, newIndex);

                        var basePosVec = currentGroup.Vertices[tri.Index1];
                        var rotatedPosVec = Vector3.Transform(basePosVec, rotateZ);
                        var finalPosVector = rotatedPosVec + origin;
                        currentWMO.WmoVertices.Add(finalPosVector);
                    }
                    currentWMO.WmoIndices.Add(newIndex);

                    if (!newIndices.TryGetValue(tri.Index2, out newIndex))
                    {
                        newIndex = currentWMO.WmoVertices.Count;
                        newIndices.Add(tri.Index2, newIndex);

                        var basePosVec = currentGroup.Vertices[tri.Index2];
                        var rotatedPosVec = Vector3.Transform(basePosVec, rotateZ);
                        var finalPosVector = rotatedPosVec + origin;
                        currentWMO.WmoVertices.Add(finalPosVector);
                    }
                    currentWMO.WmoIndices.Add(newIndex);
                }

                //for (var i = 0; i < currentGroup.Vertices.Count; i++)
                //{
                //    var basePosVector = currentGroup.Vertices[i];
                //    var rotatedPosVector = Vector3.Transform(basePosVector, rotateZ);
                //    var finalPosVector = rotatedPosVector + origin;

                //    //var baseNormVector = currentGroup.Normals[i];
                //    //var rotatedNormVector = Vector3.Transform(baseNormVector, rotateZ);

                //    currentWMO.WmoVertices.Add(finalPosVector);
                //}

                //for (var index = 0; index < currentGroup.Indices.Count; index++)
                //{
                //    currentWMO.WmoIndices.Add(currentGroup.Indices[index].Index0 + offset);
                //    currentWMO.WmoIndices.Add(currentGroup.Indices[index].Index1 + offset);
                //    currentWMO.WmoIndices.Add(currentGroup.Indices[index].Index2 + offset);
                //}

                // WMO Liquids
                if (!currentGroup.Header.HasMLIQ) continue;

                var liqInfo = currentGroup.LiquidInfo;
                var liqOrigin = liqInfo.BaseCoordinates;

                offset = currentWMO.WmoVertices.Count;
                for (var xStep = 0; xStep < liqInfo.XVertexCount; xStep++)
                {
                    for (var yStep = 0; yStep < liqInfo.YVertexCount; yStep++)
                    {
                        var xPos = liqOrigin.X + xStep * TerrainConstants.UnitSize;
                        var yPos = liqOrigin.Y + yStep * TerrainConstants.UnitSize;
                        var zPosTop = liqInfo.HeightMapMax[xStep, yStep];

                        var liqVecTop = new Vector3(xPos, yPos, zPosTop);

                        var rotatedTop = Vector3.Transform(liqVecTop, rotateZ);
                        var vecTop = rotatedTop + origin;

                        currentWMO.WmoLiquidVertices.Add(vecTop);
                    }
                }

                for (var row = 0; row < liqInfo.XTileCount; row++)
                {
                    for (var col = 0; col < liqInfo.YTileCount; col++)
                    {
                        if ((liqInfo.LiquidTileFlags[row, col] & 0x0F) == 0x0F) continue;

                        var index = ((row + 1)*(liqInfo.YVertexCount) + col);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = (row*(liqInfo.YVertexCount) + col);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = (row*(liqInfo.YVertexCount) + col + 1);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = ((row + 1)*(liqInfo.YVertexCount) + col + 1);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = ((row + 1)*(liqInfo.YVertexCount) + col);
                        currentWMO.WmoLiquidIndices.Add(offset + index);

                        index = (row*(liqInfo.YVertexCount) + col + 1);
                        currentWMO.WmoLiquidIndices.Add(offset + index);
                    }
                }
            }

            //Rotate the M2s to the new orientation
            if (currentWMO.WMOM2s != null)
            {
                foreach (var currentM2 in currentWMO.WMOM2s)
                {
                    offset = currentWMO.WmoVertices.Count;
                    for (var i = 0; i < currentM2.Vertices.Count; i++)
                    {
                        var basePosition = currentM2.Vertices[i];
                        var rotatedPosition = Vector3.Transform(basePosition, rotateZ);
                        var finalPosition = rotatedPosition + origin;

                        //var rotatedNormal = Vector3.Transform(basePosition, rotateZ);

                        currentWMO.WmoM2Vertices.Add(finalPosition);
                    }

                    foreach (var index in currentM2.Indices)
                    {
                        currentWMO.WmoM2Indices.Add(index + offset);
                    }
                }
            }
        }