private void CreateRenderData(Mesh meshToBuildListFor, double nonPlanarAngleRequired = 0) { edgeLinesData = new VectorPOD <WireVertexData>(); // first make sure all the textures are created foreach (MeshEdge meshEdge in meshToBuildListFor.MeshEdges) { if (nonPlanarAngleRequired > 0) { if (meshEdge.GetNumFacesSharingEdge() == 2) { FaceEdge firstFaceEdge = meshEdge.firstFaceEdge; FaceEdge nextFaceEdge = meshEdge.firstFaceEdge.radialNextFaceEdge; double angle = Vector3.CalculateAngle(firstFaceEdge.containingFace.normal, nextFaceEdge.containingFace.normal); if (angle > MathHelper.Tau * .1) { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } else { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } else { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } }
static public void CreatePointer(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, RGBA_Bytes color) { Vector3 direction = endPos - startPos; Vector3 directionNormal = direction.GetNormal(); Vector3 startSweepDirection = Vector3.GetPerpendicular(startPos, endPos).GetNormal(); int[] tubeStartIndices = new int[steps]; for (int i = 0; i < steps; i++) { // create tube ends verts Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 tubeStart = startPos + offset; tubeStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); Vector3 tubeEnd = endPos + offset; } int tipEndIndex = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(endPos, directionNormal, color)); for (int i = 0; i < steps; i++) { // create tube polys indexData.Add(tubeStartIndices[i]); indexData.Add(tubeStartIndices[(i + 1) % steps]); indexData.Add(tipEndIndex); } }
private void bezier(double x1, double y1, double x2, double y2, double x3, double y3) { m_points.Add(new PointD(x1, y1)); recursive_bezier(x1, y1, x2, y2, x3, y3, 0); m_points.Add(new PointD(x3, y3)); }
private void Bezier(T x1, T y1, T x2, T y2, T x3, T y3) { m_points.Add(MatrixFactory <T> .CreateVector2D(x1, y1)); RecursiveBezier(x1, y1, x2, y2, x3, y3, 0); m_points.Add(MatrixFactory <T> .CreateVector2D(x3, y3)); }
void MasterAlpha(int style, double alpha) { if (style >= 0) { while ((int)m_master_alpha.Size() <= style) { m_master_alpha.Add(AAMask); } m_master_alpha.Array[style] = Basics.RoundUint(alpha * AAMask); } }
private void AddVertex(VectorPOD <WireVertexData> edgeLines, Vector3Float vertex0, Vector3Float vertex1) { WireVertexData tempVertex; tempVertex.PositionsX = (float)vertex0.X; tempVertex.PositionsY = (float)vertex0.Y; tempVertex.PositionsZ = (float)vertex0.Z; edgeLines.Add(tempVertex); tempVertex.PositionsX = (float)vertex1.X; tempVertex.PositionsY = (float)vertex1.Y; tempVertex.PositionsZ = (float)vertex1.Z; edgeLines.Add(tempVertex); }
private WireVertexData AddVertex(Vector3 vertex0, Vector3 vertex1) { WireVertexData tempVertex; tempVertex.positionsX = (float)vertex0.x; tempVertex.positionsY = (float)vertex0.y; tempVertex.positionsZ = (float)vertex0.z; edgeLinesData.Add(tempVertex); tempVertex.positionsX = (float)vertex1.x; tempVertex.positionsY = (float)vertex1.y; tempVertex.positionsZ = (float)vertex1.z; return(tempVertex); }
private void CreateRenderData(Mesh meshToBuildListFor, Func <Vector3Float, Color> getColorFunc) { subMeshs = new List <SubTriangleMesh>(); SubTriangleMesh currentSubMesh = null; VectorPOD <VertexTextureData> textureData = null; VectorPOD <VertexColorData> colorData = null; VectorPOD <VertexNormalData> normalData = null; VectorPOD <VertexPositionData> positionData = null; // first make sure all the textures are created for (int faceIndex = 0; faceIndex < meshToBuildListFor.Faces.Count; faceIndex++) { FaceTextureData faceTexture; meshToBuildListFor.FaceTextures.TryGetValue(faceIndex, out faceTexture); if (faceTexture != null) { ImageGlPlugin.GetImageGlPlugin(faceTexture.image, true); } // don't compare the data of the texture but rather if they are just the same object if (subMeshs.Count == 0 || (faceTexture != null && (object)subMeshs[subMeshs.Count - 1].texture != (object)faceTexture.image)) { SubTriangleMesh newSubMesh = new SubTriangleMesh(); newSubMesh.texture = faceTexture == null ? null : faceTexture.image; subMeshs.Add(newSubMesh); if (getColorFunc != null) { newSubMesh.UseVertexColors = true; } currentSubMesh = subMeshs[subMeshs.Count - 1]; textureData = currentSubMesh.textureData; colorData = currentSubMesh.colorData; normalData = currentSubMesh.normalData; positionData = currentSubMesh.positionData; } VertexColorData color = new VertexColorData(); if (getColorFunc != null) { var faceColor = getColorFunc(meshToBuildListFor.Faces[faceIndex].normal); color = new VertexColorData { red = faceColor.red, green = faceColor.green, blue = faceColor.blue }; } VertexTextureData tempTexture; VertexNormalData tempNormal; VertexPositionData tempPosition; tempTexture.textureU = faceTexture == null ? 0 : (float)faceTexture.uv0.X; tempTexture.textureV = faceTexture == null ? 0 : (float)faceTexture.uv0.Y; var normal = meshToBuildListFor.Faces[faceIndex].normal; tempNormal.normalX = normal.X; tempNormal.normalY = normal.Y; tempNormal.normalZ = normal.Z; int vertexIndex = meshToBuildListFor.Faces[faceIndex].v0; tempPosition.positionX = (float)meshToBuildListFor.Vertices[vertexIndex].X; tempPosition.positionY = (float)meshToBuildListFor.Vertices[vertexIndex].Y; tempPosition.positionZ = (float)meshToBuildListFor.Vertices[vertexIndex].Z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); colorData.add(color); tempTexture.textureU = faceTexture == null ? 0 : (float)faceTexture.uv1.X; tempTexture.textureV = faceTexture == null ? 0 : (float)faceTexture.uv1.Y; vertexIndex = meshToBuildListFor.Faces[faceIndex].v1; tempPosition.positionX = (float)meshToBuildListFor.Vertices[vertexIndex].X; tempPosition.positionY = (float)meshToBuildListFor.Vertices[vertexIndex].Y; tempPosition.positionZ = (float)meshToBuildListFor.Vertices[vertexIndex].Z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); colorData.add(color); tempTexture.textureU = faceTexture == null ? 0 : (float)faceTexture.uv2.X; tempTexture.textureV = faceTexture == null ? 0 : (float)faceTexture.uv2.Y; vertexIndex = meshToBuildListFor.Faces[faceIndex].v2; tempPosition.positionX = (float)meshToBuildListFor.Vertices[vertexIndex].X; tempPosition.positionY = (float)meshToBuildListFor.Vertices[vertexIndex].Y; tempPosition.positionZ = (float)meshToBuildListFor.Vertices[vertexIndex].Z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); colorData.add(color); } }
static public void CreateCylinder(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, RGBA_Bytes color, double layerHeight) { Vector3 direction = endPos - startPos; Vector3 directionNormal = direction.GetNormal(); Vector3 startSweepDirection = Vector3.GetPerpendicular(startPos, endPos).GetNormal(); int[] tubeStartIndices = new int[steps]; int[] tubeEndIndices = new int[steps]; int[] capStartIndices = new int[steps]; int[] capEndIndices = new int[steps]; double halfHeight = layerHeight / 2 + (layerHeight * .1); double halfWidth = (radius * radius) / halfHeight; double zScale = halfHeight / radius; double xScale = halfWidth / radius; Vector3 scale = new Vector3(xScale, xScale, zScale); for (int i = 0; i < steps; i++) { // create tube ends verts Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); offset *= scale; Vector3 tubeStart = startPos + offset; tubeStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); Vector3 tubeEnd = endPos + offset; tubeEndIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeEnd, tubeNormal, color)); // create cap verts Vector3 rotateAngle = Vector3.Cross(direction, startSweepDirection); Vector3 capStartNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(rotateAngle, MathHelper.Tau / 8)); capStartNormal = Vector3.Transform(capStartNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capStartNormal = (capStartNormal * scale).GetNormal(); Vector3 capStartOffset = capStartNormal * radius; capStartOffset *= scale; Vector3 capStart = startPos + capStartOffset; capStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capStart, capStartNormal, color)); Vector3 capEndNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(-rotateAngle, MathHelper.Tau / 8)); capEndNormal = Vector3.Transform(capEndNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capEndNormal = (capEndNormal * scale).GetNormal(); Vector3 capEndOffset = capEndNormal * radius; capEndOffset *= scale; Vector3 capEnd = endPos + capEndOffset; capEndIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capEnd, capEndNormal, color)); } int tipStartIndex = colorVertexData.Count; Vector3 tipOffset = directionNormal * radius; tipOffset *= scale; colorVertexData.Add(new ColorVertexData(startPos - tipOffset, -directionNormal, color)); int tipEndIndex = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(endPos + tipOffset, directionNormal, color)); for (int i = 0; i < steps; i++) { // create tube polys indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create start cap polys indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create end cap polys indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[(i + 1) % steps]); // create start tip polys indexData.Add(tipStartIndex); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); // create end tip polys indexData.Add(tipEndIndex); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); } }
static public void CreateCylinder(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<uint> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, RGBA_Bytes color, double layerHeight) { Vector3 direction = endPos - startPos; Vector3 directionNormal = direction.GetNormal(); Vector3 startSweepDirection = Vector3.GetPerpendicular(startPos, endPos).GetNormal(); uint[] tubeStartIndices = new uint[steps]; uint[] tubeEndIndices = new uint[steps]; uint[] capStartIndices = new uint[steps]; uint[] capEndIndices = new uint[steps]; double halfHeight = layerHeight / 2 + (layerHeight * .1); double halfWidth = (radius * radius) / halfHeight; double zScale = halfHeight/radius; double xScale = halfWidth/radius; Vector3 scale = new Vector3(xScale, xScale, zScale); for (int i = 0; i < steps; i++) { // create tube ends verts Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); offset *= scale; Vector3 tubeStart = startPos + offset; tubeStartIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); Vector3 tubeEnd = endPos + offset; tubeEndIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeEnd, tubeNormal, color)); // create cap verts Vector3 rotateAngle = Vector3.Cross(direction, startSweepDirection); Vector3 capStartNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(rotateAngle, MathHelper.Tau / 8)); capStartNormal = Vector3.Transform(capStartNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capStartNormal = (capStartNormal * scale).GetNormal(); Vector3 capStartOffset = capStartNormal * radius; capStartOffset *= scale; Vector3 capStart = startPos + capStartOffset; capStartIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capStart, capStartNormal, color)); Vector3 capEndNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(-rotateAngle, MathHelper.Tau / 8)); capEndNormal = Vector3.Transform(capEndNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capEndNormal = (capEndNormal * scale).GetNormal(); Vector3 capEndOffset = capEndNormal * radius; capEndOffset *= scale; Vector3 capEnd = endPos + capEndOffset; capEndIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capEnd, capEndNormal, color)); } uint tipStartIndex = (uint)colorVertexData.Count; Vector3 tipOffset = directionNormal * radius; tipOffset *= scale; colorVertexData.Add(new ColorVertexData(startPos - tipOffset, -directionNormal, color)); uint tipEndIndex = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(endPos + tipOffset, directionNormal, color)); for (int i = 0; i < steps; i++) { // create tube polys indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create start cap polys indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create end cap polys indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[(i + 1) % steps]); // create start tip polys indexData.Add(tipStartIndex); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); // create end tip polys indexData.Add(tipEndIndex); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); } }
private void CreateRenderData(Mesh meshToBuildListFor) { subMeshs = new List<SubTriangleMesh>(); SubTriangleMesh currentSubMesh = null; VectorPOD<VertexTextureData> textureData = new VectorPOD<VertexTextureData>(); VectorPOD<VertexNormalData> normalData = new VectorPOD<VertexNormalData>(); VectorPOD<VertexPositionData> positionData = new VectorPOD<VertexPositionData>(); // first make sure all the textures are created foreach (Face face in meshToBuildListFor.Faces) { ImageBuffer faceTexture = face.GetTexture(0); if (faceTexture != null) { ImageGlPlugin.GetImageGlPlugin(faceTexture, true); } // don't compare the data of the texture but rather if they are just the same object if (subMeshs.Count == 0 || (object)subMeshs[subMeshs.Count - 1].texture != (object)faceTexture) { SubTriangleMesh newSubMesh = new SubTriangleMesh(); newSubMesh.texture = faceTexture; subMeshs.Add(newSubMesh); currentSubMesh = subMeshs[subMeshs.Count - 1]; textureData = currentSubMesh.textrueData; normalData = currentSubMesh.normalData; positionData = currentSubMesh.positionData; } Vector2[] textureUV = new Vector2[2]; Vector3[] position = new Vector3[2]; int vertexIndex = 0; foreach (FaceEdge faceEdge in face.FaceEdges()) { if (vertexIndex < 2) { textureUV[vertexIndex] = faceEdge.GetUVs(0); position[vertexIndex] = faceEdge.firstVertex.Position; } else { VertexTextureData tempTexture; VertexNormalData tempNormal; VertexPositionData tempPosition; tempTexture.textureU = (float)textureUV[0].x; tempTexture.textureV = (float)textureUV[0].y; tempNormal.normalX = (float)face.normal.x; tempNormal.normalY = (float)face.normal.y; tempNormal.normalZ = (float)face.normal.z; tempPosition.positionX = (float)position[0].x; tempPosition.positionY = (float)position[0].y; tempPosition.positionZ = (float)position[0].z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); tempTexture.textureU = (float)textureUV[1].x; tempTexture.textureV = (float)textureUV[1].y; tempNormal.normalX = (float)face.normal.x; tempNormal.normalY = (float)face.normal.y; tempNormal.normalZ = (float)face.normal.z; tempPosition.positionX = (float)position[1].x; tempPosition.positionY = (float)position[1].y; tempPosition.positionZ = (float)position[1].z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); Vector2 textureUV2 = faceEdge.GetUVs(0); Vector3 position2 = faceEdge.firstVertex.Position; tempTexture.textureU = (float)textureUV2.x; tempTexture.textureV = (float)textureUV2.y; tempNormal.normalX = (float)face.normal.x; tempNormal.normalY = (float)face.normal.y; tempNormal.normalZ = (float)face.normal.z; tempPosition.positionX = (float)position2.x; tempPosition.positionY = (float)position2.y; tempPosition.positionZ = (float)position2.z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); textureUV[1] = faceEdge.GetUVs(0); position[1] = faceEdge.firstVertex.Position; } vertexIndex++; } } }
static public void CreateCylinder(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, Color color, double layerHeight) { var direction = endPos - startPos; var directionNormal = direction.GetNormal(); var startSweepDirection = Vector3.GetPerpendicular(startPos, endPos).GetNormal(); int[] tubeStartIndices = new int[steps]; int[] tubeEndIndices = new int[steps]; int[] capStartIndices = new int[steps]; int[] capEndIndices = new int[steps]; double halfHeight = layerHeight / 2 + (layerHeight * .1); double halfWidth = radius; double zScale = halfHeight / radius; double xScale = halfWidth / radius; // Adjust start/end positions to be centered on Z for the given layer height startPos.Z -= halfHeight; endPos.Z -= halfHeight; var scale = new Vector3(xScale, xScale, zScale); var rotateAngle = Vector3Ex.Cross(startSweepDirection, direction); var startCapStartNormal = Vector3Ex.Transform(startSweepDirection, Matrix4X4.CreateRotation(rotateAngle, MathHelper.Tau / 8)); var startCapEndNormal = Vector3Ex.Transform(startSweepDirection, Matrix4X4.CreateRotation(-rotateAngle, MathHelper.Tau / 8)); for (int i = 0; i < steps; i++) { var rotationMatrix = Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i); // create tube ends verts var tubeNormal = Vector3Ex.Transform(startSweepDirection, rotationMatrix); var offset = Vector3Ex.Transform(startSweepDirection * radius, rotationMatrix) * scale; var tubeStart = startPos + offset; tubeStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); var tubeEnd = endPos + offset; tubeEndIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeEnd, tubeNormal, color)); // create cap verts var capStartNormal = Vector3Ex.Transform(startCapStartNormal, rotationMatrix); capStartNormal = (capStartNormal * scale).GetNormal(); var capStartOffset = capStartNormal * radius * scale; var capStart = startPos + capStartOffset; capStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capStart, capStartNormal, color)); var capEndNormal = Vector3Ex.Transform(startCapEndNormal, rotationMatrix); capEndNormal = (capEndNormal * scale).GetNormal(); var capEndOffset = capEndNormal * radius * scale; var capEnd = endPos + capEndOffset; capEndIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capEnd, capEndNormal, color)); } int tipStartIndex = colorVertexData.Count; var tipOffset = directionNormal * radius; tipOffset *= scale; colorVertexData.Add(new ColorVertexData(startPos - tipOffset, -directionNormal, color)); int tipEndIndex = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(endPos + tipOffset, directionNormal, color)); for (int i = 0; i < steps; i++) { // create tube polys indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create start cap polys indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create end cap polys indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[(i + 1) % steps]); // create start tip polys indexData.Add(tipStartIndex); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); // create end tip polys indexData.Add(tipEndIndex); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); } }
private void CreateRenderData(Mesh meshToBuildListFor) { subMeshs = new List <SubTriangleMesh>(); SubTriangleMesh currentSubMesh = null; VectorPOD <VertexTextureData> textureData = new VectorPOD <VertexTextureData>(); VectorPOD <VertexNormalData> normalData = new VectorPOD <VertexNormalData>(); VectorPOD <VertexPositionData> positionData = new VectorPOD <VertexPositionData>(); // first make sure all the textures are created foreach (Face face in meshToBuildListFor.Faces) { ImageBuffer faceTexture = face.GetTexture(0); if (faceTexture != null) { ImageGlPlugin.GetImageGlPlugin(faceTexture, true); } // don't compare the data of the texture but rather if they are just the same object if (subMeshs.Count == 0 || (object)subMeshs[subMeshs.Count - 1].texture != (object)faceTexture) { SubTriangleMesh newSubMesh = new SubTriangleMesh(); newSubMesh.texture = faceTexture; subMeshs.Add(newSubMesh); currentSubMesh = subMeshs[subMeshs.Count - 1]; textureData = currentSubMesh.textrueData; normalData = currentSubMesh.normalData; positionData = currentSubMesh.positionData; } Vector2[] textureUV = new Vector2[2]; Vector3[] position = new Vector3[2]; int vertexIndex = 0; foreach (FaceEdge faceEdge in face.FaceEdges()) { if (vertexIndex < 2) { textureUV[vertexIndex] = faceEdge.GetUVs(0); position[vertexIndex] = faceEdge.firstVertex.Position; } else { VertexTextureData tempTexture; VertexNormalData tempNormal; VertexPositionData tempPosition; tempTexture.textureU = (float)textureUV[0].x; tempTexture.textureV = (float)textureUV[0].y; tempNormal.normalX = (float)face.normal.x; tempNormal.normalY = (float)face.normal.y; tempNormal.normalZ = (float)face.normal.z; tempPosition.positionX = (float)position[0].x; tempPosition.positionY = (float)position[0].y; tempPosition.positionZ = (float)position[0].z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); tempTexture.textureU = (float)textureUV[1].x; tempTexture.textureV = (float)textureUV[1].y; tempNormal.normalX = (float)face.normal.x; tempNormal.normalY = (float)face.normal.y; tempNormal.normalZ = (float)face.normal.z; tempPosition.positionX = (float)position[1].x; tempPosition.positionY = (float)position[1].y; tempPosition.positionZ = (float)position[1].z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); Vector2 textureUV2 = faceEdge.GetUVs(0); Vector3 position2 = faceEdge.firstVertex.Position; tempTexture.textureU = (float)textureUV2.x; tempTexture.textureV = (float)textureUV2.y; tempNormal.normalX = (float)face.normal.x; tempNormal.normalY = (float)face.normal.y; tempNormal.normalZ = (float)face.normal.z; tempPosition.positionX = (float)position2.x; tempPosition.positionY = (float)position2.y; tempPosition.positionZ = (float)position2.z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); textureUV[1] = faceEdge.GetUVs(0); position[1] = faceEdge.firstVertex.Position; } vertexIndex++; } } }
private void CreateRenderData(Mesh meshToBuildListFor) { subMeshs = new List<SubTriangleMesh>(); SubTriangleMesh currentSubMesh = null; VectorPOD<TriangleVertexData> vertexDatas = new VectorPOD<TriangleVertexData>(); // first make sure all the textures are created foreach (Face face in meshToBuildListFor.Faces) { ImageBuffer faceTexture = face.GetTexture(0); if (faceTexture != null) { ImageGlPlugin.GetImageGlPlugin(faceTexture, true); } // don't compare the data of the texture but rather if they are just the same object if (subMeshs.Count == 0 || (object)subMeshs[subMeshs.Count - 1].texture != (object)faceTexture) { SubTriangleMesh newSubMesh = new SubTriangleMesh(); newSubMesh.texture = faceTexture; subMeshs.Add(newSubMesh); #if USE_VBO if (currentSubMesh != null) { CreateVBOForSubMesh(vertexDatas, currentSubMesh); vertexDatas.Clear(); } currentSubMesh = subMeshs[subMeshs.Count - 1]; #else currentSubMesh = subMeshs[subMeshs.Count - 1]; vertexDatas = currentSubMesh.vertexDatas; #endif } Vector2[] textureUV = new Vector2[2]; Vector3[] position = new Vector3[2]; int vertexIndex = 0; foreach (FaceEdge faceEdge in face.FaceEdges()) { if (vertexIndex < 2) { textureUV[vertexIndex] = faceEdge.GetUVs(0); position[vertexIndex] = faceEdge.firstVertex.Position; } else { TriangleVertexData tempVertex; tempVertex.textureU = (float)textureUV[0].x; tempVertex.textureV = (float)textureUV[0].y; tempVertex.positionsX = (float)position[0].x; tempVertex.positionsY = (float)position[0].y; tempVertex.positionsZ = (float)position[0].z; tempVertex.normalsX = (float)face.normal.x; tempVertex.normalsY = (float)face.normal.y; tempVertex.normalsZ = (float)face.normal.z; vertexDatas.Add(tempVertex); tempVertex.textureU = (float)textureUV[1].x; tempVertex.textureV = (float)textureUV[1].y; tempVertex.positionsX = (float)position[1].x; tempVertex.positionsY = (float)position[1].y; tempVertex.positionsZ = (float)position[1].z; tempVertex.normalsX = (float)face.normal.x; tempVertex.normalsY = (float)face.normal.y; tempVertex.normalsZ = (float)face.normal.z; vertexDatas.Add(tempVertex); Vector2 textureUV2 = faceEdge.GetUVs(0); Vector3 position2 = faceEdge.firstVertex.Position; tempVertex.textureU = (float)textureUV2.x; tempVertex.textureV = (float)textureUV2.y; tempVertex.positionsX = (float)position2.x; tempVertex.positionsY = (float)position2.y; tempVertex.positionsZ = (float)position2.z; tempVertex.normalsX = (float)face.normal.x; tempVertex.normalsY = (float)face.normal.y; tempVertex.normalsZ = (float)face.normal.z; vertexDatas.Add(tempVertex); textureUV[1] = faceEdge.GetUVs(0); position[1] = faceEdge.firstVertex.Position; } vertexIndex++; } } CreateVBOForSubMesh(vertexDatas, currentSubMesh); }
// Returns the number of styles public uint SweepStyles() { for (; ;) { if (m_scan_y > m_Rasterizer.MaxY) { return(0); } int num_cells = (int)m_Rasterizer.ScanlineNumCells((uint)m_scan_y); CellAA[] cells; uint cellOffset = 0; int curCellOffset; m_Rasterizer.ScanlineCells((uint)m_scan_y, out cells, out cellOffset); uint num_styles = (uint)(m_max_style - m_min_style + 2); uint style_id; int styleOffset = 0; m_cells.Allocate((uint)num_cells * 2, 256); // Each cell can have two styles m_ast.Capacity(num_styles, 64); m_asm.Allocate((num_styles + 7) >> 3, 8); m_asm.Zero(); if (num_cells > 0) { // Pre-add zero (for no-fill style, that is, -1). // We need that to ensure that the "-1 style" would go first. m_asm.Array[0] |= 1; m_ast.Add(0); m_styles.Array[styleOffset].start_cell = 0; m_styles.Array[styleOffset].num_cells = 0; m_styles.Array[styleOffset].last_x = -0x7FFFFFFF; m_sl_start = cells[0].X; m_sl_len = (uint)(cells[num_cells - 1].X - m_sl_start + 1); while (num_cells-- != 0) { curCellOffset = (int)cellOffset++; AddStyle(cells[curCellOffset].Left); AddStyle(cells[curCellOffset].Right); } // Convert the Y-histogram into the array of starting indexes uint i; uint start_cell = 0; StyleInfo[] stylesArray = m_styles.Array; for (i = 0; i < m_ast.Size(); i++) { int IndexToModify = (int)m_ast[i]; uint v = stylesArray[IndexToModify].start_cell; stylesArray[IndexToModify].start_cell = start_cell; start_cell += v; } num_cells = (int)m_Rasterizer.ScanlineNumCells((uint)m_scan_y); m_Rasterizer.ScanlineCells((uint)m_scan_y, out cells, out cellOffset); while (num_cells-- > 0) { curCellOffset = (int)cellOffset++; style_id = (uint)((cells[curCellOffset].Left < 0) ? 0 : cells[curCellOffset].Left - m_min_style + 1); styleOffset = (int)style_id; if (cells[curCellOffset].X == stylesArray[styleOffset].last_x) { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells - 1; unchecked { cells[cellOffset].Area += cells[curCellOffset].Area; cells[cellOffset].Cover += cells[curCellOffset].Cover; } } else { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells; cells[cellOffset].X = cells[curCellOffset].X; cells[cellOffset].Area = cells[curCellOffset].Area; cells[cellOffset].Cover = cells[curCellOffset].Cover; stylesArray[styleOffset].last_x = cells[curCellOffset].X; stylesArray[styleOffset].num_cells++; } style_id = (uint)((cells[curCellOffset].Right < 0) ? 0 : cells[curCellOffset].Right - m_min_style + 1); styleOffset = (int)style_id; if (cells[curCellOffset].X == stylesArray[styleOffset].last_x) { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells - 1; unchecked { cells[cellOffset].Area -= cells[curCellOffset].Area; cells[cellOffset].Cover -= cells[curCellOffset].Cover; } } else { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells; cells[cellOffset].X = cells[curCellOffset].X; cells[cellOffset].Area = -cells[curCellOffset].Area; cells[cellOffset].Cover = -cells[curCellOffset].Cover; stylesArray[styleOffset].last_x = cells[curCellOffset].X; stylesArray[styleOffset].num_cells++; } } } if (m_ast.Size() > 1) { break; } ++m_scan_y; } ++m_scan_y; if (m_layer_order != LayerOrder.Unsorted) { VectorPODRangeAdaptor ra = new VectorPODRangeAdaptor(m_ast, 1, m_ast.Size() - 1); if (m_layer_order == LayerOrder.Direct) { QuickSortRangeAdaptorUint m_QSorter = new QuickSortRangeAdaptorUint(); m_QSorter.Sort(ra); //quick_sort(ra, uint_greater); } else { throw new System.NotImplementedException(); //QuickSort_range_adaptor_uint m_QSorter = new QuickSort_range_adaptor_uint(); //m_QSorter.Sort(ra); //quick_sort(ra, uint_less); } } return(m_ast.Size() - 1); }
private void CreateRenderData(Mesh meshToBuildListFor, Func <Vector3, Color> getColorFunc) { subMeshs = new List <SubTriangleMesh>(); SubTriangleMesh currentSubMesh = null; VectorPOD <VertexTextureData> textureData = null; VectorPOD <VertexColorData> colorData = null; VectorPOD <VertexNormalData> normalData = null; VectorPOD <VertexPositionData> positionData = null; // first make sure all the textures are created foreach (Face face in meshToBuildListFor.Faces) { ImageBuffer faceTexture = face.GetTexture(0); if (faceTexture != null) { ImageGlPlugin.GetImageGlPlugin(faceTexture, true); } // don't compare the data of the texture but rather if they are just the same object if (subMeshs.Count == 0 || (object)subMeshs[subMeshs.Count - 1].texture != (object)faceTexture) { SubTriangleMesh newSubMesh = new SubTriangleMesh(); newSubMesh.texture = faceTexture; subMeshs.Add(newSubMesh); if (getColorFunc != null) { newSubMesh.UseVertexColors = true; } currentSubMesh = subMeshs[subMeshs.Count - 1]; textureData = currentSubMesh.textureData; colorData = currentSubMesh.colorData; normalData = currentSubMesh.normalData; positionData = currentSubMesh.positionData; } Vector2[] textureUV = new Vector2[2]; Vector3[] position = new Vector3[2]; VertexColorData color = new VertexColorData(); if (getColorFunc != null) { var faceColor = getColorFunc(face.Normal); color = new VertexColorData { red = faceColor.red, green = faceColor.green, blue = faceColor.blue }; } int vertexIndex = 0; foreach (FaceEdge faceEdge in face.FaceEdges()) { if (vertexIndex < 2) { textureUV[vertexIndex] = faceEdge.GetUv(0); position[vertexIndex] = faceEdge.FirstVertex.Position; } else { VertexTextureData tempTexture; VertexNormalData tempNormal; VertexPositionData tempPosition; tempTexture.textureU = (float)textureUV[0].X; tempTexture.textureV = (float)textureUV[0].Y; tempNormal.normalX = (float)face.Normal.X; tempNormal.normalY = (float)face.Normal.Y; tempNormal.normalZ = (float)face.Normal.Z; tempPosition.positionX = (float)position[0].X; tempPosition.positionY = (float)position[0].Y; tempPosition.positionZ = (float)position[0].Z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); colorData.add(color); tempTexture.textureU = (float)textureUV[1].X; tempTexture.textureV = (float)textureUV[1].Y; tempNormal.normalX = (float)face.Normal.X; tempNormal.normalY = (float)face.Normal.Y; tempNormal.normalZ = (float)face.Normal.Z; tempPosition.positionX = (float)position[1].X; tempPosition.positionY = (float)position[1].Y; tempPosition.positionZ = (float)position[1].Z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); colorData.add(color); Vector2 textureUV2 = faceEdge.GetUv(0); Vector3 position2 = faceEdge.FirstVertex.Position; tempTexture.textureU = (float)textureUV2.X; tempTexture.textureV = (float)textureUV2.Y; tempNormal.normalX = (float)face.Normal.X; tempNormal.normalY = (float)face.Normal.Y; tempNormal.normalZ = (float)face.Normal.Z; tempPosition.positionX = (float)position2.X; tempPosition.positionY = (float)position2.Y; tempPosition.positionZ = (float)position2.Z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); colorData.add(color); textureUV[1] = faceEdge.GetUv(0); position[1] = faceEdge.FirstVertex.Position; } vertexIndex++; } } }
static public void CreatePointer(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<uint> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, RGBA_Bytes color) { Vector3 direction = endPos - startPos; Vector3 directionNormal = direction.GetNormal(); Vector3 startSweepDirection = Vector3.GetPerpendicular(startPos, endPos).GetNormal(); uint[] tubeStartIndices = new uint[steps]; for (int i = 0; i < steps; i++) { // create tube ends verts Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 tubeStart = startPos + offset; tubeStartIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); Vector3 tubeEnd = endPos + offset; } uint tipEndIndex = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(endPos, directionNormal, color)); for (int i = 0; i < steps; i++) { // create tube polys indexData.Add(tubeStartIndices[i]); indexData.Add(tubeStartIndices[(i + 1) % steps]); indexData.Add(tipEndIndex); } }
private void CreateRenderData(Mesh meshToBuildListFor, double nonPlanarAngleRequired = 0) { edgeLinesData = new VectorPOD<WireVertexData>(); // first make sure all the textures are created foreach (MeshEdge meshEdge in meshToBuildListFor.MeshEdges) { if (nonPlanarAngleRequired > 0) { if (meshEdge.GetNumFacesSharingEdge() == 2) { FaceEdge firstFaceEdge = meshEdge.firstFaceEdge; FaceEdge nextFaceEdge = meshEdge.firstFaceEdge.radialNextFaceEdge; double angle = Vector3.CalculateAngle(firstFaceEdge.containingFace.normal, nextFaceEdge.containingFace.normal); if (angle > MathHelper.Tau * .1) { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } else { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } else { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } }