public void EditMesh(PlaytimePainter painter, bool editCopy) { if (!painter || painter == target) { return; } if (target) { DisconnectMesh(); } target = painter; targetTransform = painter.transform; editedMesh = new EditableMesh(painter); if (editCopy) { painter.SharedMesh = new Mesh(); } Redraw(); InitVerticesIfNull(); UndoMoves.Clear(); RedoMoves.Clear(); UndoMoves.Add(editedMesh.Encode().ToString()); MeshTool.OnSelectTool(); }
public void Redraw() { previewEdMesh = null; if (target) { editedMesh.Dirty = false; var mc = new MeshConstructor(editedMesh, target.MeshProfile, target.SharedMesh); if (!editedMesh.dirtyVertexIndexes && EditedMesh.Dirty) { if (EditedMesh.dirtyPosition) { mc.UpdateMesh <VertexDataTypes.VertexPos>(); } if (editedMesh.dirtyColor) { mc.UpdateMesh <VertexDataTypes.VertexColor>(); } if (editedMesh.dirtyUvs) { mc.UpdateMesh <VertexDataTypes.VertexUv>(); } } else { var m = mc.Construct(); target.SharedMesh = m; target.UpdateMeshCollider(m); } } }
public void MergeWith(EditableMesh edm, PlaytimePainter other) { if (uv2DistributeRow > 1) { var tile = Vector2.one / uv2DistributeRow; var y = uv2DistributeCurrent / uv2DistributeRow; var x = uv2DistributeCurrent - y * uv2DistributeRow; var offset = tile; offset.Scale(new Vector2(x, y)); edm.TileAndOffsetUVs(offset, tile, 1); uv2DistributeCurrent++; } triangles.AddRange(edm.triangles); var tf = other.transform; int groupOffset = maxGroupIndex + 1; foreach (var point in edm.meshPoints) { foreach (var vertex in point.vertices) { vertex.groupIndex += groupOffset; maxGroupIndex = Mathf.Max(maxGroupIndex, vertex.groupIndex); } point.WorldPos = tf.TransformPoint(point.localPos); meshPoints.Add(point); } }
public override void Decode(string data) { decodedEditableMesh = this; base.Decode(data); decodedEditableMesh = null; }
public MeshConstructor(EditableMesh edMesh, MeshPackagingProfile solution, Mesh freshMesh) { profile = solution; this.edMesh = edMesh; mesh = freshMesh; if (!mesh) { mesh = new Mesh(); } }
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; }
private static void MergeSelected() { var mats = target.Materials.ToList(); foreach (var p in SelectedForMergePainters) { if (target != p) { var nms = p.Materials; var em = new EditableMesh(p); for (var i = 0; i < nms.Length; i++) { var nm = nms[i]; if (!nm || !mats.Contains(nm)) { em.ChangeSubMeshIndex(i, mats.Count); mats.Add(nm); } else { var ind = mats.IndexOf(nm); em.ChangeSubMeshIndex(i, ind); } } em.AfterRemappingTriangleSubMeshIndexes(); editedMesh.MergeWith(em, p); p.gameObject.SetActive(false); } } editedMesh.Dirty = true; editedMesh.subMeshCount = mats.Count; SelectedForMergePainters.Clear(); target.Materials = mats.ToArray(); }
public void MergeWithNearest(EditableMesh edMesh) { var allVertices = edMesh.meshPoints; MeshPoint nearest = null; var maxDist = float.MaxValue; foreach (var v in allVertices) { var dist = v.DistanceTo(this); if (!(dist < maxDist) || v == this) { continue; } maxDist = dist; nearest = v; } if (nearest != null) { edMesh.Merge(this, nearest); } }
public void MergeWith(EditableMesh edm, PlaytimePainter other) { if (uv2DistributeRow > 1) { var tile = Vector2.one / uv2DistributeRow; var y = uv2DistributeCurrent / uv2DistributeRow; var x = uv2DistributeCurrent - y * uv2DistributeRow; var offset = tile; offset.Scale(new Vector2(x, y)); edm.TileAndOffsetUVs(offset, tile, 1); uv2DistributeCurrent++; } triangles.AddRange(edm.triangles); var tf = other.transform; foreach (var v in edm.meshPoints) { v.WorldPos = tf.TransformPoint(v.localPos); meshPoints.Add(v); } }