public bool Solver( FeatureUpdateContext updateContext, [ParentModel] ICurve Curve, double Chord, int Solver) { //-- Initialize & Input Validation //-- Regenerate( ); if( Curve == null ) return false; //-- Select Search Method //-- Search search = MarchSearch; if( Solver == 1 ) search = BranchSearch; else if( Solver == 2 ) search = NewtonSearch; //-- Compute Chords //-- var curve = Curve.com_bsplineCurve; var point = curve.EvaluatePoint( 0.0 ); var param = 0.0; do { AddPoint( point ); } while( search( curve, Chord, ref param, ref point ) ); return true; }
public bool ClosestPointOnSurf ( FeatureUpdateContext updateContext, [DefaultExpression("baseCS")] CoordinateSystem cs, [Replicatable] IPoint point, [Replicatable] BSplineSurface surf, [DefaultValue(0.01)] double tol, [Out] ref Point CPpoint, [Out] ref double Dist, [Out] ref DVector3d Normal ) { this.LetConstituentFeaturesBeDirectlyIndexible(); this.DeleteConstituentFeatures(updateContext); Point2d tempPt; DPoint3d dp = CerverFunctions.closestPointOnSurf(point.DPoint3d, surf, tol, out Dist, out tempPt, out Normal); Point outPt = new Point(this); outPt.FromDPoint3d(updateContext, cs, dp); outPt.SetSuccess(true); AddConstituentFeature(outPt); CPpoint = outPt; return true; }
public bool MeshEdgeAsLines ( FeatureUpdateContext updateContext, [DefaultExpression("baseCS")] CoordinateSystem cs, [Replicatable] Mesh mesh, [Out] ref Line[] Edges, [Out] ref double[] Length, [Out] ref int[] StartPointVtx, [Out] ref int[] EndPointVtx ) { this.LetConstituentFeaturesBeDirectlyIndexible(); this.DeleteConstituentFeatures(updateContext); DSegment3d[] m_dlines = CerverFunctions.GetMeshEdges(mesh, out StartPointVtx, out EndPointVtx); double[] m_len = new double[m_dlines.Length]; Line[] m_Edges = new Line[m_dlines.Length]; for (int i=0; i< m_dlines.Length; i++) { string name = string.Format("{0}[{1}]", this.Name, i); m_Edges[i] = new Line(this); m_Edges[i].LetConstituentFeaturesBeDirectlyIndexible(); m_Edges[i].FromDSegment3d(updateContext,cs,m_dlines[i]); m_Edges[i].AlignOptions(this); m_Edges[i].SetSuccess(true); m_len[i] = m_Edges[i].Length; } this.AddReplicatedChildFeatures(m_Edges); Edges = m_Edges; Length = m_len; return true; }
public bool Build( FeatureUpdateContext updateContext, [ParentModel] Point[] Points, double Size) { //-- Upkeep //-- if( physics == null ) { physics = new Sutd.Physics( ); } else { Regenerate( ); physics.Reset( ); } //-- Set Gravity //-- physics.world.Gravity = new Vec3D( 0, 0, -10 ); //-- Create Ground //-- var body = new Sutd.Physics.Body( ); { //-- Define Infinite Plane //-- var shape = new StaticPlaneShape( new Vec3D( 0, 0, 1 ), 0 ); physics.shapes.Add( shape ); //-- Set Physics State / Bullet //-- Fixed bodies have zero mass and inertia //-- var param = new RigidBodyConstructionInfo( mass: 0.0f, motionState: new DefaultMotionState( Mat4D.Identity ), collisionShape: shape, localInertia: Vec3D.Zero ); body.rigid = new RigidBody( param ); param.Dispose( ); physics.world.AddRigidBody( body.rigid ); body.matrix = body.rigid.WorldTransform; //-- Set Visual State / Rhino //-- Create a very thin but wide finite box //-- var transform = DTransform3d.Identity; AddBox( transform, new DVector3d( 50, 50, 0.01 ) ); body.solid = geometry[geometry.Count - 1]; } physics.bodies.Add( body ); //-- Create 3D Grid of Boxes //-- float half = (float)( Size * 0.5 ); foreach( var point in Points ) { body = new Sutd.Physics.Body( ); { //-- Collision Shape //-- var shape = new BoxShape( half, half, half ); physics.shapes.Add( shape ); //-- Mass Properties //-- var inertia = Vec3D.Zero; shape.CalculateLocalInertia( mass: 1.0f, inertia: out inertia ); //-- Physics State //-- var param = new RigidBodyConstructionInfo( mass: 1.0f, motionState: new DefaultMotionState( Mat4D.Identity ), collisionShape: shape, localInertia: inertia ); body.rigid = new RigidBody( param ); param.Dispose( ); physics.world.AddRigidBody( body.rigid ); body.rigid.Translate( new Vec3D( (float)point.X, (float)point.Y, (float)point.Z ) ); body.matrix = body.rigid.WorldTransform; //-- Visual State //-- var transform = DTransform3d.Identity; transform.Translation = point.DPoint3d; AddBox( transform, new DVector3d( Size, Size, Size ) ); body.solid = geometry[geometry.Count - 1]; } physics.bodies.Add( body ); } return true; }
public bool Simulate( FeatureUpdateContext updateContext, DemoPhysicsWorld World, int Interval, int Update) { world = World; clock.Interval = Interval; clock.Enabled = Update != 0; return true; }
public bool MeshConnectedVerticies ( FeatureUpdateContext updateContext, [DefaultExpression("baseCS")] CoordinateSystem cs, Mesh mesh, [Replicatable] IPoint SearchPoint, [DefaultValue(false)] bool generatePoints, [Out] ref int[] ConnectedVtxID, [Out] ref Point[] ConnectedVtx, [Out] ref DPoint3d[] DConnectedVtx ) { this.LetConstituentFeaturesBeDirectlyIndexible(); this.DeleteConstituentFeatures(updateContext); //System.Diagnostics.Stopwatch stp = new Stopwatch(); // stp.Start(); DPoint3d[] cntVtx = mesh.ConnectedVtx(SearchPoint.DPoint3d, out ConnectedVtxID); DConnectedVtx = cntVtx; // Feature.Print("area 1 " + stp.ElapsedMilliseconds.ToString()); // stp.Reset(); if (generatePoints) { List<Point> vtx = new List<Point>(cntVtx.Length); foreach (var v in cntVtx) { Point p = new Point(this); p.FromDPoint3d(updateContext, cs, v); p.SetSuccess(true); vtx.Add(p); } this.AddReplicatedChildFeatures(ConnectedVtx); ConnectedVtx = vtx.ToArray(); } // Feature.Print("area 2 " + stp.ElapsedMilliseconds.ToString()); // stp.Stop(); return true; }