示例#1
0
        private void AutoProjectUVs(EditableMesh eMesh)
        {
            var trgPos = MeshManager.targetTransform.position;

            var gn = GridNavigator.Inst();

            if (projectorNormalThreshold01 == 1)
            {
                foreach (var t in eMesh.triangles)
                {
                    for (var i = 0; i < 3; i++)
                    {
                        var v = t.vertexes[i];
                        v.SetUvIndexBy(PosToUv(v.meshPoint.WorldPos - trgPos));
                    }
                }
            }
            else
            {
                foreach (var t in eMesh.triangles)
                {
                    var norm = t.GetSharpNormal();

                    // var pv = gn.InPlaneVector(norm);

                    var perp = gn.PerpendicularToPlaneVector(norm);

                    if ((Mathf.Abs(perp) < projectorNormalThreshold01) || (perp > 0 != projectFront))
                    {
                        continue;
                    }

                    for (var i = 0; i < 3; i++)
                    {
                        var v = t.vertexes[i];

                        v.SetUvIndexBy(PosToUv(v.meshPoint.WorldPos - trgPos));
                    }
                }
            }

            eMesh.Dirty = true;
        }
示例#2
0
        public void DrowLinesAroundTargetPiece()
        {
            Vector3 piecePos = target.transform.TransformPoint(-Vector3.one / 2);//PositionScripts.PosUpdate(_target.getpos(), false);


            Vector3 projected = GridNavigator.Inst().ProjectToGrid(piecePos); // piecePos * getGridMaskVector() + ptdPos.ToV3(false)*getGridPerpendicularVector();
            Vector3 GridMask  = GridNavigator.Inst().GetGridMaskVector() * 128 + projected;



            Debug.DrawLine(new Vector3(projected.x, projected.y, projected.z), new Vector3(GridMask.x, projected.y, projected.z), Color.red);
            Debug.DrawLine(new Vector3(projected.x, projected.y, projected.z), new Vector3(projected.x, GridMask.y, projected.z), Color.red);
            Debug.DrawLine(new Vector3(projected.x, projected.y, projected.z), new Vector3(projected.x, projected.y, GridMask.z), Color.red);

            Debug.DrawLine(new Vector3(projected.x, GridMask.y, GridMask.z), new Vector3(GridMask.x, GridMask.y, GridMask.z), Color.red);
            Debug.DrawLine(new Vector3(GridMask.x, projected.y, GridMask.z), new Vector3(GridMask.x, GridMask.y, GridMask.z), Color.red);
            Debug.DrawLine(new Vector3(GridMask.x, GridMask.y, projected.z), new Vector3(GridMask.x, GridMask.y, GridMask.z), Color.red);

            MyDebugClasses.DrawTransformedCubeDebug(target.transform, Color.blue);
        }
示例#3
0
        void ExtendPath()
        {
            var selectedLine = MeshMGMT.SelectedLine;
            var mm           = MeshMGMT;

            if (updated == false)
            {
                return;
            }
            if (selectedLine == null)
            {
                updated = false; return;
            }

            MeshMGMT.UpdateLocalSpaceV3s();

            Vector3 previousCenterPos = selectedLine.pnts[0].Pos;

            Vector3 previousAB = selectedLine.pnts[1].Pos - selectedLine.pnts[0].Pos;

            previousCenterPos += (previousAB / 2);



            Vector3 vector   = mm.onGridLocal - previousCenterPos;
            float   distance = vector.magnitude;

            MeshPoint a = new MeshPoint(selectedLine.pnts[0].Pos);
            MeshPoint b = new MeshPoint(selectedLine.pnts[1].Pos);

            EditedMesh.meshPoints.Add(a);
            EditedMesh.meshPoints.Add(b);

            Vertex aUV = new Vertex(a, selectedLine.pnts[0].EditedUV + uvChangeSpeed * distance);
            Vertex bUV = new Vertex(b, selectedLine.pnts[1].EditedUV + uvChangeSpeed * distance);



            EditedMesh.triangles.Add(new Triangle(new Vertex[] { selectedLine.pnts[0], bUV, selectedLine.pnts[1] }));
            Triangle headTris = new Triangle(new Vertex[] { selectedLine.pnts[0], aUV, bUV });

            EditedMesh.triangles.Add(headTris);

            //

            switch (mode)
            {
            case GtoolPathConfig.ToPlanePerpendicular:
                //vector = previousCenterPos.DistanceV3To(ptdPos);

                a.localPos = mm.onGridLocal;
                b.localPos = mm.onGridLocal;


                Vector3 cross = Vector3.Cross(vector, GridNavigator.Inst().GetGridPerpendicularVector()).normalized *width / 2;
                a.localPos += cross;
                b.localPos += -cross;



                break;

            case GtoolPathConfig.Rotate:
                // Vector3 ab = a.pos.DistanceV3To(b.pos).normalized * gtoolPath.width;

                a.localPos = mm.onGridLocal;
                b.localPos = mm.onGridLocal;



                Quaternion rot   = Quaternion.FromToRotation(previousAB, vector);
                Vector3    rotv3 = (rot * vector).normalized * width / 2;
                a.localPos += rotv3;
                b.localPos += -rotv3;


                break;

            case GtoolPathConfig.AsPrevious:
                a.localPos += vector;
                b.localPos += vector;
                break;
            }

            PrevDirection = vector;

            selectedLine = new LineData(headTris, aUV, bUV);

            mm.edMesh.Dirty = true;
        }