添加插件
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ObiCatmullRomInterpolator : ObiInterpolator<float>
|
||||
{
|
||||
/**
|
||||
* 1D bezier spline interpolation
|
||||
*/
|
||||
public float Evaluate(float y0, float y1, float y2, float y3, float mu)
|
||||
{
|
||||
|
||||
float imu = 1 - mu;
|
||||
return imu * imu * imu * y0 +
|
||||
3f * imu * imu * mu * y1 +
|
||||
3f * imu * mu * mu * y2 +
|
||||
mu * mu * mu * y3;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 1D catmull rom spline second derivative
|
||||
*/
|
||||
public float EvaluateFirstDerivative(float y0, float y1, float y2, float y3, float mu)
|
||||
{
|
||||
|
||||
float imu = 1 - mu;
|
||||
return 3f * imu * imu * (y1 - y0) +
|
||||
6f * imu * mu * (y2 - y1) +
|
||||
3f * mu * mu * (y3 - y2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 1D catmull rom spline second derivative
|
||||
*/
|
||||
public float EvaluateSecondDerivative(float y0, float y1, float y2, float y3, float mu)
|
||||
{
|
||||
|
||||
float imu = 1 - mu;
|
||||
return 3f * imu * imu * (y1 - y0) +
|
||||
6f * imu * mu * (y2 - y1) +
|
||||
3f * mu * mu * (y3 - y2);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93918aac247384d8289d151d77dc4dc2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ObiCatmullRomInterpolator3D : ObiInterpolator<Vector3>
|
||||
{
|
||||
private ObiCatmullRomInterpolator interpolator = new ObiCatmullRomInterpolator();
|
||||
|
||||
/**
|
||||
* 3D spline interpolation
|
||||
*/
|
||||
public Vector3 Evaluate(Vector3 y0, Vector3 y1, Vector3 y2, Vector3 y3, float mu)
|
||||
{
|
||||
|
||||
return new Vector3(interpolator.Evaluate(y0.x, y1.x, y2.x, y3.x, mu),
|
||||
interpolator.Evaluate(y0.y, y1.y, y2.y, y3.y, mu),
|
||||
interpolator.Evaluate(y0.z, y1.z, y2.z, y3.z, mu));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 3D spline first derivative
|
||||
*/
|
||||
public Vector3 EvaluateFirstDerivative(Vector3 y0, Vector3 y1, Vector3 y2, Vector3 y3, float mu)
|
||||
{
|
||||
|
||||
return new Vector3(interpolator.EvaluateFirstDerivative(y0.x, y1.x, y2.x, y3.x, mu),
|
||||
interpolator.EvaluateFirstDerivative(y0.y, y1.y, y2.y, y3.y, mu),
|
||||
interpolator.EvaluateFirstDerivative(y0.z, y1.z, y2.z, y3.z, mu));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 3D spline second derivative
|
||||
*/
|
||||
public Vector3 EvaluateSecondDerivative(Vector3 y0, Vector3 y1, Vector3 y2, Vector3 y3, float mu)
|
||||
{
|
||||
|
||||
return new Vector3(interpolator.EvaluateSecondDerivative(y0.x, y1.x, y2.x, y3.x, mu),
|
||||
interpolator.EvaluateSecondDerivative(y0.y, y1.y, y2.y, y3.y, mu),
|
||||
interpolator.EvaluateSecondDerivative(y0.z, y1.z, y2.z, y3.z, mu));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 845dbd641b61b490bb94d745b6879e97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ObiColorInterpolator3D : ObiInterpolator<Color>
|
||||
{
|
||||
private ObiCatmullRomInterpolator interpolator = new ObiCatmullRomInterpolator();
|
||||
|
||||
/**
|
||||
* 3D spline interpolation
|
||||
*/
|
||||
public Color Evaluate(Color y0, Color y1, Color y2, Color y3, float mu)
|
||||
{
|
||||
|
||||
return new Color(interpolator.Evaluate(y0.r, y1.r, y2.r, y3.r, mu),
|
||||
interpolator.Evaluate(y0.g, y1.g, y2.g, y3.g, mu),
|
||||
interpolator.Evaluate(y0.b, y1.b, y2.b, y3.b, mu),
|
||||
interpolator.Evaluate(y0.a, y1.a, y2.a, y3.a, mu));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 3D spline first derivative
|
||||
*/
|
||||
public Color EvaluateFirstDerivative(Color y0, Color y1, Color y2, Color y3, float mu)
|
||||
{
|
||||
|
||||
return new Color(interpolator.EvaluateFirstDerivative(y0.r, y1.r, y2.r, y3.r, mu),
|
||||
interpolator.EvaluateFirstDerivative(y0.g, y1.g, y2.g, y3.g, mu),
|
||||
interpolator.EvaluateFirstDerivative(y0.b, y1.b, y2.b, y3.b, mu),
|
||||
interpolator.EvaluateFirstDerivative(y0.a, y1.a, y2.a, y3.a, mu));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 3D spline second derivative
|
||||
*/
|
||||
public Color EvaluateSecondDerivative(Color y0, Color y1, Color y2, Color y3, float mu)
|
||||
{
|
||||
|
||||
return new Color(interpolator.EvaluateSecondDerivative(y0.r, y1.r, y2.r, y3.r, mu),
|
||||
interpolator.EvaluateSecondDerivative(y0.g, y1.g, y2.g, y3.g, mu),
|
||||
interpolator.EvaluateSecondDerivative(y0.b, y1.b, y2.b, y3.b, mu),
|
||||
interpolator.EvaluateSecondDerivative(y0.a, y1.a, y2.a, y3.a, mu));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c2bda61c040346db8efd82f64c2422e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ObiConstantInterpolator : ObiInterpolator<int>
|
||||
{
|
||||
/**
|
||||
* constant interpolator
|
||||
*/
|
||||
public int Evaluate(int y0, int y1, int y2, int y3, float mu)
|
||||
{
|
||||
return mu < 0.5f ? y1 : y2;
|
||||
}
|
||||
|
||||
/**
|
||||
* derivative of constant value:
|
||||
*/
|
||||
public int EvaluateFirstDerivative(int y0, int y1, int y2, int y3, float mu)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* second derivative of constant value:
|
||||
*/
|
||||
public int EvaluateSecondDerivative(int y0, int y1, int y2, int y3, float mu)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33f10aef9ed544b14a762a9c6e8bf411
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
public interface ObiInterpolator<T>
|
||||
{
|
||||
T Evaluate(T v0, T v1, T v2, T v3, float mu);
|
||||
T EvaluateFirstDerivative(T v0, T v1, T v2, T v3, float mu);
|
||||
T EvaluateSecondDerivative(T v0, T v1, T v2, T v3, float mu);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af25f2a4d723548bfafa551b6da56d25
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user