public static void Octahedron(MeshTool geometry, float radius)
    {
        Array.Copy(octahedronIndices, geometry.indices, octahedronIndices.Length);

        for (int i = 0; i < octahedronVertices.Length; ++i)
        {
            geometry.positions[i] = octahedronVertices[i] * radius;
            geometry.normals[i]   = octahedronVertices[i];
        }

        geometry.ActiveVertices = octahedronVertices.Length;
        geometry.ActiveIndices  = octahedronIndices.Length;
    }
示例#2
0
 public void DisconnectMesh()
 {
     if (target != null)
     {
         MeshTool.OnDeSelectTool();
         target.SavedEditableMesh = edMesh.Encode().ToString();
         target = null;
     }
     Grid.Deactivateverts();
     GridNavigator.Inst().SetEnabled(false, false);
     undoMoves.Clear();
     redoMoves.Clear();
 }
示例#3
0
        public static void CombineDagsWithSameMat(MSelectionList list)
        {
            if (list == null)
            {
                Debug.Log("list null");
                return;
            }
            List <List <string> >   matClusterList = new List <List <string> >();
            List <List <MDagPath> > dagClusterList = new List <List <MDagPath> >();

            //Dictionary<List<string>, List<MDagPath>> matDic = new Dictionary<List<MFnDependencyNode>, List<MDagPath>>();
            foreach (MDagPath dag in list.DagPaths())
            {
                ShapeData sd    = GetMaterialsOfDag(dag);
                bool      exist = false;
                for (int i = 0; i < matClusterList.Count; i++)
                {
                    if (BasicFunc.IsSame(sd.sgList, matClusterList[i]))
                    {
                        exist = true;
                        dagClusterList[i].Add(dag);
                    }
                }
                if (!exist)
                {
                    matClusterList.Add(sd.sgList);
                    List <MDagPath> newDagList = new List <MDagPath>();
                    newDagList.Add(dag);
                    dagClusterList.Add(newDagList);
                }
            }
            for (int i = 0; i < matClusterList.Count; i++)
            {
                string matStr = "combined_";
                for (int j = 0; j < matClusterList[i].Count; j++)
                {
                    matStr += matClusterList[i][j] + "_";
                }
                Debug.Log(matStr);
                matStr.Replace(':', '_');
                Debug.Log("after deal:" + matStr);
                MeshTool.CombineMeshesUsingMEL(dagClusterList[i], matStr);

                //matStr += ":";
                //for (int j = 0; j < dagClusterList[i].Count; j++)
                //{
                //    matStr += "," + dagClusterList[i][j].fullPathName;
                //}
                //Debug.Log(matStr);
            }
        }
示例#4
0
 public void StopEditingMesh()
 {
     if (target)
     {
         MeshTool.OnDeSelectTool();
         target.SavedEditableMesh = new CfgData(editedMesh.Encode().ToString());
         target          = null;
         targetTransform = null;
     }
     Grid.DeactivateVertices();
     GridNavigator.Inst().SetEnabled(false, false);
     UndoMoves.Clear();
     RedoMoves.Clear();
 }
    public static void CullSphereToHemisphere(MeshTool geometry)
    {
        int lastTri = geometry.indices.Length / 3 - 1;
        var vertUse = new byte[geometry.VertexCount];

        for (int i = 0; i <= lastTri; ++i)
        {
            var triangle = geometry.GetTriangle(i);

            Vector3 a = geometry.positions[triangle.x];
            Vector3 b = geometry.positions[triangle.y];
            Vector3 c = geometry.positions[triangle.z];

            if (Vector3.Cross(b - a, c - a).y < 0)
            {
                geometry.SwapTriangle(i, lastTri);
                lastTri -= 1;
                i       -= 1;
            }
            else
            {
                vertUse[triangle.x] += 1;
                vertUse[triangle.y] += 1;
                vertUse[triangle.z] += 1;
            }
        }

        int lastVert = geometry.VertexCount - 1;

        for (int i = 0; i <= lastVert; ++i)
        {
            if (vertUse[i] == 0)
            {
                geometry.SwapVertex(i, lastVert, indices: true);
                Swap(ref vertUse[i], ref vertUse[lastVert]);
                lastVert -= 1;
                i        -= 1;
            }
        }

        geometry.SetVertexCount(lastVert + 1);
        geometry.SetIndexCount((lastTri + 1) * 3, preserve: true, lazy: false);

        geometry.mesh.Clear();
        geometry.Apply(positions: true, normals: true, indices: true);
    }
示例#6
0
        public void EditMesh(PlaytimePainter pntr, bool EditCopy)
        {
            if ((pntr == null) || (pntr == target))
            {
                return;
            }

            if (target != null)
            {
                DisconnectMesh();
            }

            target = pntr;

            edMesh = new EditableMesh();

            edMesh.Edit(pntr);

            if (EditCopy)
            {
                pntr.meshFilter.sharedMesh = new Mesh();
            }

            Redraw();

            pntr.meshNameHolder = edMesh.meshName;

            InitVertsIfNUll();

            SelectedLine = null;
            SelectedTris = null;
            SelectedUV   = null;

            undoMoves.Clear();
            redoMoves.Clear();

            undoMoves.Add(edMesh.Encode().ToString());

            MeshTool.OnSelectTool();
        }
