Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MGP-Project
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stenvers,V. (Victor)
MGP-Project
Commits
025605b2
Commit
025605b2
authored
5 years ago
by
Maurice Manshanden
Browse files
Options
Downloads
Patches
Plain Diff
Fix incorrect winding order for splitted triangles
parent
ec6eb465
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Mini Project/Assets/Splitter.cs
+13
-12
13 additions, 12 deletions
Mini Project/Assets/Splitter.cs
with
13 additions
and
12 deletions
Mini Project/Assets/Splitter.cs
+
13
−
12
View file @
025605b2
...
...
@@ -37,7 +37,7 @@ public class MeshBuilder
{
// Setup a ray along the edge
Vector3
origin
=
this
.
vertices
[
index1
];
Vector3
direction
=
origin
-
this
.
vertices
[
index2
];
Vector3
direction
=
this
.
vertices
[
index2
]
-
origin
;
// Calculate intersection
float
t
=
Vector3
.
Dot
(
p
-
origin
,
n
)
/
Vector3
.
Dot
(
direction
,
n
);
...
...
@@ -127,7 +127,7 @@ public class Splitter : MonoBehaviour
void
SplitNode
(
MeshTreeNode
node
)
{
// Too small for splitting (TODO: make configurable?)
if
(
node
.
triangles
.
Length
<
10
)
if
(
node
.
triangles
.
Length
<
10
0
)
{
return
;
}
...
...
@@ -140,7 +140,7 @@ public class Splitter : MonoBehaviour
Vector3
p
=
this
.
mesh
.
GetCenter
(
node
.
triangles
);
// point on plane
float
d
=
-
n
.
x
*
p
.
x
-
n
.
y
*
p
.
y
-
n
.
z
*
p
.
z
;
//
For containing the triangles of the
left and right
children.
//
Indices for
left and right
triangles
List
<
int
>
left
=
new
List
<
int
>();
List
<
int
>
right
=
new
List
<
int
>();
...
...
@@ -174,28 +174,29 @@ public class Splitter : MonoBehaviour
// The difficult cases where one vertex is on one side, and the other
// two vertices are on the other side of the plane.
int
s
=
-
1
,
p1
=
-
1
,
p2
=
-
1
,
l
=
-
1
;
int
s
=
-
1
,
p1
=
-
1
,
p2
=
-
1
;
bool
l
=
false
;
if
(
s1
&&
!
s2
&&
!
s3
)
{
s
=
i1
;
p1
=
i2
;
p2
=
i3
;
l
=
0
;
}
if
(!
s1
&&
s2
&&
!
s3
)
{
s
=
i2
;
p1
=
i
1
;
p2
=
i
3
;
l
=
0
;
}
if
(!
s1
&&
!
s2
&&
s3
)
{
s
=
i3
;
p1
=
i1
;
p2
=
i2
;
l
=
0
;
}
if
(
s1
&&
!
s2
&&
!
s3
)
{
s
=
i1
;
p1
=
i2
;
p2
=
i3
;
l
=
true
;
}
if
(!
s1
&&
s2
&&
!
s3
)
{
s
=
i2
;
p1
=
i
3
;
p2
=
i
1
;
l
=
true
;
}
if
(!
s1
&&
!
s2
&&
s3
)
{
s
=
i3
;
p1
=
i1
;
p2
=
i2
;
l
=
true
;
}
if
(!
s1
&&
s2
&&
s3
)
{
s
=
i1
;
p1
=
i2
;
p2
=
i3
;
l
=
1
;
}
if
(
s1
&&
!
s2
&&
s3
)
{
s
=
i2
;
p1
=
i
1
;
p2
=
i
3
;
l
=
1
;
}
if
(
s1
&&
s2
&&
!
s3
)
{
s
=
i3
;
p1
=
i1
;
p2
=
i2
;
l
=
1
;
}
if
(!
s1
&&
s2
&&
s3
)
{
s
=
i1
;
p1
=
i2
;
p2
=
i3
;
l
=
false
;
}
if
(
s1
&&
!
s2
&&
s3
)
{
s
=
i2
;
p1
=
i
3
;
p2
=
i
1
;
l
=
false
;
}
if
(
s1
&&
s2
&&
!
s3
)
{
s
=
i3
;
p1
=
i1
;
p2
=
i2
;
l
=
false
;
}
int
x1
=
mesh
.
SplitEdge
(
p1
,
s
,
p
,
n
);
int
x2
=
mesh
.
SplitEdge
(
p2
,
s
,
p
,
n
);
if
(
l
==
0
)
if
(
l
)
{
left
.
AddRange
(
new
[]
{
x1
,
x2
,
s
});
right
.
AddRange
(
new
[]
{
x1
,
p1
,
p2
,
p2
,
x2
,
x1
});
}
else
{
right
.
AddRange
(
new
[]
{
x1
,
x2
,
s
});
left
.
AddRange
(
new
[]
{
x1
,
p1
,
p2
,
p2
,
x2
,
x1
});
right
.
AddRange
(
new
[]
{
x1
,
x2
,
s
});
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment