forked from leap71/PicoGK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEx_SmoothenObject.cs
63 lines (55 loc) · 2.28 KB
/
Ex_SmoothenObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// SPDX-License-Identifier: CC0-1.0
//
// This example code file is released to the public under Creative Commons CC0.
// See https://creativecommons.org/publicdomain/zero/1.0/legalcode
//
// To the extent possible under law, LEAP 71 has waived all copyright and
// related or neighboring rights to this PicoGK example code file.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
using PicoGK;
using System.Numerics;
namespace PicoGKExamples
{
///////////////////////////////////////////////////////////////////////////
// Below is a static class that implements a single static function
// that can be called from Library::Go()
class SmoothenObject
{
public static void Task()
{
try
{
// Create a mesh from an existing STL file
Mesh msh = Mesh.mshFromStlFile(
Path.Combine( Utils.strPicoGKSourceCodeFolder(),
"Examples/Testfiles/Teapot.stl"));
// Add it to the viewer (moving it 20mm to the side)
Library.oViewer().Add(
msh.mshCreateTransformed( new Vector3(1.0f),
new Vector3(20f, 0f,0f)));
// Create a voxel field from the mesh
Voxels vox = new Voxels(msh);
// Use the TripleOffset function to smoothen the object
// this offsets the object 1mm inwards
// then offsets it 2mm outwards
// then offsets it 1mm inwards again
// eliminating detail of less than 1mm
vox.TripleOffset(1.0f);
Library.oViewer().Add(vox);
}
catch (Exception e)
{
Library.Log($"Failed to run example: \n{e.Message}"); ;
}
}
}
}