Skip to content

Commit

Permalink
Adjust project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogoson committed Sep 21, 2021
1 parent 7839c6a commit f1ce9af
Show file tree
Hide file tree
Showing 148 changed files with 2,859 additions and 3,191 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "CodeProject"]
path = CodeProject
url = git@github.com:mogoson/CodeProject.git
[submodule "MGS.CommonCode"]
path = MGS.CommonCode
url = git@github.com:mogoson/MGS.CommonCode.git
Binary file not shown.
Binary file removed Attachment/README_Image/CurveHose/CircleHose.gif
Binary file not shown.
Binary file removed Attachment/README_Image/CurveHose/EllipseHose.gif
Binary file not shown.
Binary file removed Attachment/README_Image/CurveHose/HelixHose.gif
Binary file not shown.
Binary file not shown.
Binary file removed Attachment/README_Image/CurveHose/MachineCable.gif
Binary file not shown.
Binary file removed Attachment/README_Image/CurveHose/SinHose.gif
Binary file not shown.
Binary file added Attachment/images/MonoBezierCurveHose.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Attachment/images/MonoEllipseCurveHose.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Attachment/images/MonoHelixCurveHose.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Attachment/images/MonoHermiteCurveHose.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Attachment/images/MonoSinCurveHose.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Attachment/images/MonoSpringDemo.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion CodeProject
Submodule CodeProject deleted from 950a41
1 change: 1 addition & 0 deletions MGS.CommonCode
Submodule MGS.CommonCode added at 7b1419
209 changes: 152 additions & 57 deletions README.md
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
![](.\Attachment\images\MonoHermiteCurveHose.PNG)

![Bezier Hose Editor](./Attachment/README_Image/CurveHose/BezierHoseEditor.gif)
- MonoBezierCurveHose

- Hermite Hose Editor
![](.\Attachment\images\MonoBezierCurveHose.PNG)

![Hermite Hose Editor](./Attachment/README_Image/CurveHose/HermiteHoseEditor.gif)
- MonoHelixCurveHose

- Circle Hose
![](./Attachment/images/MonoHelixCurveHose.png)

![Circle Hose](./Attachment/README_Image/CurveHose/CircleHose.gif)
- MonoEllipseCurveHose

- Ellipse Hose
![](./Attachment/images/MonoEllipseCurveHose.png)

![Ellipse Hose](./Attachment/README_Image/CurveHose/EllipseHose.gif)
- MonoSinCurveHose

- Sin Hose
![](./Attachment/images/MonoSinCurveHose.png)

![Sin Hose](./Attachment/README_Image/CurveHose/SinHose.gif)
- MonoSpringDemo

- Helix Hose
![](./Attachment/images/MonoSpringDemo.png)

![Helix Hose](./Attachment/README_Image/CurveHose/HelixHose.gif)
------

- Machine Cable
[Previous](../../README.md)

![Machine Cable](./Attachment/README_Image/CurveHose/MachineCable.gif)
------

## Contact
- If you have any questions, feel free to contact me at mogoson@outlook.com.
Copyright © 2021 Mogoson. mogoson@outlook.com
Binary file not shown.
Binary file not shown.
21 changes: 0 additions & 21 deletions UnityProject/Assets/MGS-SkinnedMesh/LICENSE.txt

This file was deleted.

8 changes: 0 additions & 8 deletions UnityProject/Assets/MGS-SkinnedMesh/LICENSE.txt.meta

This file was deleted.

Binary file not shown.
8 changes: 0 additions & 8 deletions UnityProject/Assets/MGS-SkinnedMesh/Materials/Yellow.mat.meta

This file was deleted.

9 changes: 0 additions & 9 deletions UnityProject/Assets/MGS-SkinnedMesh/Prefabs/CurveHose.meta

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Loading

0 comments on commit f1ce9af

Please sign in to comment.