/// <inheritdoc /> public override bool CastTo <T>(ref T target) { if (typeof(T).IsAssignableFrom(typeof(HeMesh3d))) { object obj = Value; target = (T)obj; return(true); } if (typeof(T).IsAssignableFrom(typeof(Mesh))) { object obj = new GH_Mesh(base.Value.ToMesh()); target = (T)obj; return(true); } if (typeof(T).IsAssignableFrom(typeof(GH_Mesh))) { object obj = new GH_Mesh(Value.ToMesh()); target = (T)obj; return(true); } if (typeof(T).IsAssignableFrom(typeof(GH_ObjectWrapper))) { object obj = new GH_ObjectWrapper(Value); target = (T)obj; return(true); } return(false); }
/// <summary> /// This function is called when Grasshopper needs to convert this /// instance of TriStateType into some other type Q. /// </summary> /// <typeparam name="Q"></typeparam> /// <param name="target"></param> /// <returns></returns> public override bool CastTo <Q>(ref Q target) { //First, see if Q is similar to the Integer primitive. if (typeof(Q).IsAssignableFrom(typeof(string))) { target = (Q)(object)ToString(); return(true); } //First, see if Q is similar to the Integer primitive. if (typeof(Q).IsAssignableFrom(typeof(PixelGrid2D))) { object ptr = Value; target = (Q)ptr; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh))) { var m = Value.GenerateMesh(Color.Black, Color.White); var ghm = new GH_Mesh(m); target = (Q)(object)ghm; return(true); } //We could choose to also handle casts to Boolean, GH_Boolean, //Double and GH_Number, but this is left as an exercise for the reader. return(false); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { var mesh = new GH_Mesh(); var filePath = ""; var fileName = ""; var save = false; if ((!DA.GetData(0, ref mesh))) { return; } if ((!DA.GetData(1, ref filePath))) { return; } if (!DA.GetData(2, ref fileName)) { return; } DA.GetData(3, ref save); if (save) { meshPath = CreateMeshPath(filePath, fileName); Export.MeshToObjFile(new List <GH_Mesh> { mesh }, meshPath); } DA.SetData(0, meshPath); }
/// <summary> /// This function is called when Grasshopper needs to convert this /// instance of TriStateType into some other type Q. /// </summary> /// <typeparam name="Q"></typeparam> /// <param name="target"></param> /// <returns></returns> public override bool CastTo <Q>(ref Q target) { //First, see if Q is similar to the Integer primitive. if (typeof(Q).IsAssignableFrom(typeof(VoxelGrid3D))) { object ptr = Value; target = (Q)ptr; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh))) { var m = VoxelGridMeshHelper.VoxelGridToMesh(Value); // don't add fake meshes.. // VoxelGridMeshHelper.addFakeShadow(ref m, new Vector3d(-0.495633, 0.142501, 0.856762), 1.0, Color.White, Color.Black); var ghm = new GH_Mesh(m); target = (Q)(object)ghm; return(true); } //First, see if Q is similar to the Integer primitive. if (typeof(Q).IsAssignableFrom(typeof(string))) { target = (Q)(object)ToString(); return(true); } //We could choose to also handle casts to Boolean, GH_Boolean, //Double and GH_Number, but this is left as an exercise for the reader. return(false); }
public PxGhRigidStaticSphere(Plane plane, float radius, Material material) { actor = PhysXManager.Physics.CreateRigidStatic(); actor.CreateShape(new SphereGeometry(radius), material); actor.GlobalPose = plane.ToMatrix(); ghMesh = new GH_Mesh(Mesh.CreateFromSphere(new Sphere(plane, radius), 32, 16)); }
public static GH_Mesh ProjectMeshToTopoFast(Mesh topoMesh, Mesh featureMesh) { GH_Mesh ghMesh = new GH_Mesh(); Mesh mesh = featureMesh.DuplicateMesh(); ///Move patch verts to topo for (int i = 0; i < mesh.Vertices.Count; i++) { Ray3d ray = new Ray3d((Point3d)mesh.Vertices[i], moveDir); double t = Rhino.Geometry.Intersect.Intersection.MeshRay(topoMesh, ray); if (t >= 0.0) { mesh.Vertices.SetVertex(i, (Point3f)ray.PointAt(t)); } else { Ray3d rayOpp = new Ray3d((Point3d)mesh.Vertices[i], -moveDir); double tOpp = Rhino.Geometry.Intersect.Intersection.MeshRay(topoMesh, rayOpp); if (tOpp >= 0.0) { mesh.Vertices.SetVertex(i, (Point3f)rayOpp.PointAt(tOpp)); } else { //mesh.Vertices.SetVertex(i, new Point3f(0, 0, 0)); //return null; } } } GH_Convert.ToGHMesh(mesh, GH_Conversion.Primary, ref ghMesh); return(ghMesh); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Mesh mesh = null; int maxVertices = 0; if (!DA.GetData(0, ref mesh)) { return; } if (!DA.GetData(1, ref maxVertices)) { return; } mesh.CreatePartitions(maxVertices, maxVertices * 2); List <GH_Mesh> newMeshes = new List <GH_Mesh>(); for (int i = 0; i < mesh.PartitionCount; i++) { MeshPart meshPart = mesh.GetPartition(i); IEnumerable <MeshFace> meshFaces = mesh.Faces.Skip(meshPart.StartFaceIndex).Take(meshPart.EndFaceIndex - meshPart.StartFaceIndex); Mesh partMesh = new Mesh(); partMesh.Vertices.AddVertices(mesh.Vertices); partMesh.Faces.AddFaces(meshFaces); partMesh.Normals.ComputeNormals(); partMesh.Compact(); GH_Mesh ghmesh = new GH_Mesh(partMesh); newMeshes.Add(ghmesh); } DA.SetDataList(0, newMeshes); }
private bool MeshTolVecErrorCheck(GH_Mesh msh, GH_Number tol, GH_Vector vec) { bool flag = true; if (msh == null || tol == null || vec == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Null Input! Skipping branch."); return(false); } if (!msh.Value.IsValid || !(msh.Value.Vertices.Count > 2)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Invalid mesh! Skipping branch."); flag = false; } if (tol.Value < Rhino.RhinoMath.ZeroTolerance) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Tolerance too small! Skipping branch."); flag = false; } if (vec.Value.IsZero) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cannot flow with zero-length vector! Skipping branch."); flag = false; } return(flag); }
public override bool CastFrom(object source) { if (source == null) { return(false); } if (source is Mesh) { Value = (Mesh)source; return(true); } GH_Mesh meshGoo = source as GH_Mesh; if (meshGoo != null) { Value = meshGoo.Value; return(true); } Mesh m = new Mesh(); if (GH_Convert.ToMesh(source, ref m, GH_Conversion.Both)) { Value = m; return(true); } return(false); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { //local varaibles GH_Mesh mesh = null; List <GH_Colour> colors = new List <GH_Colour>(); List <GH_String> attributeNames = new List <GH_String>(); List <GH_String> attributeValues = new List <GH_String>(); Dictionary <string, object> attributesDict = new Dictionary <string, object>(); Layer layer = null; string layerName = "Default"; //catch inputs and populate local variables if (!DA.GetData(0, ref mesh)) { return; } if (mesh == null) { return; } if (!DA.GetDataList(1, colors)) { return; } DA.GetDataList(2, attributeNames); DA.GetDataList(3, attributeValues); if (attributeValues.Count != attributeNames.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please provide equal numbers of attribute names and values."); return; } DA.GetData(4, ref layerName); layer = new Layer(layerName); //populate dictionary int i = 0; foreach (var a in attributeNames) { attributesDict.Add(a.Value, attributeValues[i].Value); i++; } //add the layer name to the attributes dictionary attributesDict.Add("layer", layerName); //create MeshFaceMaterial and assign mesh face material indexes in the attributes dict string meshMaterailJSON = makeMeshFaceMaterialJSON(mesh.Value, attributesDict, colors); //create json from mesh string meshJSON = _Utilities.geoJSON(mesh.Value, attributesDict); Material material = new Material(meshMaterailJSON, va3cMaterialType.Mesh); Element e = new Element(meshJSON, va3cElementType.Mesh, material, layer); DA.SetData(0, e); }
///<summary> /// Verify validity of each input set with each error handled w/ separate message ///</summary> public bool FullErrorCheck(GH_Point pt, GH_Mesh msh, GH_Number tol, GH_Integer step, GH_Vector vec) { bool flag = true; flag = flag && MeshTolVecErrorCheck(msh, tol, vec); flag = flag && PointStepErrorCheck(pt, step); return(flag); }
public SuperMesh(GH_Mesh myMesh, string guid) { parentGuid = guid; data.uvs = ""; data.normals = ""; Mesh actualMesh = myMesh.Value; // COLOURS (if any) if (actualMesh.VertexColors.Count > 0) { data.vertexColors = new List<int>(); type = "SPKL_ColorMesh"; foreach (System.Drawing.Color c in actualMesh.VertexColors) { c.ToString(); data.vertexColors.Add(ColorToInt(c)); } } // VERTICES data.vertices = new List<double>(); foreach (Point3d vertex in actualMesh.Vertices) { data.vertices.Add(Math.Round(vertex.Y * 1, 3)); data.vertices.Add(Math.Round(vertex.Z * 1, 3)); data.vertices.Add(Math.Round(vertex.X * 1, 3)); } // FACES data.faces = new List<int>(); foreach (MeshFace face in actualMesh.Faces) { if (face.IsTriangle) { data.faces.Add(0); data.faces.Add(face.A); data.faces.Add(face.B); data.faces.Add(face.C); } else { // some reason quad meshes say nono to shadows in threejs :( data.faces.Add(0); data.faces.Add(face.A); data.faces.Add(face.B); data.faces.Add(face.C); data.faces.Add(0); data.faces.Add(face.A); data.faces.Add(face.C); data.faces.Add(face.D); } } }
public SuperMesh(GH_Mesh myMesh, string guid) { parentGuid = guid; data.uvs = ""; data.normals = ""; Mesh actualMesh = myMesh.Value; // COLOURS (if any) if (actualMesh.VertexColors.Count > 0) { data.vertexColors = new List <int>(); type = "SPKL_ColorMesh"; foreach (System.Drawing.Color c in actualMesh.VertexColors) { c.ToString(); data.vertexColors.Add(ColorToInt(c)); } } // VERTICES data.vertices = new List <double>(); foreach (Point3d vertex in actualMesh.Vertices) { data.vertices.Add(Math.Round(vertex.Y * 1, 3)); data.vertices.Add(Math.Round(vertex.Z * 1, 3)); data.vertices.Add(Math.Round(vertex.X * 1, 3)); } // FACES data.faces = new List <int>(); foreach (MeshFace face in actualMesh.Faces) { if (face.IsTriangle) { data.faces.Add(0); data.faces.Add(face.A); data.faces.Add(face.B); data.faces.Add(face.C); } else { // some reason quad meshes say nono to shadows in threejs :( data.faces.Add(0); data.faces.Add(face.A); data.faces.Add(face.B); data.faces.Add(face.C); data.faces.Add(0); data.faces.Add(face.A); data.faces.Add(face.C); data.faces.Add(face.D); } } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <IGH_GeometricGoo> geometry = new List <IGH_GeometricGoo>(); Curve curve = null; if (!DA.GetDataList(0, geometry) || !DA.GetData(1, ref curve)) { return; } ////////////////将于指定曲线线有关系的物件选出(Brep,Curve,Mesh)strict 选出完全重合,some 局部重合 ,all 相关联所有 List <IGH_GeometricGoo> collect = new List <IGH_GeometricGoo>(); List <int> indexes = new List <int>(); for (int i = 0; i < geometry.Count; i++) { IGH_GeometricGoo obj = geometry[i]; if (obj is GH_Curve) { GH_Curve ghcurve = (GH_Curve)obj; if (CurveAndCurve(ghcurve.Value, curve, strict, some, all)) { indexes.Add(i); collect.Add(obj); } } else if (obj is GH_Brep) { GH_Brep ghbrep = (GH_Brep)obj; if (CurveAndBrep(ghbrep.Value, curve, strict, some, all)) { indexes.Add(i); collect.Add(obj); } } else if (obj is GH_Surface) { GH_Surface ghsurface = (GH_Surface)obj; if (CurveAndBrep(ghsurface.Value, curve, strict, some, all)) { indexes.Add(i); collect.Add(obj); } } else if (obj is GH_Mesh) { GH_Mesh ghmesh = (GH_Mesh)obj; if (CurveAndMesh(ghmesh.Value, curve, strict, some, all)) { indexes.Add(i); collect.Add(obj); } } } DA.SetDataList(0, collect); DA.SetDataList(1, indexes); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Mesh ghmesh = new GH_Mesh(); if (DA.GetData(0, ref ghmesh)) { if (ghmesh == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh input is null"); } Mesh mesh = new Mesh(); if (GH_Convert.ToMesh(ghmesh, ref mesh, GH_Conversion.Both)) { GsaElement2d elem = new GsaElement2d(mesh); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { for (int i = 0; i < elem.Elements.Count; i++) { elem.Elements[i].Property = idd; } prop2d = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } else { prop2d = null; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem)); }
public override bool CastTo <Q>(ref Q target) { if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh))) { Mesh[] meshes = Value.GetMesh(); Mesh m = new Mesh(); for (int i = 0; i < meshes.Length; ++i) { m.Append(meshes[i]); } object mesh = new GH_Mesh(m); target = (Q)mesh; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GlulamWorkpiece))) { object blank = Value; target = (Q)blank; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Brep))) { Brep[] breps = Value.GetBrep(); Brep b = new Brep(); for (int i = 0; i < breps.Length; ++i) { b.Append(breps[i]); } object brep = new GH_Brep(b); target = (Q)brep; return(true); } //if (typeof(Q).IsAssignableFrom(typeof(GH_))) if (typeof(Q).IsAssignableFrom(typeof(GH_Curve))) { Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray(); //target = crvs.Select(x => new GH_Curve(x)).ToList() as Q; object crv = new GH_Curve(crvs.FirstOrDefault()); target = (Q)(crv); return(true); } if (typeof(Q).IsAssignableFrom(typeof(List <GH_Curve>))) { Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray(); //target = crvs.Select(x => new GH_Curve(x)).ToList() as Q; object crv = crvs.Select(x => new GH_Curve(x)).ToList(); target = (Q)(crv); return(true); } return(base.CastTo <Q>(ref target)); }
public PxGhRigidStaticBox(Plane plane, float length, float width, float height, Material material) { actor = PhysXManager.Physics.CreateRigidStatic(); actor.CreateShape(new BoxGeometry(length * 0.5f, width * 0.5f, height * 0.5f), material); actor.GlobalPose = plane.ToMatrix(); ghMesh = new GH_Mesh( Mesh.CreateFromBox( new Box( plane, new BoundingBox(-length * 0.5f, -width * 0.5f, -height * 0.5f, length * 0.5f, width * 0.5f, height * 0.5f)), 1, 1, 1)); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { this.Message = Constants.Constants.PARALLEL_MESSAGE; this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, Constants.Constants.PARALLEL_WARNING); int processorCount = Environment.ProcessorCount - 1; double docTollerance = DocumentTolerance(); GH_Structure <GH_Mesh> ghPatches = new GH_Structure <GH_Mesh>(); GH_Structure <GH_Curve> inGhCurves = new GH_Structure <GH_Curve>(); bool areCurvesOK = DA.GetDataTree(0, out inGhCurves); CheckGetDataConversion(areCurvesOK); ConcurrentDictionary <GH_Path, Mesh> patchesPA = new ConcurrentDictionary <GH_Path, Mesh>(); Parallel.ForEach(inGhCurves.Paths, new ParallelOptions { MaxDegreeOfParallelism = processorCount }, path => { Polyline firstPolyline = null; inGhCurves.get_DataItem(path, 0).Value.TryGetPolyline(out firstPolyline); if ((!firstPolyline.IsValid ? true : firstPolyline == null)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Impossible convert the first Curve in Polyline"); } List <Curve> otherBranchCurves = new List <Curve>(); for (int i = 0; i < inGhCurves.get_Branch(path).Count; i++) { otherBranchCurves.Add(inGhCurves.get_DataItem(path, i).Value.DuplicateCurve()); } patchesPA[path] = Mesh.CreatePatch(firstPolyline, docTollerance, null, otherBranchCurves, null, null, true, 1); }); foreach (KeyValuePair <GH_Path, Mesh> patch in patchesPA) { GH_Mesh ghPatchMesh = null; if (GH_Convert.ToGHMesh(patch.Value, GH_Conversion.Both, ref ghPatchMesh)) { ghPatches.Append(ghPatchMesh, patch.Key); } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Conversion Failed"); return; } } DA.SetDataTree(0, ghPatches); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Program program = null; var first = new List <GH_Integer>(); var second = new List <GH_Integer>(); GH_Mesh environment = null; int environmentPlane = -1; double linearStep = 100; double angularStep = PI / 4; if (!DA.GetData(0, ref program)) { return; } if (!DA.GetDataList(1, first)) { return; } if (!DA.GetDataList(2, second)) { return; } DA.GetData(3, ref environment); if (!DA.GetData(4, ref environmentPlane)) { return; } if (!DA.GetData(5, ref linearStep)) { return; } if (!DA.GetData(6, ref angularStep)) { return; } var collision = program.Value.CheckCollisions(first.Select(x => x.Value), second.Select(x => x.Value), environment?.Value, environmentPlane, linearStep, angularStep); DA.SetData(0, collision.HasCollision); if (collision.HasCollision) { DA.SetData(1, collision.CollisionTarget.Index); } if (collision.HasCollision) { DA.SetDataList(2, collision.Meshes); } }
public override bool CastTo <Q>(ref Q target) { if (Value == null) { return(false); } if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh))) { object mesh = new GH_Mesh(Value.Mesh); target = (Q)mesh; return(true); } return(false); }
public override List <SpeckleObjectProperties> getObjectProperties(IEnumerable <object> objects) { var propertiesList = new List <SpeckleObjectProperties>(); var simpleProps = new List <ArchivableDictionary>(); int k = 0; foreach (object o in objects) { CommonObject myObj = null; GH_Brep brep = o as GH_Brep; if (brep != null) { myObj = brep.Value; } GH_Surface srf = o as GH_Surface; if (srf != null) { myObj = srf.Value; } GH_Mesh mesh = o as GH_Mesh; if (mesh != null) { myObj = mesh.Value; } GH_Curve crv = o as GH_Curve; if (crv != null) { myObj = crv.Value; } if (myObj != null) { if (myObj.UserDictionary.Keys.Length > 0) { propertiesList.Add(new SpeckleObjectProperties(k, myObj.UserDictionary)); } } k++; } return(propertiesList); }
private static GH_Mesh SetMeshLevel(GH_Mesh mesh, List <int> meshLevels, double?resolution) { var levelDetails = new MeshLevelDetails { Resolution = resolution, Level = meshLevels.Count > 0? new MeshLevels { Min = meshLevels.First(), Max = meshLevels.Last() }: null }; Geometry.setUserString( mesh, "ComputeMeshLevels", levelDetails.ToJson() ); return(mesh); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { //local varaibles GH_Mesh mesh = null; System.Collections.Generic.List <GH_String> attributeNames = new System.Collections.Generic.List <GH_String>(); System.Collections.Generic.List <GH_String> attributeValues = new System.Collections.Generic.List <GH_String>(); Dictionary <string, object> attributesDict = new Dictionary <string, object>(); //catch inputs and populate local variables if (!DA.GetData(0, ref mesh)) { return; } if (mesh == null) { return; } DA.GetDataList(1, attributeNames); DA.GetDataList(2, attributeValues); if (attributeValues.Count != attributeNames.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please provide equal numbers of attribute names and values."); return; } //populate dictionary int i = 0; foreach (var a in attributeNames) { attributesDict.Add(a.Value, attributeValues[i].Value); i++; } //create json from mesh string outJSON = _Utilities.geoJSONColoredVertices(mesh.Value, attributesDict); Material material = new Material(MaterialWithVertexColors(), SpectaclesMaterialType.Mesh); Element e = new Element(outJSON, SpectaclesElementType.Mesh, material, new Layer("Default")); DA.SetData(0, e); }
/// <summary> /// This procedure contains the user code. Input parameters are provided as regular arguments, /// Output parameters as ref arguments. You don't have to assign output parameters, /// they will have a default value. /// </summary> private void RunScript(List <System.Object> D, Mesh M, ref object Mc) { if (D.Count != M.Vertices.Count) { return; } // cast input list to an int array (faster access) int[] D1 = D.Select(x => (int)x).ToArray(); Parallel.For(0, M.Vertices.Count, i => { M.VertexColors[i] = cols[D1[i]]; } ); Mc = new GH_Mesh(M); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Mesh ghmesh = new GH_Mesh(); if (DA.GetData(0, ref ghmesh)) { Mesh mesh = new Mesh(); if (GH_Convert.ToMesh(ghmesh, ref mesh, GH_Conversion.Both)) { GsaElement2d elem = new GsaElement2d(mesh); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaProp2d) { gh_typ.CastTo(ref prop2d); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { prop2d.ID = idd; } } } else { prop2d.ID = 1; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem)); } } }
protected override void SolveInstance(IGH_DataAccess DA) { string name = null; GH_Plane tcp = null; double weight = 0; GH_Mesh mesh = null; GH_Point centroid = null; List <GH_Plane> planes = new List <GH_Plane>(); if (!DA.GetData(0, ref name)) { return; } if (!DA.GetData(1, ref tcp)) { return; } DA.GetDataList(2, planes); if (!DA.GetData(3, ref weight)) { return; } DA.GetData(4, ref centroid); DA.GetData(5, ref mesh); var tool = new Tool(tcp.Value, name, weight, centroid?.Value, mesh?.Value); if (planes.Count > 0) { if (planes.Count != 4) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, " Calibration input must be 4 planes"); } else { tool.FourPointCalibration(planes[0].Value, planes[1].Value, planes[2].Value, planes[3].Value); } } DA.SetData(0, new GH_Tool(tool)); DA.SetData(1, tool.Tcp); }
public PxGhRigidStaticMesh(Plane plane, Mesh mesh, Material material) { Mesh meshLocal = mesh.DuplicateMesh(); meshLocal.Transform(Transform.PlaneToPlane(plane, Plane.WorldXY)); List <Vector3> points = new List <Vector3>(); foreach (Point3d v in meshLocal.Vertices) { points.Add(new Vector3((float)v.X, (float)v.Y, (float)v.Z)); } List <int> faceVertexIndices = new List <int>(); foreach (MeshFace face in meshLocal.Faces) { faceVertexIndices.Add(face.A); faceVertexIndices.Add(face.B); faceVertexIndices.Add(face.C); } ConvexMeshDesc convexMeshDescription = new ConvexMeshDesc(); convexMeshDescription.Flags = ConvexFlag.ComputeConvex; convexMeshDescription.SetPositions(points.ToArray()); convexMeshDescription.SetTriangles(faceVertexIndices.ToArray()); MemoryStream memoryStream = new MemoryStream(); PhysXManager.Physics.CreateCooking().CookConvexMesh(convexMeshDescription, memoryStream); memoryStream.Position = 0; ConvexMesh convexMesh = PhysXManager.Physics.CreateConvexMesh(memoryStream); ConvexMeshGeometry convexMeshGeometry = new ConvexMeshGeometry(convexMesh); actor = PhysXManager.Physics.CreateRigidStatic(); actor.GlobalPose = plane.ToMatrix(); actor.CreateShape(convexMeshGeometry, material); ghMesh = new GH_Mesh(mesh); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { //local varaibles GH_Mesh mesh = null; List <GH_String> attributeNames = new List <GH_String>(); List <GH_String> attributeValues = new List <GH_String>(); Dictionary <string, object> attributesDict = new Dictionary <string, object>(); //catch inputs and populate local variables if (!DA.GetData(0, ref mesh)) { return; } if (mesh == null) { return; } DA.GetDataList(1, attributeNames); DA.GetDataList(2, attributeValues); if (attributeValues.Count != attributeNames.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please provide equal numbers of attribute names and values."); return; } //populate dictionary int i = 0; foreach (var a in attributeNames) { attributesDict.Add(a.Value, attributeValues[i].Value); i++; } //create json from mesh string outJSON = _Utilities.geoJSON(mesh.Value, attributesDict); DA.SetData(0, outJSON); DA.SetData(1, MaterialWithVertexColors()); }
protected override void BeforeSolveInstance() { ClearOutput(); point = false; curve = false; surface = false; brep = false; mesh = false; IGH_Structure dd = Params.Input[0].VolatileData; foreach (IGH_Goo geo in dd.AllData(true)) { if (geo is GH_Point) { point = true; } else if (geo is GH_Curve)////curve { curve = true; } else if (geo is GH_Brep) { GH_Brep bp = (GH_Brep)geo; if (bp.Value.IsSurface)///surface { surface = true; } else//////brep { brep = true; } } else if (geo is GH_Mesh) { mesh = true; GH_Mesh me = (GH_Mesh)geo; } } AddOutput(); }
public override bool CastTo <T>(out T target) { // cast to GH_Mesh if (typeof(T).IsAssignableFrom(typeof(GH_Mesh))) { object msh = new GH_Mesh(RhinoSupport.ToRhinoMesh(m_value)); target = (T)msh; return(true); } // cast to Mesh if (typeof(T).IsAssignableFrom(typeof(Mesh))) { Object msh = RhinoSupport.ToRhinoMesh(m_value); target = (T)msh; return(true); } // cast to GH_PlanktonMesh if (typeof(T).IsAssignableFrom(typeof(GH_PlanktonMesh))) { object msh = new GH_PlanktonMesh(new PlanktonMesh(m_value)); target = (T)msh; return(true); } // cast to PlanktonMesh if (typeof(T).IsAssignableFrom(typeof(PlanktonMesh))) { Object msh = new PlanktonMesh(m_value); target = (T)msh; return(true); } target = default(T); return(false); }
public override bool CastTo <Q>(ref Q target) { if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh))) { Mesh[] meshes = Value.ToMesh(); Mesh m = new Mesh(); for (int i = 0; i < meshes.Length; ++i) { m.Append(meshes[i]); } object mesh = new GH_Mesh(m); target = (Q)mesh; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GlulamAssembly))) { object blank = Value; target = (Q)blank; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Brep))) { Brep[] breps = Value.ToBrep(); Brep b = new Brep(); for (int i = 0; i < breps.Length; ++i) { b.Append(breps[i]); } object brep = new GH_Brep(b); target = (Q)brep; return(true); } return(base.CastTo <Q>(ref target)); }