public RenderVertex3D[] GetCentralCurve(Table.Table table, float acc = -1.0f) { float accuracy; // as solid ramps are rendered into the static buffer, always use maximum precision if (acc != -1.0) { accuracy = acc; // used for hit shape calculation, always! } else { var mat = table.GetMaterial(_data.Material); if (mat == null || !mat.IsOpacityActive) { accuracy = 10.0f; } else { accuracy = table.GetDetailLevel(); } } // min = 4 (highest accuracy/detail level), max = 4 * 10^(10/1.5) = ~18.000.000 (lowest accuracy/detail level) accuracy = 4.0f * MathF.Pow(10.0f, (10.0f - accuracy) * (1.0f / 1.5f)); return(DragPoint.GetRgVertex <RenderVertex3D, CatmullCurve3DCatmullCurveFactory>(_data.DragPoints, false, accuracy)); }
public Mesh GetMesh(Table.Table table, RubberData rubberData) { var mesh = GetTransformedMesh(table.TableHeight, _data.Height, table.GetDetailLevel()); mesh.Name = rubberData.Name; var preMatrix = new Matrix3D(); preMatrix.SetTranslation(0, 0, -_data.Height); return(mesh.Transform(preMatrix)); }
public Mesh GetMesh(Table.Table table, MetalWireGuideData metalWireGuideData) { var mesh = GetTransformedMesh(table.TableHeight, _data.Height, table.GetDetailLevel(), _data.Bendradius); mesh.Name = metalWireGuideData.Name; var preMatrix = new Matrix3D(); preMatrix.SetTranslation(0, 0, -_data.Height); return(mesh.Transform(preMatrix)); }
internal Mesh GetMesh(Table.Table table, int acc = -1, bool createHitShape = false) { var mesh = new Mesh(_data.Name); const int accuracy = (int)(10.0f * 1.2f); // see also above var splineAccuracy = acc != -1 ? 4.0f * MathF.Pow(10.0f, (10.0f - PhysicsConstants.HitShapeDetailLevel) * (float)(1.0 / 1.5)) : -1.0f; var sv = new SplineVertex(_data.DragPoints, _data.Thickness, table.GetDetailLevel(), (int)splineAccuracy); var numRings = sv.VertexCount - 1; var numSegments = accuracy; var numVertices = numRings * numSegments; var numIndices = 6 * numVertices; //m_numVertices*2+2; var height = _data.HitHeight + table.TableHeight; mesh.Vertices = new Vertex3DNoTex2[numVertices]; mesh.Indices = new int[numIndices]; var prevB = new Vertex3D(); var invNr = 1.0f / numRings; var invNs = 1.0f / numSegments; var index = 0; for (var i = 0; i < numRings; i++) { var i2 = i == numRings - 1 ? 0 : i + 1; var tangent = new Vertex3D(sv.MiddlePoints[i2].X - sv.MiddlePoints[i].X, sv.MiddlePoints[i2].Y - sv.MiddlePoints[i].Y, 0.0f); Vertex3D biNormal; Vertex3D normal; if (i == 0) { var up = new Vertex3D(sv.MiddlePoints[i2].X + sv.MiddlePoints[i].X, sv.MiddlePoints[i2].Y + sv.MiddlePoints[i].Y, height * 2.0f); normal = new Vertex3D(tangent.Y * up.Z, -tangent.X * up.Z, tangent.X * up.Y - tangent.Y * up.X); // = CrossProduct(tangent, up) biNormal = new Vertex3D(tangent.Y * normal.Z, -tangent.X * normal.Z, tangent.X * normal.Y - tangent.Y * normal.X); // = CrossProduct(tangent, normal) } else { normal = prevB.Clone().Cross(tangent); biNormal = tangent.Clone().Cross(normal); } biNormal.Normalize(); normal.Normalize(); prevB = biNormal; var u = i * invNr; for (var j = 0; j < numSegments; j++) { var v = ((float)j + u) * invNs; var tmp = Vertex3D.GetRotatedAxis(j * (360.0f * invNs), tangent, normal) .MultiplyScalar(_data.Thickness * 0.5f); mesh.Vertices[index] = new Vertex3DNoTex2 { X = sv.MiddlePoints[i].X + tmp.X, Y = sv.MiddlePoints[i].Y + tmp.Y }; if (createHitShape && (j == 0 || j == 3)) { //!! hack, adapt if changing detail level for hitshape // for a hit shape create a more rectangle mesh and not a smooth one tmp.Z *= 0.6f; } mesh.Vertices[index].Z = height + tmp.Z; //texel mesh.Vertices[index].Tu = u; mesh.Vertices[index].Tv = v; index++; } } // calculate faces for (var i = 0; i < numRings; i++) { for (var j = 0; j < numSegments; j++) { var quad = new int[4]; quad[0] = i * numSegments + j; if (j != numSegments - 1) { quad[1] = i * numSegments + j + 1; } else { quad[1] = i * numSegments; } if (i != numRings - 1) { quad[2] = (i + 1) * numSegments + j; if (j != numSegments - 1) { quad[3] = (i + 1) * numSegments + j + 1; } else { quad[3] = (i + 1) * numSegments; } } else { quad[2] = j; if (j != numSegments - 1) { quad[3] = j + 1; } else { quad[3] = 0; } } mesh.Indices[(i * numSegments + j) * 6] = quad[0]; mesh.Indices[(i * numSegments + j) * 6 + 1] = quad[1]; mesh.Indices[(i * numSegments + j) * 6 + 2] = quad[2]; mesh.Indices[(i * numSegments + j) * 6 + 3] = quad[3]; mesh.Indices[(i * numSegments + j) * 6 + 4] = quad[2]; mesh.Indices[(i * numSegments + j) * 6 + 5] = quad[1]; } } Mesh.ComputeNormals(mesh.Vertices, numVertices, mesh.Indices, numIndices); var maxX = Constants.FloatMin; var minX = Constants.FloatMax; var maxY = Constants.FloatMin; var minY = Constants.FloatMax; var maxZ = Constants.FloatMin; var minZ = Constants.FloatMax; for (var i = 0; i < numVertices; i++) { if (maxX < mesh.Vertices[i].X) { maxX = mesh.Vertices[i].X; } if (minX > mesh.Vertices[i].X) { minX = mesh.Vertices[i].X; } if (maxY < mesh.Vertices[i].Y) { maxY = mesh.Vertices[i].Y; } if (minY > mesh.Vertices[i].Y) { minY = mesh.Vertices[i].Y; } if (maxZ < mesh.Vertices[i].Z) { maxZ = mesh.Vertices[i].Z; } if (minZ > mesh.Vertices[i].Z) { minZ = mesh.Vertices[i].Z; } } MiddlePoint.X = (maxX + minX) * 0.5f; MiddlePoint.Y = (maxY + minY) * 0.5f; MiddlePoint.Z = (maxZ + minZ) * 0.5f; return(mesh); }
private Tuple <Mesh, Mesh> GenerateBaseWires(Table.Table table) { int accuracy; if (table.GetDetailLevel() < 5) { accuracy = 6; } else if (table.GetDetailLevel() >= 5 && table.GetDetailLevel() < 8) { accuracy = 8; } else { accuracy = (int)(table.GetDetailLevel() * 1.3f); // see below } // as solid ramps are rendered into the static buffer, always use maximum precision var mat = table.GetMaterial(_data.Material); if (mat == null || !mat.IsOpacityActive) { accuracy = 12; // see above } var rv = GetRampVertex(table, -1, false); var middlePoints = rv.MiddlePoints; var numRings = rv.VertexCount; var numSegments = accuracy; var numVertices = numRings * numSegments; var numIndices = 6 * numVertices; //m_numVertices*2+2; var tmpPoints = new Vertex2D[rv.VertexCount]; for (var i = 0; i < rv.VertexCount; i++) { tmpPoints[i] = rv.RgvLocal[rv.VertexCount * 2 - i - 1]; } Vertex3DNoTex2[] vertBuffer; Vertex3DNoTex2[] vertBuffer2; if (_data.RampType != RampType.RampType1Wire) { vertBuffer = CreateWire(numRings, numSegments, rv.RgvLocal, rv.PointHeights); vertBuffer2 = CreateWire(numRings, numSegments, tmpPoints, rv.PointHeights); } else { vertBuffer = CreateWire(numRings, numSegments, middlePoints, rv.PointHeights); vertBuffer2 = null; } // calculate faces var indices = new int[numIndices]; for (var i = 0; i < numRings - 1; i++) { for (var j = 0; j < numSegments; j++) { var quad = new int[4]; quad[0] = i * numSegments + j; if (j != numSegments - 1) { quad[1] = i * numSegments + j + 1; } else { quad[1] = i * numSegments; } if (i != numRings - 1) { quad[2] = (i + 1) * numSegments + j; if (j != numSegments - 1) { quad[3] = (i + 1) * numSegments + j + 1; } else { quad[3] = (i + 1) * numSegments; } } else { quad[2] = j; if (j != numSegments - 1) { quad[3] = j + 1; } else { quad[3] = 0; } } var offs = (i * numSegments + j) * 6; indices[offs] = quad[0]; indices[offs + 1] = quad[1]; indices[offs + 2] = quad[2]; indices[offs + 3] = quad[3]; indices[offs + 4] = quad[2]; indices[offs + 5] = quad[1]; } } if (_data.RampType != RampType.RampType1Wire) { return(new Tuple <Mesh, Mesh>( new Mesh(vertBuffer, indices), new Mesh(vertBuffer2, indices) )); } return(new Tuple <Mesh, Mesh>(new Mesh(vertBuffer, indices), null)); }