/// <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); }
/// <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) { /* * todo: select mesh box or simple box */ bool fakeShadow = false; var vg = default(VoxelGrid3D); da.GetData(0, ref vg); da.GetData(1, ref fakeShadow); var meshes = new List <Mesh>(); if (vg == null || !vg.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The (input) voxelgrid was invalid"); return; } var m = VoxelGridMeshHelper.VoxelGridToMesh(vg); try { meshes = VoxelGridMeshHelper.VoxelGridToMeshByPlanes(vg); } catch (Exception e) { throw new Exception($"Creating multiple meshes failed: {e.ToString()}"); } if (fakeShadow) { VoxelGridMeshHelper.addFakeShadow(ref m, new Vector3d(-0.495633, 0.142501, 0.856762), 1.0, Color.White, Color.Black); } da.SetData(0, m); if (meshes.Count == 6) { for (var i = 1; i <= meshes.Count; i++) { var mesh = meshes[i - 1]; if (fakeShadow) { VoxelGridMeshHelper.addFakeShadow(ref mesh, new Vector3d(-0.495633, 0.142501, 0.856762), 1.0, Color.White, Color.Black); } da.SetData(i, mesh); } } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Getting world planes failed"); } // get top faces // get bottom faces }
/// <summary> /// render the meshes /// </summary> private void GenerateBoxMeshes() { if (RenderMesh.Count != 0) { return; } foreach (var vg in RenderGrid) { var m = VoxelGridMeshHelper.VoxelGridToMesh(vg); VoxelGridMeshHelper.addFakeShadow(ref m, new Vector3d(-0.495633, 0.142501, 0.856762), 1.0, Color.White, Color.Black); RenderMesh.Add(m); } }
private void EnsureMeshCache() { if (_hasMeshCache) { return; } foreach (var ghGoo in m_data.AllData(true)) { var vg = (GH_VoxelGrid)ghGoo; var m = VoxelGridMeshHelper.VoxelGridToMesh(vg.Value); _bboxCache.Union(vg.Value.BBox.BoundingBox); VoxelGridMeshHelper.addFakeShadow(ref m, new Vector3d(-0.495633, 0.142501, 0.856762), 1.0, Color.White, Color.Black); _meshCache.Add(m); } _hasMeshCache = true; }