// * // * Builds a shape from control points // //----------------------------------------------------------------------- //Shape KochanekBartelsSpline2::realizeShape() public Shape realizeShape() { Shape shape = new Shape(); int numPoints = mClosed ? mPoints.size() : (mPoints.size() - 1); for (uint i = 0; i < numPoints; ++i) { ControlPoint2 P1 = safeGetPoint(i - 1); ControlPoint2 P2 = safeGetPoint(i); ControlPoint2 P3 = safeGetPoint(i + 1); ControlPoint2 P4 = safeGetPoint(i + 2); std_vector <Vector2> shape_getPointsReference = shape.getPointsReference(); GlobalMembers.computeKochanekBartelsPoints(P1, P2, P3, P4, mNumSeg, ref shape_getPointsReference); if (i == mPoints.size() - 2 && !mClosed) { shape.addPoint(P3.position); } } if (mClosed) { shape.close(); } shape.setOutSide(mOutSide); return(shape); }
// * // * Build a shape from bezier control points // //----------------------------------------------------------------------- public Shape realizeShape() { Shape shape = new Shape(); int numPoints = mClosed ? mPoints.Count : (mPoints.Count - 1); for (uint i = 0; i < numPoints; ++i) { Vector2 P1 = safeGetPoint(i - 1); Vector2 P2 = safeGetPoint(i); Vector2 P3 = safeGetPoint(i + 1); Vector2 P4 = safeGetPoint(i + 2); std_vector <Vector2> shape_getPointsReference = shape.getPointsReference(); GlobalMembers.computeCatmullRomPoints(P1, P2, P3, P4, mNumSeg, ref shape_getPointsReference); if (i == mPoints.Count - 2 && !mClosed) { shape.addPoint(P3); } } if (mClosed) { shape.close(); } shape.setOutSide(mOutSide); return(shape); }
// * // * Builds a shape from control points // //----------------------------------------------------------------------- //Shape CubicHermiteSpline2::realizeShape() public Shape realizeShape() { Shape shape = new Shape(); int numPoints = mClosed ? mPoints.size() : (mPoints.size() - 1); //Precompute tangents for (int i = 0; i < mPoints.size(); ++i) { CubicHermiteSplineControlPoint <Vector2> mp = mPoints[i]; GlobalMembers.computeTangents(ref mp, safeGetPoint((i - 1)).position, safeGetPoint(i + 1).position); } for (int i = 0; i < numPoints; ++i) { ControlPoint pointBefore = mPoints[i]; ControlPoint pointAfter = safeGetPoint(i + 1); std_vector <Vector2> shape_getPointsReference = shape.getPointsReference(); GlobalMembers.computeCubicHermitePoints(pointBefore, pointAfter, (uint)mNumSeg, ref shape_getPointsReference); if (i == mPoints.size() - 2 && !mClosed) { shape.addPoint(pointAfter.position); } } if (mClosed) { shape.close(); } shape.setOutSide(mOutSide); return(shape); }
// * // * Builds a path from control points // //----------------------------------------------------------------------- public Path realizePath() { Path path = new Path(); //Precompute tangents for (uint i = 0; i < mPoints.size(); ++i) { ControlPoint mp = mPoints[(int)i]; GlobalMembers.computeTangents(ref mp, safeGetPoint(i - 1).position, safeGetPoint(i + 1).position); } int numPoints = mClosed ? mPoints.size() : (mPoints.size() - 1); for (int i = 0; i < numPoints; ++i) { ControlPoint pointBefore = mPoints[i]; ControlPoint pointAfter = safeGetPoint((uint)i + 1); std_vector <Vector3> path_getPointsReference = path.getPointsReference(); GlobalMembers.computeCubicHermitePoints(pointBefore, pointAfter, mNumSeg, ref path_getPointsReference); if (i == mPoints.size() - 2 && !mClosed) { path.addPoint(pointAfter.position); } } if (mClosed) { path.close(); } return(path); }
// * // * Build a path from Catmull-Rom control points // //----------------------------------------------------------------------- public Path realizePath() { Path path = new Path(); int numPoints = mClosed ? mPoints.Count : mPoints.Count - 1; for (uint i = 0; i < numPoints; ++i) { Vector3 P1 = safeGetPoint(i - 1); Vector3 P2 = safeGetPoint(i); Vector3 P3 = safeGetPoint(i + 1); Vector3 P4 = safeGetPoint(i + 2); std_vector <Vector3> lref = path.getPointsReference(); GlobalMembers.computeCatmullRomPoints(P1, P2, P3, P4, mNumSeg, ref lref); if (i == mPoints.size() - 2 && !mClosed) { path.addPoint(P3); } } if (mClosed) { path.close(); } return(path); }
// * // * Builds the mesh into the given TriangleBuffer // * @param buffer The TriangleBuffer on where to append the mesh. // * @exception Ogre::InvalidStateException Either shape or multishape must be defined! // * @exception Ogre::InvalidStateException Required parameter is zero! // //----------------------------------------------------------------------- // //ORIGINAL LINE: void addToTriangleBuffer(TriangleBuffer& buffer) const public override void addToTriangleBuffer(ref TriangleBuffer buffer) { if (mMultiShapeToExtrude.getShapeCount() == 0) { OGRE_EXCEPT("Ogre::Exception::ERR_INVALID_STATE", "At least one shape must be defined!", "Procedural::Extruder::addToTriangleBuffer(Procedural::TriangleBuffer)"); } ; // Triangulate the begin and end caps if (mCapped && mMultiShapeToExtrude.isClosed()) { GlobalMembers._extrudeCapImpl(ref buffer, mMultiShapeToExtrude, mMultiExtrusionPath, mScaleTracks, mRotationTracks); } // Extrude the paths contained in multiExtrusionPath for (uint j = 0; j < mMultiExtrusionPath.getPathCount(); ++j) { Path extrusionPath = mMultiExtrusionPath.getPath((int)j); Track rotationTrack = null; if (mRotationTracks.find(j) != -1) // mRotationTracks.end()) { { rotationTrack = mRotationTracks[j]; //mRotationTracks.find(j).second; extrusionPath = extrusionPath.mergeKeysWithTrack(mRotationTracks[j]); // (*mRotationTracks.find(j).second); } Track scaleTrack = null; if (mScaleTracks.find(j) != -1) // mScaleTracks.end()) { { rotationTrack = mScaleTracks[j]; //mScaleTracks.find(j).second; extrusionPath = extrusionPath.mergeKeysWithTrack(mScaleTracks[j]); // (*mScaleTracks.find(j).second); } Track pathTextureTrack = null; if (mPathTextureTracks.find(j) != -1) // mPathTextureTracks.end()) { { pathTextureTrack = mPathTextureTracks[j]; //mPathTextureTracks.find(j).second; extrusionPath = extrusionPath.mergeKeysWithTrack(mPathTextureTracks[j]); //(*mPathTextureTracks.find(j).second); } std_vector <std_pair <uint, uint> > segs = mMultiExtrusionPath.getNoIntersectionParts(j); //for (List<std.pair<uint, uint>>.Enumerator it = segs.GetEnumerator(); it.MoveNext(); ++it) { foreach (var it in segs) { for (uint i = 0; i < mMultiShapeToExtrude.getShapeCount(); i++) { Shape shapeToExtrude = mMultiShapeToExtrude.getShape(i); Track shapeTextureTrack = null; if (mShapeTextureTracks.find(i) != -1) // mShapeTextureTracks.end()) { { shapeTextureTrack = mShapeTextureTracks[i]; //mShapeTextureTracks.find(i).second; shapeToExtrude.mergeKeysWithTrack(shapeTextureTrack); } GlobalMembers._extrudeBodyImpl(ref buffer, shapeToExtrude, extrusionPath, (int)it.first, (int)it.second, shapeTextureTrack, rotationTrack, scaleTrack, pathTextureTrack); } } // Make the intersections //typedef std::vector<PathCoordinate> PathIntersection; std_vector <std_vector <MultiPath.PathCoordinate> > intersections = mMultiExtrusionPath.getIntersections(); //for (List<MultiPath.PathIntersection>.Enumerator it = intersections.GetEnumerator(); it.MoveNext(); ++it) { foreach (var it in intersections) { for (uint i = 0; i < mMultiShapeToExtrude.getShapeCount(); i++) { Track shapeTextureTrack = null; if (mShapeTextureTracks.find(i) != -1) // mShapeTextureTracks.end()) { shapeTextureTrack = mShapeTextureTracks[i]; //mShapeTextureTracks.find(i).second; } GlobalMembers._extrudeIntersectionImpl(ref buffer, it, mMultiExtrusionPath, mMultiShapeToExtrude.getShape(i), shapeTextureTrack); } } } }
// //ORIGINAL LINE: bool findIntersect(const Triangle3D& STLAllocator<U, AllocPolicy>, Segment3D& intersection) const public bool findIntersect(Triangle3D triangle3d, ref Segment3D intersection) { // Compute plane equation of first triangle Vector3 e1 = mPoints[1] - mPoints[0]; Vector3 e2 = mPoints[2] - mPoints[0]; Vector3 n1 = e1.CrossProduct(e2); float d1 = -n1.DotProduct(mPoints[0]); // Put second triangle in first plane equation to compute distances to the plane float[] du = new float[3]; for (short i = 0; i < 3; i++) { du[i] = n1.DotProduct(triangle3d.mPoints[i]) + d1; if (Math.Abs(du[i]) < 1e-6) { du[i] = 0.0f; } } float du0du1 = du[0] * du[1]; float du0du2 = du[0] * du[2]; if (du0du1 > 0.0f && du0du2 > 0.0f) // same sign on all of them + not equal 0 ? { return(false); // no intersection occurs } // Compute plane equation of first triangle e1 = triangle3d.mPoints[1] - triangle3d.mPoints[0]; e2 = triangle3d.mPoints[2] - triangle3d.mPoints[0]; Vector3 n2 = e1.CrossProduct(e2); float d2 = -n2.DotProduct(triangle3d.mPoints[0]); // Put first triangle in second plane equation to compute distances to the plane float[] dv = new float[3]; for (short i = 0; i < 3; i++) { dv[i] = n2.DotProduct(mPoints[i]) + d2; if (Math.Abs(dv[i]) < 1e-6) { dv[i] = 0.0f; } } float dv0dv1 = dv[0] * dv[1]; float dv0dv2 = dv[0] * dv[2]; if (dv0dv1 > 0.0f && dv0dv2 > 0.0f) // same sign on all of them + not equal 0 ? { return(false); // no intersection occurs } //Compute the direction of intersection line Vector3 d = n1.CrossProduct(n2); // We don't do coplanar triangles if (d.SquaredLength < 1e-6) { return(false); } // Project triangle points onto the intersection line // compute and index to the largest component of D float max = Math.Abs(d[0]); int index = 0; float b = Math.Abs(d[1]); float c = Math.Abs(d[2]); if (b > max) { max = b; index = 1; } if (c > max) { max = c; index = 2; } // this is the simplified projection onto L float vp0 = mPoints[0][index]; float vp1 = mPoints[1][index]; float vp2 = mPoints[2][index]; float up0 = triangle3d.mPoints[0][index]; float up1 = triangle3d.mPoints[1][index]; float up2 = triangle3d.mPoints[2][index]; float[] isect1 = new float[2]; float[] isect2 = new float[2]; // compute interval for triangle 1 GlobalMembers.computeIntervals(vp0, vp1, vp2, dv[0], dv[1], dv[2], dv0dv1, dv0dv2, ref isect1[0], ref isect1[1]); // compute interval for triangle 2 GlobalMembers.computeIntervals(up0, up1, up2, du[0], du[1], du[2], du0du1, du0du2, ref isect2[0], ref isect2[1]); if (isect1[0] > isect1[1]) { std_array_swap <float>(isect1, 0, 1); } if (isect2[0] > isect2[1]) { std_array_swap <float>(isect2, 0, 1); } if (isect1[1] < isect2[0] || isect2[1] < isect1[0]) { return(false); } // Deproject segment onto line float r1 = System.Math.Max(isect1[0], isect2[0]); float r2 = System.Math.Min(isect1[1], isect2[1]); Plane pl1 = new Plane(n1.x, n1.y, n1.z, d1); Plane pl2 = new Plane(n2.x, n2.y, n2.z, d2); Line interLine = new Line(); pl1.intersect(pl2, ref interLine); Vector3 p = interLine.mPoint; //d.Normalise(); d = d.NormalisedCopy; Vector3 v1 = p + (r1 - p[index]) / d[index] * d; Vector3 v2 = p + (r2 - p[index]) / d[index] * d; intersection.mA = v1; intersection.mB = v2; return(true); }