Esempio n. 1
0
        public void DrawDebug(Color col)
        {
            OffsetShapeLog.DrawLine(_nodes[0].position, _nodes[1].position, col);
            OffsetShapeLog.DrawLine(_nodes[1].position, _nodes[2].position, col);
            OffsetShapeLog.DrawLine(_nodes[2].position, _nodes[0].position, col);
            Vector3 center = Utils.ToV3((_nodes[0].position + _nodes[1].position + _nodes[2].position) / 3f);

            OffsetShapeLog.DrawDirection(center, _tangentV3, "tangent", col);
            OffsetShapeLog.DrawLabel(_centre, "\nTriangle ID " + id);
            //            Vector3 p0 = JMath.ToV3(_nodes[0].position);
            //            Vector3 p1 = JMath.ToV3(_nodes[1].position);
            //            Vector3 p2 = JMath.ToV3(_nodes[2].position);
            //
            //            Debug.DrawLine(p0, p1, col);
            //            Debug.DrawLine(p1, p2, col);
            //            Debug.DrawLine(p2, p0, col);
            ////
            //
            //            Color a = new Color(col.r, col.g, col.b, 0.25f);
            //            Vector3 v0 = p0 + Vector3.up * _nodes[0].height * 20;
            //            Vector3 v1 = p1 + Vector3.up * _nodes[1].height * 20;
            //            Vector3 v2 = p2 + Vector3.up * _nodes[2].height * 20;
            //
            //            Debug.DrawLine(positions[0], positions[1], col);
            //            Debug.DrawLine(positions[1], positions[2], col);
            //            Debug.DrawLine(positions[2], positions[0], col);
            //            GizmoLabel.Label("Node" + _nodes[0].id, v0);
            //            GizmoLabel.Label("Node" + _nodes[1].id, v1);
            //            GizmoLabel.Label("Node" + _nodes[2].id, v2);
        }
Esempio n. 2
0
        private void CalculateUVs(SkeletonTri tri)
        {
            int baseIndex = FindBaseIndex(tri);

            OffsetShapeLog.DrawLine(tri.centre, tri.positions[baseIndex], Color.red);
            Vector2 baseUV = Vector2.zero;

            OffsetShapeLog.AddLine("============");
            OffsetShapeLog.AddLine("triangle uv node find! ", tri.id, " base node id ", tri[baseIndex].id, " tangent ", tri.tangentV3);
            OffsetShapeLog.AddLine("============");
            foreach (UVNode uvnode in _uvnodes)
            {
                OffsetShapeLog.AddLine("uvnode! ", uvnode.node.id, uvnode.tangent);
                if (uvnode.node != tri[baseIndex])
                {
                    continue;
                }
                if (!uvnode.TangentCheck(tri.tangentV3))
                {
                    continue;
                }
                baseUV = uvnode.uv;
            }
            OffsetShapeLog.AddLine("!!!!!!!!!!!!");
            OffsetShapeLog.DrawLabel(tri.centre, baseUV.ToString());

            int indexB = (baseIndex + 1) % 3;
            int indexC = (baseIndex + 2) % 3;

            Vector3 p0 = tri.positions[baseIndex];
            Vector3 p1 = tri.positions[indexB];
            Vector3 p2 = tri.positions[indexC];

            Vector3 vA = p1 - p0;
            Vector3 vB = p2 - p0;

            Vector3 right   = tri.tangentV3;
            Vector3 up      = Vector3.Cross(right, tri.normal);
            Vector3 upVA    = Vector3.Project(vA, up);
            Vector3 rightVA = Vector3.Project(vA, right);
            Vector3 upVB    = Vector3.Project(vB, up);
            Vector3 rightVB = Vector3.Project(vB, right);

            float   apexUVAX = rightVA.magnitude * Mathf.Sign(Vector3.Dot(right, rightVA));
            float   apexUVAY = upVA.magnitude * Mathf.Sign(Vector3.Dot(up, upVA));
            Vector2 apexUVA  = baseUV + new Vector2(apexUVAX, apexUVAY);
            float   apexUVBX = rightVB.magnitude * Mathf.Sign(Vector3.Dot(right, rightVB));
            float   apexUVBY = upVB.magnitude * Mathf.Sign(Vector3.Dot(up, upVB));
            Vector2 apexUVB  = baseUV + new Vector2(apexUVBX, apexUVBY);

            _uvnodes.Add(new UVNode(tri[indexB], apexUVA, right));
            _uvnodes.Add(new UVNode(tri[indexC], apexUVB, right));

            Vector2[] uvs = new Vector2[3];
            uvs[baseIndex] = baseUV;
            uvs[indexB]    = apexUVA;
            uvs[indexC]    = apexUVB;
            tri.uvs        = uvs;
        }
Esempio n. 3
0
        public void Build(SkeletonData data)
        {
            System.Collections.Generic.List <SkeletonTri> allTris   = new System.Collections.Generic.List <SkeletonTri>(data.mesh.GetTriangles());
            System.Collections.Generic.List <SkeletonTri> startTris = new System.Collections.Generic.List <SkeletonTri>();
            int triCount = allTris.Count;

            for (int t = 0; t < triCount; t++)
            {
                SkeletonTri tri = allTris[t];
                if (tri.hasStartEdge)
                {
                    allTris.RemoveAt(t);
                    triCount--;
                    t--;
                    startTris.Add(tri);
                }
            }

            while (startTris.Count > 0)
            {
                SkeletonTri tri = startTris[0];
                startTris.RemoveAt(0);
                CalculateUVs(tri);
            }

            while (allTris.Count > 0)
            {
                SkeletonTri tri = allTris[0];
                allTris.RemoveAt(0);
                CalculateUVs(tri);
            }

            foreach (UVNode uvnode in _uvnodes)
            {
                OffsetShapeLog.DrawLabel(uvnode.node.position, "\n\n" + uvnode.uv);
            }
        }
Esempio n. 4
0
        private void AddFace(Edge liveEdge, Node staticNodeA, Node staticNodeB)
        {
            OffsetShapeLog.DrawEdge(liveEdge, Color.red);
            OffsetShapeLog.DrawLabel(liveEdge.nodeA.position, "new face");
            SkeletonFace face = new SkeletonFace(liveEdge, staticNodeA, staticNodeB);

            _faces.Add(face);

            if (!_edgeDic.ContainsKey(liveEdge.nodeA))
            {
                _edgeDic.Add(liveEdge.nodeA, new List <SkeletonFace>());
                _edgeDic[liveEdge.nodeA].Add(face);
            }
            else
            {
                _edgeDic[liveEdge.nodeA].Add(face);
            }

            if (!_edgeDic.ContainsKey(liveEdge.nodeB))
            {
                _edgeDic.Add(liveEdge.nodeB, new List <SkeletonFace>());
                _edgeDic[liveEdge.nodeB].Add(face);
            }
            else
            {
                _edgeDic[liveEdge.nodeB].Add(face);
            }

            if (!_nodeDic.ContainsKey(liveEdge))
            {
                _nodeDic.Add(liveEdge, face);
            }
            else
            {
                _nodeDic[liveEdge] = face;
            }
        }
Esempio n. 5
0
 public void DebugDrawMovement(Color col)
 {
     OffsetShapeLog.DrawLine(previousPosition, position, col);
     OffsetShapeLog.DrawLabel(position, "Node " + id);
 }