Initial Commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*=========================================================================
|
||||
|
||||
Library: iMSTK-Unity
|
||||
|
||||
Copyright (c) Kitware, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=========================================================================*/
|
||||
|
||||
namespace ImstkUnity
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to maintain a simple ring buffer for accumulating data, the buffer
|
||||
/// maintains the sum of the data as well for fast average calculation.
|
||||
/// The size can be determined at initialization.
|
||||
/// Used to keep track of timing and performance data outside of the profiler
|
||||
/// </summary>
|
||||
public class AccumulatingBuffer
|
||||
{
|
||||
private float[] _data;
|
||||
private int _length;
|
||||
private int _current = 0;
|
||||
private float _sum = 0;
|
||||
|
||||
public int Length
|
||||
{
|
||||
get { return _length; }
|
||||
}
|
||||
|
||||
public float Average
|
||||
{
|
||||
get { return _sum / _length; }
|
||||
}
|
||||
|
||||
public AccumulatingBuffer(int size)
|
||||
{
|
||||
_data = new float[size];
|
||||
for (int i = 0; i < _length; ++i)
|
||||
{
|
||||
_data[i] = 0;
|
||||
}
|
||||
_length = size;
|
||||
}
|
||||
|
||||
public void Push(float val)
|
||||
{
|
||||
_sum -= _data[_current];
|
||||
_data[_current] = val;
|
||||
_sum += _data[_current];
|
||||
_current = (_current + 1) % _length;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a90673231ba79240b70d953f7fd2be3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 936dbb32eb653d84a9bcbe9caad48547, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,144 @@
|
||||
/*=========================================================================
|
||||
|
||||
Library: iMSTK-Unity
|
||||
|
||||
Copyright (c) Kitware, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=========================================================================*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ImstkUnity
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to handle a series of collision pairs and their data, maybe this could be
|
||||
/// refactored to hold actual instances of interactions ...
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class CollisionInteractions
|
||||
{
|
||||
[Serializable]
|
||||
public class CollisionInteractionData
|
||||
{
|
||||
public DynamicalModel model1;
|
||||
public DynamicalModel model2;
|
||||
|
||||
public double friction = 0.0;
|
||||
public double restitution = 0.0;
|
||||
|
||||
public double deformableStiffness1 = 0.2;
|
||||
public double deformableStiffness2 = 0.2;
|
||||
|
||||
public double rigidBodyCompliance = 0.0001;
|
||||
|
||||
public string collisionTypeName = "Auto";
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
public List<CollisionInteractionData> _collisions = new List<CollisionInteractionData>();
|
||||
|
||||
public CollisionInteractions() {}
|
||||
public CollisionInteractions(CollisionInteractions other)
|
||||
{
|
||||
_collisions = new List<CollisionInteractionData>(other._collisions);
|
||||
}
|
||||
|
||||
public CollisionInteractionData GetData(DynamicalModel a, DynamicalModel b)
|
||||
{
|
||||
var index = Index(a, b);
|
||||
if (index >= 0) return _collisions[index];
|
||||
else
|
||||
{
|
||||
throw new System.Exception("Could not find collision pair");
|
||||
}
|
||||
}
|
||||
|
||||
public CollisionInteractionData Add(DynamicalModel a, DynamicalModel b)
|
||||
{
|
||||
var index = Index(a, b);
|
||||
if (index < 0)
|
||||
{
|
||||
|
||||
var data = new CollisionInteractionData();
|
||||
data.model1 = a;
|
||||
data.model2 = b;
|
||||
_collisions.Add(data);
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.Exception("Add Called with pair that already exists");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetData(CollisionInteractionData d)
|
||||
{
|
||||
var index = Index(d.model1, d.model2);
|
||||
if (index >= 0)
|
||||
{
|
||||
_collisions[index] = d;
|
||||
}
|
||||
else
|
||||
{
|
||||
_collisions.Add(d);
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(CollisionInteractionData d)
|
||||
{
|
||||
var index = Index(d.model1, d.model2);
|
||||
if (index > 0)
|
||||
{
|
||||
_collisions.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(DynamicalModel a, DynamicalModel b)
|
||||
{
|
||||
var index = Index(a, b);
|
||||
if (index >= 0)
|
||||
{
|
||||
_collisions.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(DynamicalModel a)
|
||||
{
|
||||
_collisions.RemoveAll(x => x.model1 == a || x.model2 == a);
|
||||
}
|
||||
|
||||
public void RemoveAllNull()
|
||||
{
|
||||
_collisions.RemoveAll(x => x.model1 == null || x.model2 == null);
|
||||
}
|
||||
|
||||
public bool IsEnabled(DynamicalModel a, DynamicalModel b)
|
||||
{
|
||||
return Index(a, b) != -1;
|
||||
}
|
||||
|
||||
|
||||
private int Index(DynamicalModel a, DynamicalModel b)
|
||||
{
|
||||
return _collisions.FindIndex(x =>
|
||||
{
|
||||
return (a == x.model1 && b == x.model2) ||
|
||||
(a == x.model2 && b == x.model1);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52017e2e915a71d4280520f4108c6f11
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 936dbb32eb653d84a9bcbe9caad48547, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,113 @@
|
||||
/*=========================================================================
|
||||
|
||||
Library: iMSTK-Unity
|
||||
|
||||
Copyright (c) Kitware, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=========================================================================*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace ImstkUnity
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles drawing of meshes in the editor, can draw line or triangle meshes
|
||||
/// </summary>
|
||||
public static class ImstkGizmos
|
||||
{
|
||||
static public void DrawPointMesh(Mesh mesh, Vector3 position, Quaternion rotation, Vector3 localScale, Color? color = null)
|
||||
{
|
||||
var actualColor = color ?? Color.white;
|
||||
for (int i = 0; i < mesh.vertices.Length - 1; ++i)
|
||||
{
|
||||
Vector3 v0 = mesh.vertices[i];
|
||||
v0 = rotation * v0;
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
v0[j] = v0[j] * localScale[j];
|
||||
}
|
||||
v0 = v0 + position;
|
||||
Gizmos.color = actualColor;
|
||||
Gizmos.DrawLine(v0, v0);
|
||||
}
|
||||
}
|
||||
static public void DrawLineMesh(Mesh mesh, Vector3 position, Quaternion rotation, Vector3 localScale, Color? color = null)
|
||||
{
|
||||
var actualColor = color ?? Color.white;
|
||||
for (int i = 0; i < mesh.vertices.Length - 1; ++i)
|
||||
{
|
||||
Vector3 v0 = mesh.vertices[i];
|
||||
Vector3 v1 = mesh.vertices[i + 1];
|
||||
v0 = rotation * v0;
|
||||
v1 = rotation * v1;
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
v0[j] = v0[j] * localScale[j];
|
||||
v1[j] = v1[j] * localScale[j];
|
||||
}
|
||||
v0 = v0 + position;
|
||||
v1 = v1 + position;
|
||||
|
||||
Gizmos.color = actualColor;
|
||||
Gizmos.DrawLine(v0, v1);
|
||||
}
|
||||
}
|
||||
|
||||
static public void DrawLineMesh(Mesh mesh, Color? color = null)
|
||||
{
|
||||
var actualColor = color ?? Color.white;
|
||||
for (int i = 0; i < mesh.vertices.Length - 1; ++i)
|
||||
{
|
||||
Vector3 v0 = mesh.vertices[i];
|
||||
Vector3 v1 = mesh.vertices[i + 1];
|
||||
Gizmos.color = actualColor;
|
||||
Gizmos.DrawLine(v0, v1);
|
||||
}
|
||||
}
|
||||
|
||||
static public void DrawMesh(Mesh mesh, Color? color = null)
|
||||
{
|
||||
DrawMesh(mesh, Vector3.zero, Quaternion.identity, Vector3.one, color);
|
||||
}
|
||||
|
||||
static public void DrawMesh(Mesh mesh, Vector3 position, Quaternion rotation, Vector3 localScale, Color? color = null)
|
||||
{
|
||||
if (mesh)
|
||||
{
|
||||
// Only check for the first sub-mesh
|
||||
switch (mesh.GetTopology(0))
|
||||
{
|
||||
case MeshTopology.Quads:
|
||||
case MeshTopology.Triangles:
|
||||
Gizmos.color = color ?? Color.white;
|
||||
Gizmos.DrawWireMesh(mesh, position, rotation, localScale);
|
||||
break;
|
||||
case MeshTopology.Lines:
|
||||
case MeshTopology.LineStrip:
|
||||
DrawLineMesh(mesh, position, rotation, localScale, color);
|
||||
break;
|
||||
case MeshTopology.Points:
|
||||
DrawPointMesh(mesh, position, rotation, localScale, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
static public void DrawMesh(Imstk.PointSet pointSet, Color? color = null)
|
||||
{
|
||||
var mesh = pointSet.ToMesh();
|
||||
DrawMesh(mesh, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 589c0c96d50516d4f948b897face7732
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 936dbb32eb653d84a9bcbe9caad48547, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
/*=========================================================================
|
||||
|
||||
Library: iMSTK-Unity
|
||||
|
||||
Copyright (c) Kitware, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=========================================================================*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace ImstkUnity
|
||||
{
|
||||
public class PullOnKey : MonoBehaviour
|
||||
{
|
||||
public string key = "p";
|
||||
public Suturing suturing;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
if (suturing == null)
|
||||
{
|
||||
suturing = GetComponent<Suturing>();
|
||||
if (suturing == null)
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(key))
|
||||
{
|
||||
suturing.Pull();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db82d5cfb9b04c64489ef356f79d9134
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 936dbb32eb653d84a9bcbe9caad48547, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
/*=========================================================================
|
||||
|
||||
Library: iMSTK-Unity
|
||||
|
||||
Copyright (c) Kitware, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=========================================================================*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace ImstkUnity
|
||||
{
|
||||
// Simple singleton class as per https://blog.yarsalabs.com/using-singletons-in-unity/
|
||||
// More powerful version is https://gist.github.com/rickyah/271e3aa31ff8079365bc
|
||||
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
private static T _instance;
|
||||
public static T Instance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = FindObjectOfType<T>();
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new GameObject(typeof(T).Name).AddComponent<T>();
|
||||
}
|
||||
}
|
||||
else if (_instance != FindObjectOfType<T>())
|
||||
{
|
||||
Destroy(FindObjectOfType<T>());
|
||||
}
|
||||
// Need to check if this is necessary
|
||||
// DontDestroyOnLoad(_instance.gameObject);
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 304d361e811909849aa344698e3891af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 936dbb32eb653d84a9bcbe9caad48547, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
/*=========================================================================
|
||||
|
||||
Library: iMSTK-Unity
|
||||
|
||||
Copyright (c) Kitware, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=========================================================================*/
|
||||
|
||||
namespace ImstkUnity
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to gather information about runtime behavior, mirrors the
|
||||
/// pattern of the Unity Profilermarker, but gives access to it's data
|
||||
/// for in game display. Use Begin() and End() to mark a section of interes
|
||||
/// after End() the timing value is automatically pushed to the buffer
|
||||
/// </summary>
|
||||
public class TimingBuffer
|
||||
{
|
||||
private AccumulatingBuffer _buffer;
|
||||
private System.Diagnostics.Stopwatch _stopwatch = new System.Diagnostics.Stopwatch();
|
||||
|
||||
public float AverageTimeMs
|
||||
{
|
||||
get { return _buffer.Average * 1000; }
|
||||
}
|
||||
|
||||
public float AverageTimeSeconds
|
||||
{
|
||||
get { return _buffer.Average; }
|
||||
}
|
||||
|
||||
public float AverageRateSeconds
|
||||
{
|
||||
get { return 1.0f / AverageTimeSeconds; }
|
||||
}
|
||||
|
||||
public TimingBuffer(int size)
|
||||
{
|
||||
_buffer = new AccumulatingBuffer(size);
|
||||
}
|
||||
|
||||
public void Begin()
|
||||
{
|
||||
_stopwatch.Restart();
|
||||
}
|
||||
|
||||
public void End()
|
||||
{
|
||||
_stopwatch.Stop();
|
||||
_buffer.Push((float)_stopwatch.Elapsed.TotalSeconds);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4357ae8e312beb2458f3c4a2abd19904
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 936dbb32eb653d84a9bcbe9caad48547, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user