/// <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; }