示例#7
0
    protected virtual void OnSceneGUI()
    {
        Handles.BeginGUI();
        {
            toolMode = (ToolMode)GUI.Toolbar(new Rect(10, 10, 200, 20), (int)toolMode, new[] { "Mesh", "Data" });

            // meshTool
            if (toolMode == ToolMode.Mesh)
            {
                meshTool = (MeshTool)GUI.Toolbar(new Rect(10, 35, 200, 20), (int)meshTool, new[] { "Build", "Paint" });
                //if (meshTool == MeshTool.Painting)
                //    selected = null;

                //// tileset
                //if (meshTool == MeshTool.Painting)
                //    GUI.Window(0, new Rect(10, 80, 200, 300), PaintingWindow, "Tiles");
            }
            else
            if (toolMode == ToolMode.Stage)
            {
                stageTool = (StageTool)GUI.Toolbar(new Rect(10, 35, 200, 20), (int)stageTool, new[] { "Data", "Gimick", "Back" });

                //// Data
                //if (stageTool == StageTool.Data)
                //    GUI.Window(0, new Rect(10, 80, 200, 300), DataWindow, "Data");

                //// Gimick
                //if (stageTool == StageTool.Gimick)
                //    GUI.Window(0, new Rect(10, 80, 200, 300), GimickWindow, "Gimick");

                //// Back
                //if (stageTool == StageTool.BackPoint)
                //    GUI.Window(0, new Rect(10, 80, 200, 300), BackWindow, "BackPoint");
            }
        }
        Handles.EndGUI();
    }
    public static void HemisphereOld(MeshTool geometry,
                                     float radius,
                                     int complexity,
                                     bool correction)
    {
        int subdivisions = complexity / 6;
        int sides        = (complexity % 6) + 3;

        if (correction)
        {
            // try to make the average of apoth/radius = desired radius
            // * desired = (radius + apoth) / 2
            // apoth = radius * cos(pi / sides)
            // * desired = (radius + radius * cos(pi / sides)) / 2
            // * desired = radius * (1 + cos(pi / sides)) / 2
            // rearrange to determine radius from desired radius
            // * radius = desired / ((1 + cos(pi / sides)) / 2)

            radius = radius * 2 / (1 + Mathf.Cos(Mathf.PI / (sides * (subdivisions + 1))));
        }

        // pyramid
        int vertCount = sides + 1;
        int faceCount = sides;
        int edgeCount = sides * 2;

        for (int i = 0; i < subdivisions; ++i)
        {
            vertCount += edgeCount;
            edgeCount += faceCount * 6;
            faceCount *= 4;
        }

        geometry.SetVertexCount(vertCount);
        geometry.SetIndexCount(faceCount * 3, lazy: true);

        geometry.ActiveVertices = sides + 1;
        geometry.ActiveIndices  = sides * 3;

        geometry.positions[0] = new Vector3(0, radius, 0);
        geometry.normals[0]   = new Vector3(0, 1, 0);

        float da = Mathf.PI * 2 / sides;

        for (int i = 1; i < vertCount; ++i)
        {
            var normal = new Vector3(Mathf.Cos(da * i), 0, Mathf.Sin(da * i));

            geometry.positions[i] = FasterMath.Mul(normal, radius);
            geometry.normals[i]   = normal;
        }

        for (int i = 1; i < sides; ++i)
        {
            geometry.SetTriangle(i, 0, i + 1, i);
        }

        geometry.SetTriangle(0, 0, 1, sides);

        int prevTriCount = geometry.ActiveIndices / 3;
        int nextTriCount = 0;

        var edges = new Dictionary <int, ushort>(prevTriCount * 6);

        for (int i = 0; i < subdivisions; i++)
        {
            nextTriCount = prevTriCount * 4;

            for (int j = 0; j < prevTriCount; ++j)
            {
                var tri = geometry.GetTriangle(j);

                int a = GetMiddlePoint((ushort)tri.x, (ushort)tri.y, geometry, radius, edges);
                int b = GetMiddlePoint((ushort)tri.y, (ushort)tri.z, geometry, radius, edges);
                int c = GetMiddlePoint((ushort)tri.z, (ushort)tri.x, geometry, radius, edges);

                geometry.SetTriangle(prevTriCount + j * 3 + 0, tri.x, a, c);
                geometry.SetTriangle(prevTriCount + j * 3 + 1, tri.y, b, a);
                geometry.SetTriangle(prevTriCount + j * 3 + 2, tri.z, c, b);
                geometry.SetTriangle(j, a, b, c);
            }

            prevTriCount = nextTriCount;
            edges.Clear();
        }

        geometry.mesh.Clear();
        geometry.Apply(positions: true, normals: true, indices: true);
    }
示例#9
0
    // Update is called once per frame
    public void EditorUpdate(Camera cam)
    {
        //Event e = Event.current;
        //if (e.type == EventType.MouseDown) {
        //    mouseDownPos = e.mousePosition;
        //    if (e.button == 0) {
        //        if (curOperator == Operator.AddBlock) {
        //            if (bShowPreview) {
        //                int gx = (int)previewBlockPos.x;
        //                int gy = (int)previewBlockPos.y;
        //                int gz = (int)previewBlockPos.z;
        //                blockManager.setBlock(gx, gy, gz, (short)BlockTypeEnum.BT_Sand);
        //                bDirty = true;
        //            }
        //        }
        //        if (curOperator == Operator.DeleteBlock) {
        //            if (bShowPreview) {
        //                int gx = (int)selectedBlockPos.x;
        //                int gy = (int)selectedBlockPos.y;
        //                int gz = (int)selectedBlockPos.z;
        //                blockManager.setBlock(gx, gy, gz, (short)BlockTypeEnum.BT_Air);
        //                bDirty = true;
        //            }
        //        }
        //    }
        //}
        //else if (e.type == EventType.mouseMove) {
        //    if (curOperator == Operator.AddBlock || curOperator == Operator.DeleteBlock) {
        //        Ray ray = cam.ScreenPointToRay(new Vector3(e.mousePosition.x, cam.pixelHeight - e.mousePosition.y, 0));
        //        Vector3 startPos = transform.InverseTransformPoint(ray.origin);
        //        Vector3 dir = transform.InverseTransformDirection(ray.direction);
        //        RayCastRestult rlt = rtm.rayCast(startPos, dir, 50);
        //        bShowPreview = rlt.bHit;
        //        if (rlt.bHit) {
        //            //Debug.Log(rlt.hitFaceIndex.ToString());
        //            if (curOperator == Operator.AddBlock) {
        //                Vector3 hitPos = startPos + dir * (rlt.hitLength + 0.001f);
        //                float gx = (int)(hitPos.x / Const.BlockSize) + 0.5f;
        //                float gy = (int)(hitPos.y / Const.BlockSize) + 0.5f;
        //                float gz = (int)(hitPos.z / Const.BlockSize) + 0.5f;
        //                selectedBlockPos = new Vector3(gx, gy, gz);
        //                previewBlockPos = new Vector3(gx, gy, gz) + Const.getFaceNormal(rlt.hitFaceIndex) * Const.BlockSize;
        //            }
        //            else if (curOperator == Operator.DeleteBlock) {
        //                Vector3 hitPos = startPos + dir * (rlt.hitLength + 0.001f);
        //                float gx = (int)(hitPos.x / Const.BlockSize) + 0.5f;
        //                float gy = (int)(hitPos.y / Const.BlockSize) + 0.5f;
        //                float gz = (int)(hitPos.z / Const.BlockSize) + 0.5f;
        //                selectedBlockPos = new Vector3(gx, gy, gz);
        //            }
        //        }
        //    }
        //}

        if (bDirty)
        {
            bDirty = false;
            DebugTool.Log("开始更新光线追踪");
            rtm.clearAll();
            blockManager.forEachBlock((short block, int gx, int gy, int gz) => {
                if (block != (short)BlockTypeEnum.Air)
                {
                    rtm.setBlock(gx, gy, gz, RayCastBlockType.All);
                }
            });

            //初始化AO计算
            RayMarchingAo rma = new RayMarchingAo();
            rma.Init(rtm);

            m_meshes.Clear();
            DebugTool.Log("开始计算光照");
            TerrainTool.calcLight2(blockManager, 32);
            DebugTool.Log("开始更新网格");

            BlockTypeFun blockTypeFun = new BlockTypeFun();

            for (int i = 0; i < SpaceX; i++)
            {
                for (int k = 0; k < SpaceZ; k++)
                {
                    for (int j = 0; j < SpaceY; j++)
                    {
                        BlockChunk chunk = new BlockChunk(blockManager, i * Const.ChunkSize, j * Const.ChunkSize, k * Const.ChunkSize);
                        for (int f = 0; f < 6; f++)
                        {
                            List <MeshTool.BlockSurface> surface = MeshTool.getChunkSurface(chunk, blockTypeFun, f);
                            Texture2D texSurface = MeshTool.SurfacePointsToTexture(surface, f);

                            RenderTexture targetAoResult = rma.RenderByCalcShader(texSurface, new Vector3(i, j, k) * Const.ChunkSize, f);
                            //回读亮度数据
                            RenderTexture.active = targetAoResult;
                            Texture2D readback = new Texture2D(targetAoResult.width, targetAoResult.height);
                            readback.ReadPixels(new Rect(0, 0, targetAoResult.width, targetAoResult.width), 0, 0);
                            MeshTool.SetRaytraceAo(surface, readback);
                            Mesh mesh = MeshTool.createMesh2(surface, f, blockTypeFun);
                            if (mesh)
                            {
                                Vector3 pos = ((new Vector3(i, j, k))) * Const.ChunkSize;
                                m_meshes.Add(new MeshInfo(mesh, pos));
                            }
                        }
                    }
                }
            }
            DebugTool.Log("结束");
        }
    }
