コード例 #1
0
    static bool Vector4_Normalize(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 0)
        {
            UnityEngine.Vector4 argThis = (UnityEngine.Vector4)vc.csObj;        argThis.Normalize();
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
コード例 #2
0
 static public int Normalize(IntPtr l)
 {
     try{
         UnityEngine.Vector4 self = (UnityEngine.Vector4)checkSelf(l);
         self.Normalize();
         setBack(l, self);
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #3
0
 static int Normalize(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.Vector4 obj = (UnityEngine.Vector4)ToLua.CheckObject(L, 1, typeof(UnityEngine.Vector4));
         obj.Normalize();
         ToLua.SetBack(L, 1, obj);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #4
0
ファイル: FastHull.cs プロジェクト: turbosheep/ThriveVR
 protected void SplitTriangle(FastHull topHull, FastHull bottomHull, int[] oldToNewVertexMap, Vector3 pointOnPlane, Vector3 planeNormal, int top, int cw, int ccw, out Vector3 cwIntersection, out Vector3 ccwIntersection)
 {
     Vector3 v0 = vertices[top];
     Vector3 v1 = vertices[cw];
     Vector3 v2 = vertices[ccw];
     
     // Intersect the top-cw edge with the plane
     float cwDenominator = Vector3.Dot(v1 - v0, planeNormal);
     float cwScalar = Mathf.Clamp01(Vector3.Dot(pointOnPlane - v0, planeNormal) / cwDenominator);
     
     // Intersect the top-ccw edge with the plane
     float ccwDenominator = Vector3.Dot(v2 - v0, planeNormal);
     float ccwScalar = Mathf.Clamp01(Vector3.Dot(pointOnPlane - v0, planeNormal) / ccwDenominator);
     
     // Interpolate vertex positions
     Vector3 cwVertex = new Vector3();
     
     cwVertex.x = v0.x + (v1.x - v0.x) * cwScalar;
     cwVertex.y = v0.y + (v1.y - v0.y) * cwScalar;
     cwVertex.z = v0.z + (v1.z - v0.z) * cwScalar;
     
     Vector3 ccwVertex = new Vector3();
     
     ccwVertex.x = v0.x + (v2.x - v0.x) * ccwScalar;
     ccwVertex.y = v0.y + (v2.y - v0.y) * ccwScalar;
     ccwVertex.z = v0.z + (v2.z - v0.z) * ccwScalar;
     
     // Create top triangle
     int cwA = topHull.vertices.Count;
     topHull.vertices.Add(cwVertex);
     
     int ccwA = topHull.vertices.Count;
     topHull.vertices.Add(ccwVertex);
     
     topHull.indices.Add(oldToNewVertexMap[top]);
     topHull.indices.Add(cwA);
     topHull.indices.Add(ccwA);
     
     // Create bottom triangles
     int cwB = bottomHull.vertices.Count;
     bottomHull.vertices.Add(cwVertex);
     
     int ccwB = bottomHull.vertices.Count;
     bottomHull.vertices.Add(ccwVertex);
     
     bottomHull.indices.Add(oldToNewVertexMap[cw]);
     bottomHull.indices.Add(oldToNewVertexMap[ccw]);
     bottomHull.indices.Add(ccwB);
     
     bottomHull.indices.Add(oldToNewVertexMap[cw]);
     bottomHull.indices.Add(ccwB);
     bottomHull.indices.Add(cwB);
     
     // Interpolate normals
     if (normals != null)
     {
         Vector3 n0 = normals[top];
         Vector3 n1 = normals[cw];
         Vector3 n2 = normals[ccw];
         
         Vector3 cwNormal = new Vector3();
         
         cwNormal.x = n0.x + (n1.x - n0.x) * cwScalar;
         cwNormal.y = n0.y + (n1.y - n0.y) * cwScalar;
         cwNormal.z = n0.z + (n1.z - n0.z) * cwScalar;
         
         cwNormal.Normalize();
         
         Vector3 ccwNormal = new Vector3();
         
         ccwNormal.x = n0.x + (n2.x - n0.x) * ccwScalar;
         ccwNormal.y = n0.y + (n2.y - n0.y) * ccwScalar;
         ccwNormal.z = n0.z + (n2.z - n0.z) * ccwScalar;
         
         ccwNormal.Normalize();
         
         // Add vertex property
         topHull.normals.Add(cwNormal);
         topHull.normals.Add(ccwNormal);
         
         bottomHull.normals.Add(cwNormal);
         bottomHull.normals.Add(ccwNormal);
     }
     
     // Interpolate colors
     if (colors != null)
     {
         Color32 c0 = colors[top];
         Color32 c1 = colors[cw];
         Color32 c2 = colors[ccw];
         
         Color32 cwColor = Color32.Lerp(c0, c1, cwScalar);
         Color32 ccwColor = Color32.Lerp(c0, c2, ccwScalar);
         
         // Add vertex property
         topHull.colors.Add(cwColor);
         topHull.colors.Add(ccwColor);
         
         bottomHull.colors.Add(cwColor);
         bottomHull.colors.Add(ccwColor);
     }
     
     // Interpolate tangents
     if (tangents != null)
     {
         Vector4 t0 = tangents[top];
         Vector4 t1 = tangents[cw];
         Vector4 t2 = tangents[ccw];
         
         Vector4 cwTangent = new Vector4();
         
         cwTangent.x = t0.x + (t1.x - t0.x) * cwScalar;
         cwTangent.y = t0.y + (t1.y - t0.y) * cwScalar;
         cwTangent.z = t0.z + (t1.z - t0.z) * cwScalar;
         
         cwTangent.Normalize();
         cwTangent.w = t1.w;
         
         Vector4 ccwTangent = new Vector4();
         
         ccwTangent.x = t0.x + (t2.x - t0.x) * ccwScalar;
         ccwTangent.y = t0.y + (t2.y - t0.y) * ccwScalar;
         ccwTangent.z = t0.z + (t2.z - t0.z) * ccwScalar;
         
         ccwTangent.Normalize();
         ccwTangent.w = t2.w;
         
         // Add vertex property
         topHull.tangents.Add(cwTangent);
         topHull.tangents.Add(ccwTangent);
         
         bottomHull.tangents.Add(cwTangent);
         bottomHull.tangents.Add(ccwTangent);
     }
     
     // Interpolate uvs
     if (uvs != null)
     {
         Vector2 u0 = uvs[top];
         Vector2 u1 = uvs[cw];
         Vector2 u2 = uvs[ccw];
         
         Vector2 cwUv = new Vector2();
         
         cwUv.x = u0.x + (u1.x - u0.x) * cwScalar;
         cwUv.y = u0.y + (u1.y - u0.y) * cwScalar;
         
         Vector2 ccwUv = new Vector2();
         
         ccwUv.x = u0.x + (u2.x - u0.x) * ccwScalar;
         ccwUv.y = u0.y + (u2.y - u0.y) * ccwScalar;
         
         // Add vertex property
         topHull.uvs.Add(cwUv);
         topHull.uvs.Add(ccwUv);
         
         bottomHull.uvs.Add(cwUv);
         bottomHull.uvs.Add(ccwUv);
     }
     
     // Set output
     cwIntersection = cwVertex;
     ccwIntersection = ccwVertex;
 }
コード例 #5
0
ファイル: LegacyHull.cs プロジェクト: turbosheep/ThriveVR
 protected void SplitTriangle(LegacyHull topHull, LegacyHull bottomHull, Edge topEdge0, Edge topEdge1, Edge topCutEdge, Edge bottomEdge0, Edge bottomEdge1, Edge bottomCutEdge, Edge bottomEdge2, int vertex0, int vertex1, int vertex2, float scalar0, float scalar1, int[] oldToNewVertex)
 {
     Vector3 n0 = normals[vertex0];
     Vector3 n1 = normals[vertex1];
     Vector3 n2 = normals[vertex2];
     
     Vector4 t0 = tangents[vertex0];
     Vector4 t1 = tangents[vertex1];
     Vector4 t2 = tangents[vertex2];
     
     Vector2 uv0 = uvs[vertex0];
     Vector2 uv1 = uvs[vertex1];
     Vector2 uv2 = uvs[vertex2];
     
     // Calculate the cut vertex data by interpolating original triangle values
     Vector3 cutNormal0 = new Vector3();
     
     cutNormal0.x = n0.x + (n1.x - n0.x) * scalar0;
     cutNormal0.y = n0.y + (n1.y - n0.y) * scalar0;
     cutNormal0.z = n0.z + (n1.z - n0.z) * scalar0;
     
     cutNormal0.Normalize();
     
     Vector3 cutNormal1 = new Vector3();
     
     cutNormal1.x = n1.x + (n2.x - n1.x) * scalar1;
     cutNormal1.y = n1.y + (n2.y - n1.y) * scalar1;
     cutNormal1.z = n1.z + (n2.z - n1.z) * scalar1;
     
     cutNormal1.Normalize();
     
     Vector4 cutTangent0 = new Vector4();
     
     cutTangent0.x = t0.x + (t1.x - t0.x) * scalar0;
     cutTangent0.y = t0.y + (t1.y - t0.y) * scalar0;
     cutTangent0.z = t0.z + (t1.z - t0.z) * scalar0;
     
     cutTangent0.Normalize();
     cutTangent0.w = t0.w;
     
     Vector4 cutTangent1 = new Vector4();
     
     cutTangent1.x = t1.x + (t2.x - t1.x) * scalar1;
     cutTangent1.y = t1.y + (t2.y - t1.y) * scalar1;
     cutTangent1.z = t1.z + (t2.z - t1.z) * scalar1;
     
     cutTangent1.Normalize();
     cutTangent1.w = t1.w;
     
     Vector2 cutUv0 = new Vector2();
     
     cutUv0.x = uv0.x + (uv1.x - uv0.x) * scalar0;
     cutUv0.y = uv0.y + (uv1.y - uv0.y) * scalar0;
     
     Vector2 cutUv1 = new Vector2();
     
     cutUv1.x = uv1.x + (uv2.x - uv1.x) * scalar1;
     cutUv1.y = uv1.y + (uv2.y - uv1.y) * scalar1;
     
     // Add the cut vertices to the hulls
     int topCutVertex0, topCutVertex1;
     
     topHull.AddVertex(topEdge0.point0.position, cutNormal0, cutTangent0, cutUv0, topEdge0.point0, out topCutVertex0);
     
     topHull.AddVertex(topEdge1.point0.position, cutNormal1, cutTangent1, cutUv1, topEdge1.point0, out topCutVertex1);
     
     int bottomCutVertex0, bottomCutVertex1;
     
     bottomHull.AddVertex(bottomEdge0.point0.position, cutNormal0, cutTangent0, cutUv0, bottomEdge0.point0, out bottomCutVertex0);
     
     bottomHull.AddVertex(bottomEdge1.point0.position, cutNormal1, cutTangent1, cutUv1, bottomEdge1.point0, out bottomCutVertex1);
     
     // Create the top of the original triangle
     Triangle topTriangle = new Triangle(topCutVertex0, oldToNewVertex[vertex1], topCutVertex1, topEdge0.point0, topEdge0.point1, topEdge1.point0, topEdge0, topEdge1, topCutEdge);
     
     topHull.triangles.Add(topTriangle);
     
     // Create the bottom of the original triangle
     Edge bottomCrossEdge = new Edge(bottomEdge0.point1, bottomEdge1.point0);
     
     Triangle bottomTriangle0 = new Triangle(oldToNewVertex[vertex0], bottomCutVertex0, bottomCutVertex1, bottomEdge0.point1, bottomEdge0.point0, bottomEdge1.point0, bottomEdge0, bottomCutEdge, bottomCrossEdge);
     Triangle bottomTriangle1 = new Triangle(oldToNewVertex[vertex0], bottomCutVertex1, oldToNewVertex[vertex2], bottomEdge0.point1, bottomEdge1.point0, bottomEdge1.point1, bottomCrossEdge, bottomEdge1, bottomEdge2);
     
     bottomHull.edges.Add(bottomCrossEdge);
     bottomHull.triangles.Add(bottomTriangle0);
     bottomHull.triangles.Add(bottomTriangle1);
 }