Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UFrameIT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FrameIT
UFrameIT
Commits
a194612c
Commit
a194612c
authored
2 years ago
by
Tobias Schöner
Browse files
Options
Downloads
Patches
Plain Diff
feat: add generator for holed plane
parent
867ef8d0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Assets/Scripts/MeshGenerator/HoledPlaneGenerator.cs
+64
-0
64 additions, 0 deletions
Assets/Scripts/MeshGenerator/HoledPlaneGenerator.cs
Assets/Scripts/MeshGenerator/HoledPlaneGenerator.cs.meta
+11
-0
11 additions, 0 deletions
Assets/Scripts/MeshGenerator/HoledPlaneGenerator.cs.meta
with
75 additions
and
0 deletions
Assets/Scripts/MeshGenerator/HoledPlaneGenerator.cs
0 → 100644
+
64
−
0
View file @
a194612c
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Linq
;
using
UnityEngine
;
public
class
HoledPlaneGenerator
:
ShapeGenerator
{
#
region
InspectorVariables
[
Header
(
"Plane values"
)]
public
Vector2
planeSize
=
new
(
100
,
100
);
public
Vector2
holeLocation
=
new
(
50
,
50
);
public
float
holeRadius
=
1f
;
[
Header
(
"Technical"
)]
[
Range
(
4
,
1000
,
order
=
4
)]
public
int
holeSideCount
=
500
;
[
Header
(
"Parts"
)]
public
MeshFilter
planeMesh
;
#
endregion
InspectorVariables
#
region
Implementation
protected
override
void
GenerateShape
()
{
AssignMesh
(
planeMesh
,
CreateHoledPlane
(
planeSize
,
holeLocation
,
holeRadius
,
holeSideCount
));
}
private
static
(
Vector3
[]
vertices
,
int
[]
triangles
)
CreateHoledPlane
(
Vector2
planeSize
,
Vector2
holeLocation
,
float
holeRadius
,
int
holeSideCount
)
{
var
corners
=
new
Vector3
[
4
]
{
new
Vector3
(
planeSize
.
x
/
2
,
0
,
planeSize
.
y
/
2
),
new
Vector3
(
planeSize
.
x
/
2
,
0
,
-
planeSize
.
y
/
2
),
new
Vector3
(-
planeSize
.
x
/
2
,
0
,
-
planeSize
.
y
/
2
),
new
Vector3
(-
planeSize
.
x
/
2
,
0
,
planeSize
.
y
/
2
)
};
var
circlePoints
=
GetCirclePoints
(
holeRadius
,
holeSideCount
,
new
Vector3
(
holeLocation
.
x
,
0
,
holeLocation
.
y
));
Vector3
[]
vertices
=
circlePoints
.
Union
(
corners
).
ToArray
();
int
[]
triangles
=
new
int
[
vertices
.
Length
*
3
];
int
cpCount
=
circlePoints
.
Length
;
int
quarter
=
Mathf
.
FloorToInt
((
float
)
cpCount
/
4
);
int
rest
=
cpCount
%
4
;
int
start
=
0
;
for
(
int
corner
=
0
;
corner
<
4
;
corner
++)
{
int
cornerIdx
=
cpCount
+
corner
;
int
end
=
start
+
(
rest
--
>
0
?
quarter
+
1
:
quarter
);
for
(
int
i
=
start
;
i
<
end
;
i
++)
{
triangles
[
i
*
3
+
0
]
=
(
i
+
1
)
%
cpCount
;
triangles
[
i
*
3
+
1
]
=
i
;
triangles
[
i
*
3
+
2
]
=
cornerIdx
;
}
triangles
[
triangles
.
Length
-
((
corner
+
1
)*
3
)
+
0
]
=
end
%
cpCount
;
triangles
[
triangles
.
Length
-
((
corner
+
1
)*
3
)
+
1
]
=
cornerIdx
;
triangles
[
triangles
.
Length
-
((
corner
+
1
)*
3
)
+
2
]
=
cpCount
+
(
corner
+
1
)
%
4
;
start
=
end
;
}
return
(
vertices
,
triangles
);
}
#
endregion
Implementation
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Assets/Scripts/MeshGenerator/HoledPlaneGenerator.cs.meta
0 → 100644
+
11
−
0
View file @
a194612c
fileFormatVersion: 2
guid: 9965b0da5ebc17848beccc46e84bd114
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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