本文整理汇总了C#中CRSpline.Interp方法的典型用法代码示例。如果您正苦于以下问题:C# CRSpline.Interp方法的具体用法?C# CRSpline.Interp怎么用?C# CRSpline.Interp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRSpline
的用法示例。
在下文中一共展示了CRSpline.Interp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: generateMesh
void generateMesh()
{
if(meshPrefab==null)
return;
List<Vector3> vertices=new List<Vector3>();
List<int>[] triangles=new List<int>[3];
triangles[0]=new List<int>();
triangles[1]=new List<int>();
triangles[2]=new List<int>();
List<Vector2> uv=new List<Vector2>();
List<Vector3> normals=new List<Vector3>();
List<Vector4> tangents=new List<Vector4>();
CRSpline posSpline = new CRSpline( path.getPositions() );
//CRSpline rotSpline = new CRSpline( path.getRotations() );
Mesh[] mesh=new Mesh[3];
mesh[0]=meshPrefab.FindChild("start").GetComponent<MeshFilter>().sharedMesh;
mesh[1]=meshPrefab.FindChild("middle").GetComponent<MeshFilter>().sharedMesh;
mesh[2]=meshPrefab.FindChild("end").GetComponent<MeshFilter>().sharedMesh;
Vector3[][] meshVertices=new Vector3[3][];
int[][] meshTriangles=new int[3][];
Vector2[][] meshUv=new Vector2[3][];
Vector3[][] meshNormals=new Vector3[3][];
Vector4[][] meshTangents=new Vector4[3][];
float[] max=new float[3];
for(int i=0;i<3;i++)
{
meshVertices[i]=mesh[i].vertices;
meshTriangles[i]=mesh[i].GetTriangles(0);
meshUv[i]=mesh[i].uv;
meshNormals[i]=mesh[i].normals;
meshTangents[i]=mesh[i].tangents;
for(int vi=0;vi<meshTriangles[i].Length;vi++)
{
if(meshVertices[i][meshTriangles[i][vi]].x>max[i])
max[i]=meshVertices[i][meshTriangles[i][vi]].x;
}
}
float cursor=0;
int vertI=0;
int meshI=0;
if(path.round)
meshI=1;
bool last=false;
//float scale=1;
while(true)
{
if(meshI==2)
break;
if(getT(cursor+max[meshI])<1.0f || last)
{
if(last)
{
//scale=1.0f/(getT(cursor+max[meshI])-getT(cursor))*(1.0f-getT(cursor));
}
if(getT(cursor+max[meshI]+max[2])>1.0f && !path.round)
meshI=2;
for(int i=0;i<meshTriangles[meshI].Length;i++)
{
triangles[meshI].Add(vertI+meshTriangles[meshI][i]);
}
vertI+=mesh[meshI].vertexCount;
for(int i=0;i<meshVertices[meshI].Length;i++)
{
float vertexCursor=cursor+Mathf.Max(meshVertices[meshI][i].x,0);
float t=getT(vertexCursor);
Vector3 vPos=posSpline.Interp(t);
Vector3 look=posSpline.Velocity(t).normalized;
Quaternion r=Quaternion.LookRotation(look);
r=Quaternion.Euler(0,-90,0)*Quaternion.Euler(r.eulerAngles.z,(r.eulerAngles.y),-r.eulerAngles.x);
Vector3 localVert=meshVertices[meshI][i];
localVert.x=0;
Vector3 vert=(r*localVert)+(vPos-transform.position);
//vert.x-=middleVertices[i].x;
//Debug.Log(t);
vertices.Add(vert);
uv.Add(meshUv[meshI][i]);
normals.Add(r*meshNormals[meshI][i]);
tangents.Add(r*meshTangents[meshI][i]);
}
//Debug.Log(max);
cursor+=max[meshI];
if(meshI==0)
meshI=1;
//.........这里部分代码省略.........
示例2: DistributeNodes
public void DistributeNodes()
{
int numNodes = path.Count;
//if (numNodes<5) return;
Vector3[] newpositions = new Vector3[numNodes];
Vector3[] positions = new Vector3[numNodes];
for(int i=0; i<positions.Length; i++)
{
if( path[i] != null )
positions[i] = path[i].position;
}
CRSpline posSpline = new CRSpline( positions );
for (int a=1; a<positions.Length-1; a++)
{
float p = (1.0f / ((float)numNodes-3.0f)) * (a-1);
//Debug.Log(p+","+getT( splineLenght*p ));
newpositions[a] = posSpline.Interp(getT( splineLenght*p ));
}
for (int a=1; a<positions.Length-1; a++)
path[a].position = newpositions[a];
}
示例3: easePath
protected void easePath( )
{
positionSpline = new CRSpline( path.getPositions() );
rotationSpline = new CRSpline( path.getRotations() );
float startI=(1.0f/(positionSpline.pts.Length-3))*(pathStartNode-1);
float endI=(1.0f/(positionSpline.pts.Length-3))*(pathEndNode-1);
float i=startI+ ((endI-startI)*normalizedTime);
Vector3 newPos = positionSpline.Interp( i );
if (transform==null)
{
Debug.Log("EasePath error: "+easingGroup + " " + animationCurveName);
return;
}
if(space==Space.World)
transform.position = newPos;
else
transform.localPosition = newPos;
if( lookAtTransform!= null )
{
transform.LookAt( lookAtTransform, vectorUp );
}
else if( pathAlignWithSpeed )
{
Vector3 velVector = positionSpline.Velocity( i);
if(space==Space.World)
transform.rotation = Quaternion.LookRotation( velVector );
else
transform.localRotation = Quaternion.LookRotation( velVector );
}
else
{
Vector3 newRot = rotationSpline.Interp( i );
if(space==Space.World)
transform.rotation = Quaternion.Euler( newRot );
else
transform.localRotation = Quaternion.Euler( newRot );
}
}