-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTrimMeshWithCurveOp.cs
107 lines (85 loc) · 3.04 KB
/
TrimMeshWithCurveOp.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) Ryan Schmidt ([email protected]) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited. Proprietary and confidential.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using g3;
namespace gs
{
public class TrimMeshWithCurveOp : BaseDMeshSourceOp
{
DMesh3 TrimmedMesh;
IMeshSourceOp mesh_source;
public IMeshSourceOp MeshSource {
get { return mesh_source; }
set {
if (mesh_source != null)
mesh_source.OperatorModified -= on_input_modified;
mesh_source = value;
if (mesh_source != null)
mesh_source.OperatorModified += on_input_modified;
invalidate();
}
}
ISampledCurve3dSourceOp curve_source;
public ISampledCurve3dSourceOp CurveSource {
get { return curve_source; }
set {
if (curve_source != null)
curve_source.OperatorModified -= on_input_modified;
curve_source = value;
if (curve_source != null)
curve_source.OperatorModified += on_input_modified;
invalidate();
}
}
protected virtual void on_input_modified(ModelingOperator op) {
base.invalidate();
}
public virtual void Update()
{
base.begin_update();
if (MeshSource == null)
throw new Exception("TrimMeshFromCurveOp: must set valid MeshSource to compute!");
if (CurveSource == null)
throw new Exception("TrimMeshFromCurveOp: must set valid CurveSource to compute!");
IMesh meshIn = MeshSource.GetIMesh();
//ISpatial spatialIn = MeshSource.GetSpatial();
DCurve3 curve = new DCurve3(CurveSource.GetICurve());
TrimmedMesh = new DMesh3(meshIn, MeshHints.None);
AxisAlignedBox3d bounds = TrimmedMesh.CachedBounds;
Vector3d seed = bounds.Center + bounds.Extents.y * Vector3d.AxisY;
MeshTrimLoop trim = new MeshTrimLoop(TrimmedMesh, curve, seed, null);
trim.Trim();
ApplyModifiers(TrimmedMesh);
base.complete_update();
}
/*
* IMeshSourceOp / DMeshSourceOp interface
*/
public override IMesh GetIMesh()
{
if (base.requires_update())
Update();
return TrimmedMesh;
}
public override DMesh3 GetDMeshUnsafe() {
return (DMesh3)GetIMesh();
}
public override bool HasSpatial {
get { return false; }
}
public override ISpatial GetSpatial() {
return null;
}
public override DMesh3 ExtractDMesh()
{
Update();
var result = TrimmedMesh;
TrimmedMesh = null;
base.result_consumed();
return result;
}
}
}