Skip to content

Commit

Permalink
update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
komietty committed Jan 5, 2023
1 parent de3d03d commit e2d348e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 224 deletions.
38 changes: 35 additions & 3 deletions Assets/Samples/Curvature/CurvatureViewer.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
using UnityEngine;
using static UnityEngine.GraphicsBuffer;
using static Unity.Mathematics.math;

namespace VectorField {
public class CurvatureViewer : TangentBundle {
public class CurvatureViewer : MonoBehaviour {
public enum CurvType {
ScalarGaussCurvature,
ScalarMeanCurvature,
PrincipalCurvature,
NormalCurvature
};
[SerializeField] protected CurvType curvType;
[SerializeField] protected Material surfMat;
protected GraphicsBuffer colBuf;
protected HeGeom geom;
protected Mesh mesh;

protected override void Start() {
base.Start();
void Start() {
var filt = GetComponentInChildren<MeshFilter>();
var rend = GetComponentInChildren<MeshRenderer>();
mesh = HeComp.Weld(filt.sharedMesh);
geom = new HeGeom(mesh, transform);
filt.sharedMesh = mesh;
rend.material = surfMat;
colBuf = new GraphicsBuffer(Target.Structured, geom.nVerts, 12);
UpdateCol(GenCurvatureCol());
}
void OnDestroy() {
colBuf?.Dispose();
}

protected void UpdateCol(float[] values) {
var n = geom.nVerts;
var x = 0f;
var vals = new float[n];
var lrps = new Vector3[n];
for (var i = 0; i < n; i++) {
var vrt = geom.Verts[i];
var val = values[vrt.vid];
vals[i] = val;
x = max(abs(val), x);
}
x = min(PI / 8, x);
for (var i = 0; i < n; i++) lrps[i] = ColorMap.Color(vals[i], -x, x);
colBuf.SetData(lrps);
surfMat.SetBuffer("_Col", colBuf);
}

float[] GenCurvatureCol() {
var c = new float[geom.nVerts];
Expand Down
11 changes: 5 additions & 6 deletions Assets/Samples/Curvature/CurvatureViewer.unity
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: b342c832fd42e4e0eb56ad391ca20b17, type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071068
value: 1
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: b342c832fd42e4e0eb56ad391ca20b17, type: 3}
propertyPath: m_LocalRotation.x
value: -0.7071068
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: b342c832fd42e4e0eb56ad391ca20b17, type: 3}
propertyPath: m_LocalRotation.y
Expand All @@ -343,7 +343,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: b342c832fd42e4e0eb56ad391ca20b17, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -90
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: b342c832fd42e4e0eb56ad391ca20b17, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
Expand All @@ -356,7 +356,7 @@ PrefabInstance:
- target: {fileID: -6400281290468069383, guid: b342c832fd42e4e0eb56ad391ca20b17, type: 3}
propertyPath: m_Mesh
value:
objectReference: {fileID: -2432090755550338912, guid: 08f0115afb38748dfa1b4a8401bf4725, type: 3}
objectReference: {fileID: -2432090755550338912, guid: b342c832fd42e4e0eb56ad391ca20b17, type: 3}
- target: {fileID: 919132149155446097, guid: b342c832fd42e4e0eb56ad391ca20b17, type: 3}
propertyPath: m_Name
value: bunny
Expand Down Expand Up @@ -385,9 +385,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a63855471c8db4181bc06a1a4dec2720, type: 3}
m_Name:
m_EditorClassIdentifier:
curvType: 0
surfMat: {fileID: 2100000, guid: 9cae412d13da54de783f7652ff10f15c, type: 2}
tngtMat: {fileID: 2100000, guid: 6dd285232008d44fdb3f388c2ec44785, type: 2}
curvType: 3
--- !u!1 &745660130
GameObject:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion Assets/Samples/HamonicBasis/HamonicBasisViewer.unity
Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,4 @@ MonoBehaviour:
m_EditorClassIdentifier:
surfMat: {fileID: 2100000, guid: 29d24685523474f149b6d05e68b78acb, type: 2}
tngtMat: {fileID: 2100000, guid: f06181c810ac942b99541d77166a8dcf, type: 2}
baseNumber: 1
baseNumber: 2
83 changes: 0 additions & 83 deletions Assets/Samples/Sampling/scale.obj

This file was deleted.

108 changes: 0 additions & 108 deletions Assets/Samples/Sampling/scale.obj.meta

This file was deleted.

20 changes: 0 additions & 20 deletions Packages/VectorField/Core/VectorField/TangentBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace VectorField {
public abstract class TangentBundle : MonoBehaviour {
[SerializeField] protected Material surfMat;
[SerializeField] protected Material tngtMat;
protected GraphicsBuffer colBuf;
protected GraphicsBuffer tngBuf;
protected HeGeom geom;
protected Mesh mesh;
Expand All @@ -22,27 +21,9 @@ public abstract class TangentBundle : MonoBehaviour {
geom = new HeGeom(mesh, transform);
filt.sharedMesh = mesh;
rend.material = surfMat;
colBuf = new GraphicsBuffer(Target.Structured, geom.nVerts, 12);
tngBuf = new GraphicsBuffer(Target.Structured, geom.nFaces * 6, 12);
}

protected void UpdateCol(float[] values) {
var n = geom.nVerts;
var x = 0f;
var vals = new float[n];
var lrps = new Vector3[n];
for (var i = 0; i < n; i++) {
var vrt = geom.Verts[i];
var val = values[vrt.vid];
vals[i] = val;
x = max(abs(val), x);
}
x = min(PI / 8, x);
for (var i = 0; i < n; i++) lrps[i] = ColorMap.Color(vals[i], -x, x);
colBuf.SetData(lrps);
surfMat.SetBuffer("_Col", colBuf);
}

protected void UpdateTng(float3[] omega) {
var n = geom.nFaces;
var tngs = new Vector3[n * 6];
Expand Down Expand Up @@ -83,7 +64,6 @@ public abstract class TangentBundle : MonoBehaviour {
}

protected virtual void OnDestroy() {
colBuf?.Dispose();
tngBuf?.Dispose();
}
}
Expand Down
5 changes: 3 additions & 2 deletions Packages/VectorField/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "com.komietty.vectorfield",
"displayName": "VectorFeild",
"version": "0.0.1",
"version": "0.1.0",
"unity": "2022.2",
"keywords": [
"Vector Field",
"Manifold",
"Geometry"
],
"description": "Vector field generator on mesh and a set of its operators",
"dependencies": {
"com.unity.mathematics": "1.2.6"
},
Expand All @@ -16,5 +17,5 @@
"email": "[email protected]",
"url": "https://github.com/komietty"
},
"type": "library"
"type": "module"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# unity-vectorfield
<img src="Documents/ribbon.png"/>

Unity-vectorfield is vector field generator on mesh and set of its oparators. It allows you to quick implementation of differecial geometry argolithms on Unity3d, then instantly applying to game programmings or media art creations. This library is heavily Inspired by [Keenan Crane's Lectures at CMU](https://www.cs.cmu.edu/~kmcrane/Projects/DDG/) and [Polyscope](https://github.com/nmwsharp/polyscope) and referencing a lot from them.
Unity-vectorfield is vector field generator on mesh and a set of its operators. It allows you to quick implementation of differential geometry algorithms on Unity3d, then instantly applying to game programming, media art creation, or physical simulation. This library is heavily Inspired by [Keenan Crane's Lectures at CMU](https://www.cs.cmu.edu/~kmcrane/Projects/DDG/) and [Polyscope](https://github.com/nmwsharp/polyscope) and referencing a lot from them.

## Features
This library contains features below:
Expand Down

0 comments on commit e2d348e

Please sign in to comment.