示例#10
0
    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("拆分"))
        {
            MeshTool meshTool = target as MeshTool;
            m_Mesh = meshTool.GetComponent <MeshFilter>().sharedMesh;
            Mesh rMesh = CutMesh1(m_Mesh, (color) => {
                if (color.r >= color.b && color.r >= color.g && color.r >= color.a)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            Mesh gMesh = CutMesh1(m_Mesh, (color) => {
                if (color.g >= color.r && color.g >= color.b && color.g >= color.a)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            Mesh bMesh = CutMesh1(m_Mesh, (color) => {
                if (color.b >= color.r && color.b >= color.g && color.b >= color.a)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            Mesh aMesh = CutMesh1(m_Mesh, (color) => {
                if (color.a >= color.r && color.a >= color.g && color.a >= color.b)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });


            //AssetDatabase.CreateAsset(redMesh, "Assets/newmesh1.mesh");
        }

        if (GUILayout.Button("设置顶点色"))
        {
            MeshTool meshTool = target as MeshTool;
            m_Mesh = meshTool.GetComponent <MeshFilter>().sharedMesh;
            List <Vector3> vector3s = new List <Vector3>();
            Mesh           newMesh  = Object.Instantiate(m_Mesh);
            newMesh.GetVertices(vector3s);
            List <Color> colors = new List <Color>();
            vector3s.ForEach((item) => {
                Color color = Color.white;
                if (item.y > 0)
                {
                    color = Color.red;
                }
                else
                {
                    color = Color.blue;
                }
                colors.Add(color);
            }
                             );
            newMesh.SetColors(colors);
            AssetDatabase.CreateAsset(newMesh, "Assets/newmesh.mesh");
        }
    }
示例#11
0
    private void OnPlaneGenerationGUI()
    {
        planeGenerationData = planeGenerationData ?? new PlaneGenerationData();

        planeGenerationData.direction = (PlaneGenerationData.Direction)UG.EnumPopup("平面方向", planeGenerationData.direction);

        UG.BeginHorizontal();

        planeGenerationData.length = UG.DelayedFloatField("长", planeGenerationData.length);
        planeGenerationData.width  = UG.DelayedFloatField("宽", planeGenerationData.width);

        UG.EndHorizontal();

        UG.BeginHorizontal();

        planeGenerationData.verticesPerLength = UG.DelayedIntField("长顶点数", planeGenerationData.verticesPerLength);
        planeGenerationData.verticesPerWidth  = UG.DelayedIntField("宽顶点数", planeGenerationData.verticesPerWidth);

        UG.EndHorizontal();

        bool   legal        = true;
        string errorMessage = String.Empty;

        if (defaultMaterial == null)
        {
            legal         = false;
            errorMessage += "默认材质不能为空";
        }

        if (planeGenerationData.length <= 0)
        {
            legal         = false;
            errorMessage += "平面长必须大于0\n";
        }

        if (planeGenerationData.width <= 0)
        {
            legal         = false;
            errorMessage += "平面宽必须大于0\n";
        }

        if (planeGenerationData.verticesPerLength <= 0)
        {
            legal         = false;
            errorMessage += "平面长顶点数必须大于0\n";
        }

        if (planeGenerationData.verticesPerWidth <= 0)
        {
            legal         = false;
            errorMessage += "平面宽顶点数必须大于0\n";
        }

        if (legal)
        {
            if (GUILayout.Button("生成"))
            {
                MeshTool.InstantiatePlane(planeGenerationData, defaultMaterial);
            }
        }
        else
        {
            UG.HelpBox(errorMessage, MessageType.Error);
        }
    }
示例#12
0
        void SORT_AND_UPDATE_UI()
        {
            if (Grid == null)
            {
                return;
            }

            if (Grid.verts[0].go == null)
            {
                InitVertsIfNUll();
            }

            // if (_meshTool == MeshTool.vertices)
            //   DrowLinesAroundTargetPiece();

            UpdateLocalSpaceV3s();

            edMesh.SortAround(collisionPosLocal, false);

            float scaling = 16;

            Grid.selectedVertex.go.SetActiveTo(false);
            Grid.pointedVertex.go.SetActiveTo(false);

            for (int i = 0; i < vertsShowMax; i++)
            {
                Grid.verts[i].go.SetActiveTo(false);
            }

            if (MeshTool.ShowVertices)
            {
                for (int i = 0; i < vertsShowMax; i++)
                {
                    if (edMesh.meshPoints.Count > i)
                    {
                        MarkerWithText mrkr   = Grid.verts[i];
                        MeshPoint      vpoint = edMesh.meshPoints[i];

                        Vector3 worldPos = vpoint.WorldPos;
                        float   tmpScale;
                        tmpScale = Vector3.Distance(worldPos,
                                                    Transform.gameObject.TryGetCameraTransform().position) / scaling;

                        if (GetPointedVert() == vpoint)
                        {
                            mrkr = Grid.pointedVertex; tmpScale *= 2;
                        }
                        else if (GetSelectedVert() == edMesh.meshPoints[i])
                        {
                            mrkr      = Grid.selectedVertex;
                            tmpScale *= 1.5f;
                        }

                        mrkr.go.SetActiveTo(true);
                        mrkr.go.transform.position   = worldPos;
                        mrkr.go.transform.rotation   = Transform.gameObject.TryGetCameraTransform().rotation;
                        mrkr.go.transform.localScale = new Vector3((IsInTrisSet(vpoint) ? 1.5f : 1) * tmpScale, tmpScale, tmpScale);

                        Ray        tmpRay = new Ray();
                        RaycastHit hit;
                        tmpRay.origin    = Transform.gameObject.TryGetCameraTransform().position;
                        tmpRay.direction = mrkr.go.transform.position - tmpRay.origin;

                        if ((Physics.Raycast(tmpRay, out hit, 1000)) && (!PlaytimeToolComponent.MeshEditorIgnore.Contains(hit.transform.tag)))
                        {
                            mrkr.go.SetActiveTo(false);
                        }

                        if (SameTrisAsPointed(vpoint))
                        {
                            mrkr.textm.color = Color.white;
                        }
                        else
                        {
                            mrkr.textm.color = Color.gray;
                        }


                        MeshTool.AssignText(mrkr, vpoint);
                    }
                }
            }
        }
示例#13
0
        void RAYCAST_SELECT_MOUSEedit()
        {
            PointedTris = null;
            PointedLine = null;

            bool pointingUV = Raycast_VertexIsPointed();

            if (_dragging)
            {
                MeshTool.ManageDragging();
            }

            if (!_dragging)
            {
                if ((pointingUV) && (currentUV <= edMesh.meshPoints[0].uvpoints.Count))
                {
                    var pointedVX = edMesh.meshPoints[0];

                    if (currentUV == pointedVX.uvpoints.Count)
                    {
                        currentUV--;
                    }

                    if ((SelectedUV != null) && (SelectedUV.meshPoint == pointedVX) && (!SelectingUVbyNumber))
                    {
                        PointedUV = SelectedUV;
                    }
                    else
                    {
                        PointedUV = pointedVX.uvpoints[currentUV];
                    }

                    if (EditorInputManager.GetMouseButtonDown(0))
                    {
                        AssignSelected(PointedUV);
                    }
                }

                MeshToolBase t = MeshTool;

                if ((t.ShowVertices) && (PointedUV != null))
                {
                    if (t.MouseEventPointedVertex())
                    {
                        EditedMesh.SetLastPointed(PointedUV);
                    }
                    else
                    {
                        EditedMesh.ClearLastPointed();
                    }
                }
                else if ((t.ShowLines) && (PointedLine != null))
                {
                    if (t.MouseEventPointedLine())
                    {
                        EditedMesh.SetLastPointed(PointedLine);
                    }
                    else
                    {
                        EditedMesh.ClearLastPointed();
                    }
                }
                else if ((t.ShowTriangles) && (PointedTris != null))
                {
                    if (t.MouseEventPointedTriangle())
                    {
                        EditedMesh.SetLastPointed(PointedTris);
                    }
                    else
                    {
                        EditedMesh.ClearLastPointed();
                    }
                }
                else
                {
                    t.MouseEventPointedNothing();
                    EditedMesh.ClearLastPointed();
                }
            }
        }
示例#14
0
        public bool PEGI()
        {
            bool changed = false;

            EditableMesh.inspected = edMesh;

            pegi.newLine();

            if (edMesh != null)
            {
                if ("Mesh ".foldout(ref inspectMesh).nl())
                {
                    changed |= edMesh.Nested_Inspect().nl();
                }
            }
            pegi.Space();

            pegi.newLine();

            changed |= target.PreviewShaderToggle_PEGI();

            if ((!target.IsOriginalShader) && ("preview".select(45, ref meshSHaderMode.selected, meshSHaderMode.allModes).nl()))
            {
                meshSHaderMode.selected.Apply();
            }

            pegi.Space();

            pegi.newLine();

            var previousTool = MeshTool;

            if ("tool".select(70, ref Cfg._meshTool, MeshToolBase.AllTools).nl())
            {
                Grid.vertexPointMaterial.SetColor("_Color", MeshTool.VertColor);
                previousTool.OnDeSelectTool();
                MeshTool.OnSelectTool();
            }

            pegi.Space();

            pegi.newLine();

            "Mesh Name:".edit(70, ref target.meshNameHolder);

#if UNITY_EDITOR
            if (((AssetDatabase.GetAssetPath(target.GetMesh()).Length == 0) || (String.Compare(target.meshNameHolder, target.GetMesh().name) != 0)) &&
                (icon.Save.Click("Save Mesh As {0}".F(target.GenerateMeshSavePath()), 25).nl()))
            {
                target.SaveMesh();
            }
#endif

            pegi.newLine();

            pegi.nl();

            MeshTool.PEGI();

            pegi.newLine();

            if ("Hint".foldout(ref showTooltip).nl())
            {
                pegi.writeHint(MeshTool.Tooltip);
            }

            if ("Merge Meshes".foldout(ref showCopyOptions).nl())
            {
                if (!selectedPainters.Contains(target))
                {
                    if ("Copy Mesh".Click("Add Mesh to the list of meshes to be merged").nl())
                    {
                        selectedPainters.Add(target);
                    }

                    if (selectedPainters.Count > 0)
                    {
                        if (edMesh.UV2distributeRow < 2 && "Enable EV2 Distribution".toggleInt("Each mesh's UV2 will be modified to use a unique portion of a texture.", ref edMesh.UV2distributeRow).nl())
                        {
                            edMesh.UV2distributeRow = Mathf.Max(2, (int)Mathf.Sqrt(selectedPainters.Count));
                        }
                        else
                        {
                            if (edMesh.UV2distributeCurrent > 0)
                            {
                                ("All added meshes will be distributed in " + edMesh.UV2distributeRow + " by " + edMesh.UV2distributeRow + " grid. By cancelling this added" +
                                 "meshes will have UVs unchanged and may use the same portion of Texture (sampled with UV2) as other meshes.").writeHint();
                                if ("Cancel Distribution".Click().nl())
                                {
                                    edMesh.UV2distributeRow = 0;
                                }
                            }
                            else
                            {
                                "Row:".edit("Will change UV2 so that every mesh will have it's own portion of a texture.", 25, ref edMesh.UV2distributeRow, 2, 16).nl();
                                "Start from".edit(ref edMesh.UV2distributeCurrent).nl();
                            }
                            pegi.write("Using " + (edMesh.UV2distributeCurrent + selectedPainters.Count + 1) + " out of " + (edMesh.UV2distributeRow * edMesh.UV2distributeRow).ToString() + " spots");
                            pegi.newLine();
                        }

                        "Will Merge with the following:".nl();
                        for (int i = 0; i < selectedPainters.Count; i++)
                        {
                            if (selectedPainters[i] == null)
                            {
                                selectedPainters.RemoveAt(i);
                                i--;
                            }
                            else
                            {
                                if (icon.Delete.Click(25))
                                {
                                    selectedPainters.RemoveAt(i);
                                    i--;
                                }
                                else
                                {
                                    selectedPainters[i].gameObject.name.nl();
                                }
                            }
                        }

                        if ("Merge!".Click().nl())
                        {
                            foreach (var p in selectedPainters)
                            {
                                edMesh.MergeWith(p);
                            }

                            edMesh.Dirty = true;
                        }
                    }
                }
                else
                {
                    if ("Remove from Copy Selection".Click().nl())
                    {
                        selectedPainters.Remove(target);
                    }
                }
            }



            pegi.newLine();

            Grid.vertexPointMaterial.SetColor("_Color", MeshTool.VertColor);

            if ((!Application.isPlaying) && ("references".foldout(ref showReferences).nl()))
            {
                "vertexPointMaterial".write(Grid.vertexPointMaterial);
                pegi.newLine();

                "vertexPrefab".edit(ref Grid.vertPrefab).nl();
                "Max Vert Markers ".edit(ref vertsShowMax).nl();
                "pointedVertex".edit(ref Grid.pointedVertex.go).nl();
                "SelectedVertex".edit(ref Grid.selectedVertex.go).nl();
            }

            EditableMesh.inspected = null;

            return(changed);
        }
示例#15
0
    public void Update()
    {
        if (bDirty)
        {
            bDirty = false;
            bNeedReselectPreview = true;
            DebugTool.Log("开始更新射线模块");
            rtm.clearAll();
            blockManager.forEachBlock((short block, int gx, int gy, int gz) => {
                if (block != (short)BlockTypeEnum.Air)
                {
                    rtm.setBlock(gx, gy, gz, RayCastBlockType.All);
                }
            });

            //初始化AO计算
            RayMarchingAo rma = new RayMarchingAo();
            rma.Init(rtm);

            foreach (var obj in objects)
            {
                GameObject.Destroy(obj);
            }
            objects.Clear();

            //m_meshes.Clear();
            DebugTool.Log("开始计算光照");
            {
                //计算光照
                Vector3 sunDir = new Vector3(1, -3, 1);
                sunDir.Normalize();
                TerrainTool.calcLight(blockManager, rtm, rays, sunDir);
            }

            BlockTypeFun blockTypeFun = new BlockTypeFun();

            //TerrainTool.calcLight2(blockManager, 16);
            DebugTool.Log("开始更新网格");
            for (int i = 0; i < SpaceX; i++)
            {
                for (int k = 0; k < SpaceZ; k++)
                {
                    for (int j = 0; j < SpaceY; j++)
                    {
                        BlockChunk chunk = new BlockChunk(blockManager, i * Const.ChunkSize, j * Const.ChunkSize, k * Const.ChunkSize);
                        for (int f = 0; f < 6; f++)
                        {
                            List <MeshTool.BlockSurface> surface = MeshTool.getChunkSurface(chunk, blockTypeFun, f);
                            Texture2D texSurface = MeshTool.SurfacePointsToTexture(surface, f);

                            Texture2D readback = null;
                            if (surface.Count > 0)
                            {
                                RenderTexture targetAoResult = rma.RenderByCalcShader(texSurface, new Vector3(i, j, k) * Const.ChunkSize, f);
                                //回读亮度数据
                                RenderTexture.active = targetAoResult;
                                readback             = new Texture2D(targetAoResult.width, targetAoResult.height);
                                readback.ReadPixels(new Rect(0, 0, targetAoResult.width, targetAoResult.width), 0, 0);
                                MeshTool.SetRaytraceAo(surface, readback);
                            }

                            Mesh mesh = MeshTool.createMesh2(surface, f, blockTypeFun);
                            if (mesh)
                            {
                                Vector3 pos = ((new Vector3(i, j, k))) * Const.ChunkSize - halfSpaceSize;
                                if (mesh != null)
                                {
                                    GameObject obj = new GameObject("Chunk", typeof(MeshRenderer), typeof(MeshFilter));
                                    obj.isStatic = true;
                                    obj.GetComponent <Renderer>().material = GlobalResources.getBlockMaterial();
                                    obj.GetComponent <MeshFilter>().mesh   = mesh;
                                    obj.transform.position = pos;
                                    objects.Add(obj);
                                }
                            }
                        }
                    }
                }
            }
            DebugTool.Log("结束");
        }
    }
示例#16
0
        private void SortAndUpdate()
        {
            if (!Grid)
            {
                return;
            }

            if (!Grid.vertices[0].go)
            {
                InitGridIfNull();
            }

            UpdateLocalSpaceMousePosition();

            editedMesh.SortAround(collisionPosLocal, false);

            const float scaling = 16;

            Grid.selectedVertex.go.SetActive(false);
            Grid.pointedVertex.go.SetActive(false);

            for (var i = 0; i < verticesShowMax; i++)
            {
                Grid.vertices[i].go.SetActive(false);
            }

            if (!MeshTool.ShowVertices)
            {
                return;
            }

            var camTf = CurrentViewTransform();

            for (var i = 0; i < verticesShowMax; i++)
            {
                RaycastHit hit;

                if (editedMesh.meshPoints.Count <= i)
                {
                    continue;
                }

                var mark  = Grid.vertices[i];
                var point = editedMesh.meshPoints[i];

                var worldPos = point.WorldPos;
                var tmpScale = Vector3.Distance(worldPos, camTf.position) / scaling;

                if (point == editedMesh.PointedVertex)
                {
                    mark = Grid.pointedVertex; tmpScale *= 2;
                }
                else if (GetSelectedVertex() == editedMesh.meshPoints[i])
                {
                    mark      = Grid.selectedVertex;
                    tmpScale *= 1.5f;
                }

                var go = mark.go;
                var tf = go.transform;


                go.SetActive(true);
                tf.position   = worldPos;
                tf.rotation   = camTf.rotation;
                tf.localScale = new Vector3((editedMesh.IsInTriangleSet(point) ? 1.5f : 1) * tmpScale, tmpScale, tmpScale);

                var tmpRay = new Ray {
                    origin = camTf.position
                };

                tmpRay.direction = tf.position - tmpRay.origin;

                if (Physics.Raycast(tmpRay, out hit, 1000) && (!meshEditorIgnore.Contains(hit.transform.tag)))
                {
                    mark.go.SetActive(false);
                }

                mark.textm.color = SameTriangleAsPointed(point) ? Color.white : Color.gray;


                MeshTool.AssignText(mark, point);
            }
        }
示例#17
0
文件: main.cs 项目: wachel/block
    IEnumerator InitWorld()
    {
        Block.BlockManager bm = new Block.BlockManager();

        for (int i = 0; i < (int)Game.BlockType.Num; i++)
        {
            for (int f = 0; f < 6; f++)
            {
                Game.BlockType block = (Game.BlockType)i;
                texturePacker.AddTexture(block, f, TextureNameConfig.GetTextureName(block, f));
            }
        }
        texturePacker.Pack();
        packedTexture = texturePacker.GetPackedTexture();

        BlockTypeFun blockTypeFun = new BlockTypeFun();

        blockTypeFun.texturePacker = texturePacker;
        //float startTime = Time.realtimeSinceStartup;
        int WorldSizeX = 8;
        int WorldSizeY = 2;
        int WorldSizeZ = 8;

        //申请内存
        bm.create(WorldSizeX * Const.ChunkSize, WorldSizeY * Const.ChunkSize, WorldSizeZ * Const.ChunkSize, blockTypeFun);

        DebugTool.Log("申请内存");
        yield return(null);

        //
        TerrainTool.createTerrain(bm, WorldSizeX, WorldSizeY, WorldSizeZ);
        DebugTool.Log("创建地形");
        yield return(null);

        TerrainTool.createTree(bm, WorldSizeX, WorldSizeY, WorldSizeZ);
        DebugTool.Log("创建树");
        yield return(null);

        List <HouseItem> houseItems = new List <HouseItem>();

        TerrainTool.createBuildings(bm, ref houseItems);
        DebugTool.Log("创建建筑完成");
        yield return(null);

        //光线追踪初始化
        RayCastManager rtm = new RayCastManager();

        rtm.create(bm.SizeX, bm.SizeY, bm.SizeZ);
        for (int x = 0; x < rtm.getSizeX(); x++)
        {
            for (int z = 0; z < rtm.getSizeZ(); z++)
            {
                for (int y = 0; y < rtm.getSizeY(); y++)
                {
                    short            block = bm.getBlock(x, y, z);
                    RayCastBlockType rlt   = 0;
                    rlt |= blockTypeFun.isCollider(block) ? RayCastBlockType.Collider : RayCastBlockType.Nothing;
                    rlt |= blockTypeFun.isOpacity(block) ? RayCastBlockType.Opacity : RayCastBlockType.Nothing;
                    rtm.setBlock(x, y, z, rlt);
                }
                rtm.updateInSun(x, z);
            }
        }

        //预处理光线
        Vector3[][] rays = new Vector3[6][];
        {
            for (int i = 0; i < 6; i++)
            {
                rays[i] = TerrainTool.getRandomRays(9, i);
            }
        }
        DebugTool.Log("预处理光线追踪完成");
        yield return(null);

        rtm.updateAllLight();
        DebugTool.Log("扩散光照计算完毕");
        yield return(null);

        //int[] lightCount = new int[Const.MaxLightIteration + 1];
        //for (int i = 0; i < WorldSizeX * Const.ChunkSize; i++) {
        //    for (int k = 0; k < WorldSizeZ * Const.ChunkSize; k++) {
        //        for (int j = 0; j < WorldSizeY * Const.ChunkSize; j++) {
        //            lightCount[rtm.getLight(i, j, k)]++;
        //        }
        //    }
        //}
        //for (int i = 0; i < lightCount.Length; i++) {
        //    Debug.Log("light (" + i + ") = " + lightCount[i]);
        //}

        Texture2D lightMap = new Texture2D(256, 256, TextureFormat.RGBAHalf, false);

        Color[] colors = new Color[256 * 256];
        for (int i = 0; i < 256; i++)
        {
            for (int j = 0; j < 256; j++)
            {
                colors[j * 256 + i] = new Color(i / 256.0f, i / 256.0f, i / 256.0f, 1) * 2;
            }
        }
        lightMap.SetPixels(colors);
        lightMap.Apply();


        LightmapData[] lightmaps = new LightmapData[1];
        lightmaps[0]               = new LightmapData();
        lightmaps[0].lightmapFar   = lightMap;
        lightmaps[0].lightmapNear  = lightMap;
        LightmapSettings.lightmaps = lightmaps;

        GameObject itemsRoot = new GameObject("items");

        for (int i = 0; i < houseItems.Count; i++)
        {
            HouseItem  item   = houseItems[i];
            string     path   = HouseItemGenerator.GetItemPrefabPath(item.item);
            GameObject prefab = GlobalResources.loadPrefab(path);
            if (prefab != null)
            {
                GameObject inst = GameObject.Instantiate <GameObject>(prefab);
                inst.name               = houseItems[i].item.ToString();
                inst.transform.parent   = itemsRoot.transform;
                inst.transform.position = houseItems[i].pos + new Vector3(0.5f, 0f, 0.5f);
                MeshRenderer renderer = inst.GetComponentInChildren <MeshRenderer>();
                renderer.lightmapIndex = 0;
                inst.isStatic          = true;
                float light = rtm.getLight(item.pos.x, item.pos.y, item.pos.z) / (float)Const.MaxLightIteration;
                light = Mathf.Lerp(0.0f, 0.6f, light);
                renderer.lightmapScaleOffset = new Vector4(0, 0, light, 0f);
                //MeshFilter meshFilter = inst.GetComponentInChildren<MeshFilter>();
                //Mesh mesh = meshFilter.mesh;
                //Color32[] colors = new Color32[mesh.colors.Length];
                //byte c = (byte)(rtm.getLight(item.pos.x, item.pos.y, item.pos.z) * 255);
                //ArrayTool.SetAll(colors, new Color32(c,c,c,1));
                //mesh.colors32 = colors;
            }
            else
            {
                int a = 0;
            }
        }

        //初始化AO计算
        rma = new RayMarchingAo();
        rma.Init(rtm);

        //ViewVoxel viewVoxel = GameObject.FindObjectOfType<ViewVoxel>();
        //if (viewVoxel) {
        //    Texture3D voxelTex3D = rma.GetVoxelTexture();
        //    //OpenGLLibrary.glEnable(OpenGL.GL_TEXTURE_3D);
        //    //OpenGLLibrary.glBindTexture(OpenGL.GL_TEXTURE_3D, voxelTex3D.GetNativeTexturePtr());
        //    //byte[] data = new byte[voxelTex3D.width * voxelTex3D.height * voxelTex3D.depth * 4];
        //    //for (int i = 0; i < data.Length; i++ ){
        //    //    data[i] = 0x56;
        //    //}
        //    //OpenGL.TexSubImage3D(OpenGL.GL_TEXTURE_3D, 0, 0, 0, 0, 32, 32, 32, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, ref data);
        //    //OpenGL.TextureSubImage3D(voxelTex3D, 0, 0, 0, 0, 1, 1, 1, OpenGL.GL_RED, OpenGL.GL_UNSIGNED_BYTE, ref data);
        //    viewVoxel.SetVexelTex(voxelTex3D);
        //}

        //计算光照
        Vector3 sunDir = new Vector3(1, -3, 1);

        sunDir.Normalize();
        {
            //TerrainTool.calcLight(bm, rtm, rays, sunDir);
            //TerrainTool.calcLight2(bm,32);
        }
        DebugTool.Log("计算光照完成");
        yield return(null);

        Material mat = GlobalResources.getBlockMaterial();

        mat.mainTexture = texturePacker.GetPackedTexture();
        GameObject root = GameObject.Find("Root");

        if (root == null)
        {
            root = new GameObject("Root");
        }

        Level level = GameObject.FindObjectOfType <Level>();

        if (level)
        {
            level.scene = rtm;
        }

        //创建网格
        for (int i = 0; i < WorldSizeX; i++)
        {
            for (int k = 0; k < WorldSizeZ; k++)
            {
                for (int j = 0; j < WorldSizeY; j++)
                {
                    int baseX = i * Const.ChunkSize;
                    int baseY = j * Const.ChunkSize;
                    int baseZ = k * Const.ChunkSize;

                    BlockChunk chunk = new BlockChunk(bm, baseX, baseY, baseZ);

                    Vector3 chunkPos = new Vector3(i * Const.ChunkSize * Const.BlockSize, j * Const.ChunkSize * Const.BlockSize, k * Const.ChunkSize * Const.BlockSize);

                    //bool[,,] visibleBlocks = new bool[Const.ChunkSize,Const.ChunkSize,Const.ChunkSize];// = MeshTool.GetVisibleBlocks(chunk, blockTypeFun);
                    //TerrainTool.calcChunkLight(chunk, i, j, k, rtm, rays, sunDir);
                    //Mesh mesh = MeshTool.createMesh(chunk, blockTypeFun, 0, 0, 0);
                    for (int f = 0; f < 6; f++)
                    {
                        List <MeshTool.BlockSurface> surface = MeshTool.getChunkSurface(chunk, blockTypeFun, f);
                        //for (int s = 0; s < surface.Count; s++) {
                        //    visibleBlocks[surface[s].pos.x, surface[s].pos.y, surface[s].pos.z] = true;
                        //}


                        Texture2D texSurface = MeshTool.SurfacePointsToTexture(surface, f);

                        RenderTexture targetAoResult = rma.RenderByCalcShader(texSurface, new Vector3(i, j, k) * Const.ChunkSize, f);

                        //回读亮度数据
                        RenderTexture.active = targetAoResult;
                        Texture2D readback = new Texture2D(targetAoResult.width, targetAoResult.height);
                        readback.ReadPixels(new Rect(0, 0, targetAoResult.width, targetAoResult.width), 0, 0);
                        MeshTool.SetRaytraceAo(surface, readback);
                        MeshTool.SetExtendAo(surface, rtm, f, new VecInt3(i * Const.ChunkSize, j * Const.ChunkSize, k * Const.ChunkSize));

                        //将可行走区域标记黑色
                        //if (f == (int)BlockFaceIndex.BFI_y1) {
                        //    for (int s = 0; s < surface.Count; s++) {
                        //        int gx = baseX + surface[s].pos.x;
                        //        int gy = baseY + surface[s].pos.y;
                        //        int gz = baseZ + surface[s].pos.z;
                        //        if (rtm.testBlock(gx, gy, gz, (byte)RayTraceBlockType.Walkable)) {
                        //            for (int v = 0; v < 4; v++) {
                        //                surface[s].raytraceAo[v] *= 0.1f;
                        //            }
                        //        }
                        //    }
                        //}

                        Mesh mesh = MeshTool.createMesh2(surface, f, blockTypeFun);

                        if (mesh != null)
                        {
                            GameObject obj = new GameObject("Chunk", typeof(MeshRenderer), typeof(MeshFilter));
                            obj.isStatic = true;
                            obj.GetComponent <Renderer>().material = mat;
                            obj.GetComponent <MeshFilter>().mesh   = mesh;
                            obj.transform.SetParent(root.transform);
                            obj.transform.position = chunkPos;
                        }
                    }

                    //physics.AddChunk(visibleBlocks, chunkPos);
                    yield return(null);
                }
            }
        }
        StaticBatchingUtility.Combine(root);
        StaticBatchingUtility.Combine(itemsRoot);
        DebugTool.Log("生成网格");
        yield return(null);
    }
    public static void Sphere(MeshTool geometry,
                              float radius,
                              int level,
                              bool correction)
    {
        var geodesic = geodesics[Mathf.Min(level, geodesics.Count - 1)];

        geometry.Topology = MeshTopology.Triangles;
        geometry.SetVertexCount(geodesic.VertexCount);
        geometry.SetIndexCount(geodesic.FaceCount * 3, lazy: true);

        if (correction)
        {
            radius *= geodesic.Correction;
        }

        if (geodesic.Base == Solid.Tetrahedron)
        {
            Tetrahedron(geometry, radius);
        }
        if (geodesic.Base == Solid.Octahedron)
        {
            Octahedron(geometry, radius);
        }
        if (geodesic.Base == Solid.Icosohedron)
        {
            Icosohedron(geometry, radius);
        }

        int prevTriCount = geometry.ActiveIndices / 3;
        int nextTriCount = 0;

        // only need as much edge memory as the last iteration, which adds an six
        // edges per triangle of the previous iteration
        int penulTriCount = geodesic.FaceCount / 4;
        var edges         = new Dictionary <int, ushort>(penulTriCount * 6);

        for (int i = 0; i < geodesic.Subdivisions; i++)
        {
            nextTriCount = prevTriCount * 4;

            for (int j = 0; j < prevTriCount; ++j)
            {
                var tri = geometry.GetTriangle(j);

                int a = GetMiddlePoint((ushort)tri.x, (ushort)tri.y, geometry, radius, edges);
                int b = GetMiddlePoint((ushort)tri.y, (ushort)tri.z, geometry, radius, edges);
                int c = GetMiddlePoint((ushort)tri.z, (ushort)tri.x, geometry, radius, edges);

                geometry.SetTriangle(prevTriCount + j * 3 + 0, tri.x, a, c);
                geometry.SetTriangle(prevTriCount + j * 3 + 1, tri.y, b, a);
                geometry.SetTriangle(prevTriCount + j * 3 + 2, tri.z, c, b);
                geometry.SetTriangle(j, a, b, c);
            }

            prevTriCount = nextTriCount;
            edges.Clear();
        }

        geometry.mesh.Clear();
        geometry.Apply(positions: true, normals: true, indices: true);
    }
示例#19
0
    protected virtual void OnSceneGUI()
    {
        // 選択状況の保存データ
        SelectInitialize();

        // overlay gui
        Handles.BeginGUI();
        {
            toolMode = (ToolMode)GUI.Toolbar(new Rect(10, 10, 200, 20), (int)toolMode, new[] { "Move", "Mesh", "Data" });

            // meshTool
            if (toolMode == ToolMode.Mesh)
            {
                meshTool = (MeshTool)GUI.Toolbar(new Rect(10, 35, 200, 20), (int)meshTool, new[] { "Build", "Paint" });
                if (meshTool == MeshTool.Painting)
                {
                    selected = null;
                }

                // tileset
                if (meshTool == MeshTool.Painting)
                {
                    GUI.Window(0, new Rect(10, 80, 200, 300), PaintingWindow, "Tiles");
                }
            }
            else
            if (toolMode == ToolMode.Stage)
            {
                stageTool = (StageTool)GUI.Toolbar(new Rect(10, 35, 200, 20), (int)stageTool, new[] { "Data", "Gimick", "Back" });

                // Data
                if (stageTool == StageTool.Data)
                {
                    GUI.Window(0, new Rect(10, 80, 200, 300), DataWindow, "Data");
                }

                // Gimick
                if (stageTool == StageTool.Gimick)
                {
                    GUI.Window(0, new Rect(10, 80, 200, 300), GimickWindow, "Gimick");
                }

                // Back
                if (stageTool == StageTool.BackPoint)
                {
                    GUI.Window(0, new Rect(10, 80, 200, 300), BackWindow, "BackPoint");
                }
            }
        }
        Handles.EndGUI();

        if (toolMode == ToolMode.Transform)
        {
            TransformMove();
            return;
        }

        DefaultControll();

        if (toolMode == ToolMode.Mesh)
        {   // Mesh作成
            switch (meshTool)
            {
            case MeshTool.Building: MeshToolBuild(); break;

            case MeshTool.Painting: MeshToolPaint(); break;
            }
        }
        else
        if (toolMode == ToolMode.Stage)
        {   // 情報の登録
            //ActiveHover();

            switch (stageTool)
            {
            case StageTool.Data: StageToolData(); break;

            case StageTool.Gimick: StageToolGimick(); break;

            case StageTool.BackPoint: StageToolBackPoint(); break;
            }
        }
        // 描画
        Drawing();

        // 塗りなおし
        if (invokeRepaint)
        {
            Repaint();
        }

        // always keep the tiler selected for now
        // later should detect if something is being grabbed or hovered
        Selection.activeGameObject = tiler.transform.gameObject;
    }
示例#20
0
        private void ProcessMouseActions()
        {
            PointedTriangle = null;
            PointedLine     = null;

            var pointingUv = RayCastVertexIsPointed();

            if (_dragging)
            {
                MeshTool.ManageDragging();
            }

            if (!_dragging)
            {
                if (pointingUv && _currentUv <= editedMesh.meshPoints[0].vertices.Count)
                {
                    var pointedVx = editedMesh.meshPoints[0];

                    if (_currentUv == pointedVx.vertices.Count)
                    {
                        _currentUv--;
                    }

                    if ((SelectedUv != null) && (SelectedUv.meshPoint == pointedVx) && (!_selectingUVbyNumber))
                    {
                        PointedUv = SelectedUv;
                    }
                    else
                    {
                        PointedUv = pointedVx.vertices[_currentUv];
                    }

                    if (EditorInputManager.GetMouseButtonDown(0))
                    {
                        AssignSelected(PointedUv);
                    }
                }

                var t = MeshTool;

                if (t.ShowVertices && PointedUv != null)
                {
                    if (t.MouseEventPointedVertex())
                    {
                        EditedMesh.SetLastPointed(PointedUv);
                    }
                    else
                    {
                        EditedMesh.ClearLastPointed();
                    }
                }
                else if (t.ShowLines && PointedLine != null)
                {
                    if (t.MouseEventPointedLine())
                    {
                        EditedMesh.SetLastPointed(PointedLine);
                    }
                    else
                    {
                        EditedMesh.ClearLastPointed();
                    }
                }
                else if (t.ShowTriangles && PointedTriangle != null)
                {
                    if (t.MouseEventPointedTriangle())
                    {
                        EditedMesh.SetLastPointed(PointedTriangle);
                    }
                    else
                    {
                        EditedMesh.ClearLastPointed();
                    }
                }
                else
                {
                    t.MouseEventPointedNothing();
                    EditedMesh.ClearLastPointed();
                }
            }
        }
示例#21
0
 private void Awake()
 {
     mesh = new Mesh();
     tool = new MeshTool(mesh, MeshTopology.Triangles);
     filter.sharedMesh = mesh;
 }
示例#22
0
        public bool Inspect()
        {
            var changed = false;

            EditableMesh.inspected = editedMesh;

            pegi.nl();

            target.PreviewShaderToggleInspect().changes(ref changed);

            if (!target.NotUsingPreview && "preview".select(45, ref MeshShaderMode.selected, MeshShaderMode.AllModes).nl(ref changed))
            {
                MeshShaderMode.ApplySelected();
            }

            var previousTool = MeshTool;

            if ("tool:".select_Index(35, ref Cfg.meshTool, MeshToolBase.AllTools).changes(ref changed))
            {
                Grid.vertexPointMaterial.SetColor("_Color", MeshTool.VertexColor);
                previousTool.OnDeSelectTool();
                MeshTool.OnSelectTool();
            }


            if (DocsEnabled && pegi.FullWindowService.DocumentationClick("About {0} tool".F(MeshTool.NameForDisplayPEGI())))
            {
                pegi.FullWindowService.DocumentationOpen(MeshTool.Tooltip + (MeshTool.ShowGrid ? GridNavigator.ToolTip : ""));
            }

            if (target.skinnedMeshRenderer)
            {
                pegi.FullWindowService.WarningDocumentationClickOpen
                    ("When using Skinned Mesh Renderer, the mesh will be transformed by it, so mesh points will not be in the correct position, and it is impossible to do any modifications on mesh with the mouse. It is still possible to do automatic processes like " +
                    "changing mesh profile and everything that doesn't require direct input from mouse over the object. It is recommended to edit the object separately from the skinned mesh."
                    , "Skinned mesh detected");
            }

            pegi.nl();



            var mt = MeshTool;

            mt.Inspect().nl(ref changed);

            foreach (var p in CameraModuleBase.MeshToolPlugins)
            {
                p.MeshToolInspection(mt).nl(ref changed);
            }

            pegi.nl();

            Grid.vertexPointMaterial.SetColor("_Color", MeshTool.VertexColor);


            EditableMesh.inspected = null;

            if (changed)
            {
                MeshTool.SetShaderKeywords();
            }

            return(changed);
        }
示例#23
0
 private void ModifyMesh(Vector3 displacement, Vector3 center)
 {
     using (List <MeshFilter> .Enumerator enumerator = this.m_Filters.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             MeshFilter current  = enumerator.Current;
             Mesh       mesh1    = current.get_mesh();
             Vector3[]  vertices = mesh1.get_vertices();
             for (int index = 0; index < vertices.Length; ++index)
             {
                 Vector3 pos = ((Component)current).get_transform().TransformPoint(vertices[index]);
                 vertices[index] = Vector3.op_Addition(vertices[index], Vector3.op_Multiply(displacement, MeshTool.Gaussian(pos, center, this.m_Radius)));
             }
             mesh1.set_vertices(vertices);
             mesh1.RecalculateBounds();
             MeshCollider component = (MeshCollider)((Component)current).GetComponent <MeshCollider>();
             if (Object.op_Inequality((Object)component, (Object)null))
             {
                 Mesh mesh2 = new Mesh();
                 mesh2.set_vertices(mesh1.get_vertices());
                 mesh2.set_triangles(mesh1.get_triangles());
                 component.set_sharedMesh(mesh2);
             }
         }
     }
 }