-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mogoson
committed
Sep 21, 2021
1 parent
7839c6a
commit f1ce9af
Showing
148 changed files
with
2,859 additions
and
3,191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "CodeProject"] | ||
path = CodeProject | ||
url = [email protected]:mogoson/CodeProject.git | ||
[submodule "MGS.CommonCode"] | ||
path = MGS.CommonCode | ||
url = [email protected]:mogoson/MGS.CommonCode.git |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Submodule CodeProject
deleted from
950a41
Submodule MGS.CommonCode
added at
7b1419
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,180 @@ | ||
# MGS-SkinnedMesh | ||
[TOC] | ||
|
||
- [Alibaba Cloud](https://www.aliyun.com/minisite/goods?userCode=0fgf4qk9) | ||
# MGS.SkinnedMesh | ||
|
||
## Summary | ||
- Unity plugin for create skinned mesh in scene. | ||
|
||
## Demand | ||
|
||
### CurveHose | ||
|
||
- Create flexible hose base on bezier curve. | ||
- Create flexible hose base on anchor curve. | ||
- Unity plugin for create skinned mesh in scene. | ||
|
||
## Environment | ||
- Unity 5.0 or above. | ||
- .Net Framework 3.5 or above. | ||
|
||
## Achieve | ||
|
||
### CurveHose | ||
|
||
- BezierCurve : Define bezier curve. | ||
|
||
- HermiteCurve : Hermite curve in three dimensional space. | ||
|
||
- EllipseCurve : Ellipse curve. | ||
|
||
- HelixCurve : Helix curve. | ||
|
||
- SinCurve : Sin curve. | ||
|
||
- CurveHose : Define CurveHose to render dynamic hose mesh base on | ||
center curve. | ||
|
||
- BezierHose : Render dynamic hose mesh base on cubic bezier curve. | ||
|
||
- HermiteHose : Render dynamic hose mesh base on anchor vector animation | ||
curve. | ||
|
||
- CircleHose : Render dynamic hose mesh base on circle curve. | ||
|
||
- EllipseHose : Render dynamic hose mesh base on ellipse curve. | ||
|
||
- HelixHose : Render dynamic hose mesh base on helix curve. | ||
- .Net Framework 3.5 or above. | ||
- Unity 5.0 or above. | ||
|
||
- SinHose : Render dynamic hose mesh base on sin curve. | ||
## Platform | ||
|
||
- Windows | ||
|
||
## Implemented | ||
|
||
```C# | ||
public abstract class MonoSkinnedMesh : MonoBehaviour, ISkinnedMesh{} | ||
public abstract class MonoCurveHose : MonoSkinnedMesh, IMonoCurveHose{} | ||
public class MonoCurveSkinnedHose : MonoCurveHose, IMonoCurveHose{} | ||
public sealed class MeshUtility{} | ||
``` | ||
|
||
## Technology | ||
|
||
### Build Vertices | ||
|
||
```C# | ||
//Create polygon vertices. | ||
var vertices = new List<Vector3>(); | ||
var sector = 2 * Mathf.PI / edge; | ||
var radian = 0f; | ||
for (int i = 0; i <= edge; i++) | ||
{ | ||
radian = sector * i; | ||
vertices.Add(center + rotation * new Vector3(Mathf.Cos(radian), Mathf.Sin(radian)) * radius); | ||
} | ||
return vertices; | ||
|
||
//Create polygon triangles index base on center vertice. | ||
var triangles = new List<int>(); | ||
var offset = clockwise ? 0 : 1; | ||
for (int i = 0; i < edge; i++) | ||
{ | ||
triangles.Add(start + i + offset); | ||
triangles.Add(start + i - offset + 1); | ||
triangles.Add(center); | ||
} | ||
return triangles; | ||
|
||
//Create prism triangles index. | ||
var triangles = new List<int>(); | ||
var polygonVs = polygon + 1; | ||
var currentSegment = 0; | ||
var nextSegment = 0; | ||
for (int s = 0; s < segment - 1; s++) | ||
{ | ||
// Calculate start index. | ||
currentSegment = polygonVs * s; | ||
nextSegment = polygonVs * (s + 1); | ||
for (int p = 0; p < polygon; p++) | ||
{ | ||
// Left-Bottom triangle. | ||
triangles.Add(start + currentSegment + p); | ||
triangles.Add(start + currentSegment + p + 1); | ||
triangles.Add(start + nextSegment + p + 1); | ||
|
||
// Right-Top triangle. | ||
triangles.Add(start + currentSegment + p); | ||
triangles.Add(start + nextSegment + p + 1); | ||
triangles.Add(start + nextSegment + p); | ||
} | ||
} | ||
return triangles; | ||
|
||
//Create polygon uv. | ||
var uv = new List<Vector2>(); | ||
var sector = 2 * Mathf.PI / edge; | ||
var radian = 0f; | ||
var center = Vector2.one * 0.5f; | ||
for (int i = 0; i <= edge; i++) | ||
{ | ||
radian = sector * i; | ||
uv.Add(center + new Vector2(Mathf.Cos(radian), Mathf.Sin(radian)) * 0.5f); | ||
} | ||
return uv; | ||
|
||
//Create prism uv. | ||
var uv = new List<Vector2>(); | ||
var polygonVs = polygon + 1; | ||
var vertices = polygonVs * segment; | ||
var slice = 1.0f / polygon; | ||
var u = 0f; | ||
var v = 0f; | ||
for (int i = 0; i < vertices; i++) | ||
{ | ||
u = slice * (i % polygonVs); | ||
v = (i / polygonVs) % 2; | ||
uv.Add(new Vector2(u, v)); | ||
} | ||
return uv; | ||
``` | ||
|
||
### Build Mesh | ||
|
||
```C# | ||
//Rebuild the mesh of hose. | ||
mesh.vertices = CreateVertices(curve, segments, differ, isSeal); | ||
mesh.triangles = CreateTriangles(segments, isSeal); | ||
mesh.uv = CreateUV(segments, isSeal); | ||
mesh.RecalculateNormals(); | ||
mesh.RecalculateBounds(); | ||
``` | ||
|
||
### Shared Mesh | ||
|
||
```C# | ||
meshRenderer.sharedMesh = mesh; | ||
meshRenderer.localBounds = mesh.bounds; | ||
if (meshCollider) | ||
{ | ||
meshCollider.sharedMesh = null; | ||
meshCollider.sharedMesh = mesh; | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
- Attach mono curve component to a game object. | ||
- Attach mono skinned mesh component to a game object. | ||
- Adjust the args of curve and skinned component or edit curve in scene editor. | ||
|
||
- Adjust the args of curve and Rebuild runtime, and MonoSkinnedMesh will auto Rebuild. | ||
|
||
```C# | ||
var curve = GetComponent<MonoHermiteCurve>(); | ||
curve.AddAnchor(new HermiteAnchor(point)); | ||
curve..Rebuild();//The MonoSkinnedMesh will auto Rebuild. | ||
``` | ||
|
||
## Demo | ||
- Demos in the path "MGS-SkinnedMesh/Scenes" provide reference to you. | ||
|
||
- Demos in the path "MGS.Packages/SkinnedMesh/Demo/" provide reference to you. | ||
|
||
## Preview | ||
|
||
### CurveHose | ||
- MonoHermiteCurveHose | ||
|
||
- Bezier Hose Editor | ||
 | ||
|
||
 | ||
- MonoBezierCurveHose | ||
|
||
- Hermite Hose Editor | ||
 | ||
|
||
 | ||
- MonoHelixCurveHose | ||
|
||
- Circle Hose | ||
 | ||
|
||
 | ||
- MonoEllipseCurveHose | ||
|
||
- Ellipse Hose | ||
 | ||
|
||
 | ||
- MonoSinCurveHose | ||
|
||
- Sin Hose | ||
 | ||
|
||
 | ||
- MonoSpringDemo | ||
|
||
- Helix Hose | ||
 | ||
|
||
 | ||
------ | ||
|
||
- Machine Cable | ||
[Previous](../../README.md) | ||
|
||
 | ||
------ | ||
|
||
## Contact | ||
- If you have any questions, feel free to contact me at [email protected]. | ||
Copyright © 2021 Mogoson. [email protected] |
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
8 changes: 0 additions & 8 deletions
8
UnityProject/Assets/MGS-SkinnedMesh/Materials/Yellow.mat.meta
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-7.16 KB
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/BezierHose.prefab
Binary file not shown.
8 changes: 0 additions & 8 deletions
8
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/BezierHose.prefab.meta
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-6.65 KB
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/CircleHose.prefab
Binary file not shown.
8 changes: 0 additions & 8 deletions
8
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/CircleHose.prefab.meta
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-6.71 KB
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/EllipseHose.prefab
Binary file not shown.
8 changes: 0 additions & 8 deletions
8
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/EllipseHose.prefab.meta
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-7.12 KB
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/HelixHose.prefab
Binary file not shown.
8 changes: 0 additions & 8 deletions
8
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/HelixHose.prefab.meta
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-6.92 KB
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/HermiteHose.prefab
Binary file not shown.
8 changes: 0 additions & 8 deletions
8
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/HermiteHose.prefab.meta
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-6.86 KB
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/SinHose.prefab
Binary file not shown.
8 changes: 0 additions & 8 deletions
8
UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose/SinHose.prefab.meta
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.