void Start() { int sizeX = 100, sizeZ = 100; var meshFilter = this.gameObject.AddComponent <MeshFilter>(); var oldMesh = meshFilter.sharedMesh; if (oldMesh) { DestroyImmediate(oldMesh, true); } meshFilter.sharedMesh = EditUtil.CreateGrid(sizeX, sizeZ); var meshRenderer = this.gameObject.AddComponent <MeshRenderer>(); meshRenderer.material = Resources.Load <Material>("Materials/GridMaterial"); meshRenderer.material.color = new Color(0.5f, 0.5f, 0.5f); var collider = this.gameObject.AddComponent <BoxCollider>(); collider.size = new Vector3(sizeX, 0.0f, sizeZ); Vector3 position = new Vector3(50.0f, 0, 50.0f) + new Vector3(-0.5f, -0.25f, -0.5f); this.transform.position = EditManager.Instance.ToWorldCoordinate(position); }
public void SelectRange(Vector3 begin, Vector3 end) { Vector3i bpos = new Vector3i(begin.x, begin.y * 2.0f, begin.z); Vector3i epos = new Vector3i(end.x, end.y * 2.0f, end.z); EditUtil.MinMaxElements(ref bpos, ref epos); for (int z = bpos.z; z <= epos.z; z++) { for (int y = bpos.y; y <= epos.y; y++) { for (int x = bpos.x; x <= epos.x; x++) { Vector3 curpos = new Vector3(x, y * 0.5f, z); if (!this.IsSelected(curpos)) { this.Add(curpos); this.Add(EditManager.Instance.CurrentLayer.GetModel(curpos)); } else { this.Remove(EditManager.Instance.CurrentLayer.GetModel(curpos)); } } } } this.LastPosition = end; }
//TODO: Copied from VsVimHost public FSharpOption <int> GetNewLineIndent(ITextView textView, ITextSnapshotLine contextLine, ITextSnapshotLine newLine, IVimLocalSettings localSettings) { //if (_vimApplicationSettings.UseEditorIndent) //{ var indent = _smartIndentationService.GetDesiredIndentation(textView, newLine); if (indent.HasValue) { return(FSharpOption.Create(indent.Value)); } else { // If the user wanted editor indentation but the editor doesn't support indentation // even though it proffers an indentation service then fall back to what auto // indent would do if it were enabled (don't care if it actually is) // // Several editors like XAML offer the indentation service but don't actually // provide information. User clearly wants indent there since the editor indent // is enabled. Do a best effort and use Vim style indenting return(FSharpOption.Create(EditUtil.GetAutoIndent(contextLine, localSettings.TabStop))); } //} //return FSharpOption<int>.None; }
public void SetPosition(Vector3 position) { this.position = position; this.hashCode = EditUtil.PositionToHashCode(position); if (this.gameObject != null) { this.gameObject.transform.position = this.position + this.shape.offset + this.offset; } }
// 位置指定でブロックの取得 public Block GetBlock(Vector3 position) { int key = EditUtil.PositionToHashCode(position); Block value; if (this.blocks.TryGetValue(key, out value)) { return(value); } return(null); }
// 選択ブロックを移動 public void Move(Vector2 screenDir) { if (!this.HasCapturedBlocks()) { this.CaptureBlocks(CaptureMode.Moving, this.GetSelectedBlocks(), this.GetSelectedModels()); } Vector3 up, right; EditUtil.ScreenDirToWorldDir(out up, out right); this.transform.position = this.transform.position + up * screenDir.y + right * screenDir.x; }
private Texture2D AddTexture(string fileName) { string path = this.TextureDirectory + "/" + fileName; Texture2D texture = EditUtil.LoadTextureFromFile(path); if (texture != null) { texture.name = fileName; this.textureList.Add(texture); } return(texture); }
public Model GetModel(Vector3 position) { int hash = EditUtil.PositionToHashCode(position); for (int i = 0; i < this.models.Count; i++) { if (hash == this.models[i].GetHashCode()) { return(this.models[i]); } } return(null); }
void Awake() { var guideObj = new GameObject(); guideObj.name = "Guide"; guideObj.transform.parent = this.transform; this.guide = guideObj.AddComponent <Guide>(); this.guide.SetColor(new Color(0.5f, 0.5f, 1.0f), new Color(1.0f, 1.0f, 1.0f)); this.panelSurfaceMesh = EditUtil.CreatePanelSurfaceMesh(); this.panelLineMesh = EditUtil.CreatePanelLineMesh(); this.blockSurfaceMesh = EditUtil.CreateBlockSurfaceMesh(); this.blockLineMesh = EditUtil.CreateBlockLineMesh(); }
public static List <OBJMaterial> LoadMTL(string path) { if (!File.Exists(path)) { return(null); } string[] lines = File.ReadAllLines(path); List <OBJMaterial> materials = new List <OBJMaterial>(); OBJMaterial currentMaterial = null; foreach (string line in lines) { if (line.Length == 0) { continue; } if (line[0] == '#') { continue; } string[] tokens = line.Split(' '); if (tokens[0] == "newmtl") { currentMaterial = new OBJMaterial(); materials.Add(currentMaterial); currentMaterial.name = tokens[1]; } else if (tokens[0] == "map_Kd") { string dirName = Path.GetDirectoryName(path); string textureName = Path.GetFileNameWithoutExtension(tokens[1]); string textureExt = Path.GetExtension(tokens[1]); currentMaterial.albedo = EditUtil.LoadTextureFromFile(dirName + "/" + tokens[1]); currentMaterial.emission = EditUtil.LoadTextureFromFile(dirName + "/" + textureName + "_e" + textureExt); currentMaterial.normal = EditUtil.LoadTextureFromFile(dirName + "/" + textureName + "_n" + textureExt); currentMaterial.specular = EditUtil.LoadTextureFromFile(dirName + "/" + textureName + "_s" + textureExt); } } return(materials); }
// マウスカーソル位置のブロックを取得 private bool GetCursorPoint(out Point point) { point = new Point(); var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { point.normal = hit.normal; point.gameObject = hit.transform.gameObject; point.position = EditUtil.ResolvePosition(hit.point - point.normal * 0.25f); point.meshId = (int)hit.textureCoord2.x; return(true); } point.position = Vector3.zero; point.normal = Vector3.zero; point.gameObject = null; return(false); }
public void Merge(Mesh mesh, Vector3 position, BlockDirection direction, int textureId, int meshIndex) { var chip = TexturePalette.Instance.GetChip(textureId); int vertexOffset = this.vertexPos.Count; Vector3[] vertexPos = mesh.vertices; Vector2[] vertexUv = mesh.uv; for (int j = 0; j < vertexPos.Length; j++) { Vector3 localPosition = Vector3.Scale(vertexPos[j], new Vector3(-1, 1, -1)); this.vertexPos.Add(position + EditUtil.RotatePosition(localPosition, direction)); this.vertexUv.Add(chip.ApplyUV(vertexUv[j], meshIndex, position.y)); } int[] indices = mesh.GetIndices(0); for (int j = 0; j < indices.Length; j++) { this.triangles.Add(vertexOffset + indices[j]); } }
// 選択幅を拡張 public void Expand(Vector2 screenDir) { if (this.HasCapturedBlocks()) { return; } Vector3 up, right; EditUtil.ScreenDirToWorldDir(out up, out right); Vector3 expandVector = up * screenDir.y + right * screenDir.x; foreach (var point in this.selectedBlocks.GetAllBlocks()) { Vector3 newPosition = point.position + expandVector; var target = this.selectedBlocks.GetBlock(newPosition); if (target == null) { this.Add(newPosition); } } }
// ルート用メッシュを出力 public void WriteToRouteMesh(BlockGroup blockGroup, BlockMeshMerger mesh) { if (!this.IsEnterable(blockGroup)) { return; } int offset = mesh.vertexPos.Count; for (int j = 0; j < 4; j++) { int index = EditUtil.ReversePanelVertexIndex(j, this.direction); Vector3 vertex = EditUtil.panelVertices[j]; vertex.y = this.shape.panelVertices[index] * 0.5f - 0.25f; vertex = EditManager.Instance.ToWorldCoordinate(vertex); mesh.vertexPos.Add(this.position + vertex); } if (this.direction == BlockDirection.Xplus || this.direction == BlockDirection.Xminus ) { mesh.triangles.Add(offset + 0); mesh.triangles.Add(offset + 2); mesh.triangles.Add(offset + 1); mesh.triangles.Add(offset + 1); mesh.triangles.Add(offset + 2); mesh.triangles.Add(offset + 3); } else { mesh.triangles.Add(offset + 0); mesh.triangles.Add(offset + 3); mesh.triangles.Add(offset + 1); mesh.triangles.Add(offset + 0); mesh.triangles.Add(offset + 2); mesh.triangles.Add(offset + 3); } }
// オブジェクトをクリック public void OnObjectClicked() { var selector = EditManager.Instance.Selector; var cursor = EditManager.Instance.Cursor; switch (EditManager.Instance.GetTool()) { case EditManager.Tool.Block: if (cursor.visible) { // 1つ手前にブロックを配置 EditManager.Instance.AddBlock(cursor.point, EditManager.Instance.Cursor.blockDirection); } break; case EditManager.Tool.Eraser: // 選択されたオブジェクトを消す if (cursor.visible) { if (cursor.block != null) { EditManager.Instance.RemoveBlock(cursor.point); } else if (cursor.model != null) { EditManager.Instance.RemoveModel(cursor.model); } } break; case EditManager.Tool.Brush: if (cursor.visible) { // 対象のブロックを塗る(テクスチャ指定) var block = EditManager.Instance.CurrentLayer.GetBlock(cursor.point); if (block != null) { EditManager.Instance.PaintBlock(block, cursor.panelDirection, cursor.objectSelected, TexturePalette.Instance.GetItem()); } } break; case EditManager.Tool.Spuit: if (cursor.visible) { // 対象のブロックのテクスチャを取得 var block = EditManager.Instance.CurrentLayer.GetBlock(cursor.point); if (block != null) { TexturePalette.Instance.SetItem(block.GetTextureChip(cursor.panelDirection, cursor.objectSelected)); } } break; case EditManager.Tool.PointSelector: // 選択モード if (cursor.visible) { // キャプチャ状態のオブジェクトを解放 selector.ReleaseBlocks(); // CtrlもShiftも押さずにクリックしたら選択解除 if (!this.modifierControl && !this.modifierShift) { selector.Clear(); } if (this.modifierShift && selector.Count > 0) { // Shift押しながら2つ目以降を選択した場合、範囲選択をする selector.SelectRange(selector.LastPosition, cursor.point); } else if (cursor.model != null) { if (selector.IsSelected(cursor.model)) { selector.Remove(cursor.model); } else { selector.Add(cursor.model); } } else { // 通常の選択 if (selector.IsSelected(cursor.point)) { selector.Remove(cursor.point); } else { selector.Add(cursor.point); } } } else { // 何もないところをCtrlもShiftも押さずにクリックしたら選択解除 if (!this.modifierControl && !this.modifierShift) { selector.ReleaseBlocks(); selector.Clear(); } } break; case EditManager.Tool.RoutePath: if (cursor.visible) { var routePath = EditManager.Instance.RoutePath; var block = EditManager.Instance.CurrentLayer.GetBlock(cursor.point); if (routePath.isSelected) { // パス確定 if (routePath.ContainsPath(routePath.selectedPosition, block.position)) { // 存在していたら消す EditManager.Instance.RemoveRoutePath(routePath.selectedPosition, block.position); routePath.RemovePath(routePath.selectedPosition, block.position); } else if (routePath.CanAddPath(routePath.selectedPosition, block.position)) { // 存在していなかったら追加 EditManager.Instance.AddRoutePath(routePath.selectedPosition, block.position); } else if (routePath.selectedPosition == block.position) { // 同じ位置の場合は侵入フラグをトグルする EditManager.Instance.SetEnterable(block, !block.enterable); } routePath.isSelected = false; EditManager.Instance.Selector.Clear(); } else { // パスの開始ブロックを選択 EditManager.Instance.Selector.Add(block.position); routePath.selectedPosition = block.position; routePath.isSelected = true; } } break; case EditManager.Tool.Model: if (cursor.visible) { var foundModel = EditManager.Instance.CurrentLayer.GetModel(cursor.point); if (foundModel == null) { // モデル配置 EditManager.Instance.AddModel(cursor.point, (int)EditUtil.DirectionToAngle(EditManager.Instance.Cursor.blockDirection)); } } break; case EditManager.Tool.MetaInfo: EditManager.Instance.Selector.Clear(); EditManager.Instance.MetaInfo.gameObject.SetActive(false); if (cursor.visible) { var block = EditManager.Instance.CurrentLayer.GetBlock(cursor.point); if (block != null) { // メタ情報を記入するブロックを選択 EditManager.Instance.Selector.Add(block.position); // メタ情報記入のダイアログを表示 EditManager.Instance.MetaInfo.gameObject.SetActive(true); EditManager.Instance.MetaInfo.SetBlock(block); } } break; } }
private void SpbtFSet_DropDownClosed(object sender, EventArgs e) { EditUtil.UpgradeDrawSettings(); }
// 90度回転 public void TurnBlock(int value) { BlockDirection direction = EditUtil.RotateDirection(this.blockDirection, value); this.blockDirection = direction; }
public void Doc_OnChange(object sender, EventArgs e) { if (!Doc.IsInBatch) { EditUtil.RefreshSeekBar(); EditUtil.cn_WidthChanged(null, null); } }
public void Update() { bool visible = false; // マウスカーソルの処理 Vector3 point, normal; GameObject gameObject; bool cursorEnabled = this.GetCursorPoint(out point, out normal, out gameObject); this.block = null; this.model = null; if (gameObject == EditManager.Instance.CurrentLayer.gameObject) { this.block = EditManager.Instance.CurrentLayer.GetBlock(point); } else if (gameObject != null) { this.model = EditManager.Instance.CurrentLayer.GetModel(gameObject); } switch (EditManager.Instance.GetTool()) { case EditManager.Tool.Block: if (cursorEnabled) { // 手前に立体カーソルを置く point += new Vector3(normal.x, normal.y * 0.5f, normal.z); visible = true; this.point = point; this.transform.position = point; this.transform.rotation = Quaternion.AngleAxis( EditUtil.DirectionToAngle(this.blockDirection), Vector3.up); this.transform.localScale = Vector3.one; } break; case EditManager.Tool.Eraser: case EditManager.Tool.PointSelector: if (cursorEnabled) { // 立体カーソルを置く if (this.block != null) { visible = true; this.point = point; this.SetBlock(); this.transform.position = point; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } else if (this.model != null) { visible = true; this.point = point; this.SetModelBound(this.model); this.transform.position = this.model.position; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } } break; case EditManager.Tool.Brush: case EditManager.Tool.Spuit: if (cursorEnabled && this.block != null) { this.point = point; // 面カーソルを置く visible = true; this.panelDirection = EditUtil.VectorToDirection(normal); var block = EditManager.Instance.CurrentLayer.GetBlock(point); if (block.GetMesh(this.panelDirection) != null) { // 面のメッシュが存在していたら、面が選択されている this.objectSelected = false; this.SetPanel(); this.transform.position = point + new Vector3(normal.x * 0.5f, normal.y * 0.25f, normal.z * 0.5f); switch (this.panelDirection) { case BlockDirection.Yplus: this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; break; case BlockDirection.Yminus: this.transform.rotation = Quaternion.Euler(180, 0, 0); this.transform.localScale = Vector3.one; break; case BlockDirection.Zplus: this.transform.rotation = Quaternion.Euler(90, 180, 0); this.transform.localScale = new Vector3(1.0f, 1.0f, 0.5f); break; case BlockDirection.Zminus: this.transform.rotation = Quaternion.Euler(90, 0, 0); this.transform.localScale = new Vector3(1.0f, 1.0f, 0.5f); break; case BlockDirection.Xplus: this.transform.rotation = Quaternion.Euler(90, 90, 0); this.transform.localScale = new Vector3(1.0f, 1.0f, 0.5f); break; case BlockDirection.Xminus: this.transform.rotation = Quaternion.Euler(90, 270, 0); this.transform.localScale = new Vector3(1.0f, 1.0f, 0.5f); break; } } else { // 面のメッシュが存在していないなら、オブジェクトが選択されている this.objectSelected = true; this.SetBlock(); this.transform.position = point; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } } break; case EditManager.Tool.Model: if (cursorEnabled) { // ブロックの上に立体カーソルを置く point += new Vector3(0.0f, 0.25f, 0.0f); visible = true; this.point = point; this.transform.position = point; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } break; case EditManager.Tool.RoutePath: case EditManager.Tool.MetaInfo: if (cursorEnabled && this.block != null && EditUtil.VectorToDirection(normal) == BlockDirection.Yplus ) { this.point = point; // 面カーソルを置く visible = true; this.transform.position = point + new Vector3(normal.x * 0.5f, normal.y * 0.25f, normal.z * 0.5f); this.panelDirection = BlockDirection.Yplus; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } break; } this.visible = visible; this.guide.gameObject.SetActive(visible); }
public void DosToUnixAtEnd() { var text = EditUtil.NormalizeNewLines("dog\r\ncat\r\n", "\n"); Assert.Equal("dog\ncat\n", text); }
public void SetPosition(Vector3 position) { this.position = position; this.hashCode = EditUtil.PositionToHashCode(position); }
public void UnixToDos() { var text = EditUtil.NormalizeNewLines("dog\ncat", "\r\n"); Assert.Equal("dog\r\ncat", text); }
private void grFrame_Drop(object sender, DragEventArgs e) { EditUtil.ReplaceFrame(_draged.Frm, Frm, ActualWidth / 2 < e.GetPosition(this).X); imDropRigth.Visibility = imDropLeft.Visibility = Visibility.Collapsed; }
public void Update() { bool visible = false; // マウスカーソルの処理 Point point; bool cursorEnabled = this.GetCursorPoint(out point); this.block = null; this.model = null; if (point.gameObject != null) { var layer = point.gameObject.GetComponent <EditLayer>(); if (layer != null) { if (layer == EditManager.Instance.CurrentLayer) { this.block = layer.GetBlock(point.position); } } else { this.model = EditManager.Instance.CurrentLayer.GetModel(point.gameObject); } } switch (EditManager.Instance.GetTool()) { case EditManager.Tool.Block: if (cursorEnabled) { // 手前に立体カーソルを置く visible = true; this.point = EditUtil.ResolvePosition(point.position + new Vector3(point.normal.x, point.normal.y * 0.5f, point.normal.z)); this.transform.position = this.point; this.transform.rotation = Quaternion.AngleAxis( EditUtil.DirectionToAngle(this.blockDirection), Vector3.up); this.transform.localScale = Vector3.one; } break; case EditManager.Tool.Eraser: case EditManager.Tool.PointSelector: if (cursorEnabled) { // 立体カーソルを置く if (this.block != null) { visible = true; this.point = point.position; this.SetBlock(); this.transform.position = point.position; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } else if (this.model != null) { visible = true; this.point = point.position; this.SetModelBound(this.model); this.transform.position = this.model.position; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } } break; case EditManager.Tool.Brush: case EditManager.Tool.Spuit: if (cursorEnabled && this.block != null) { this.point = point.position; // 面カーソルを置く visible = true; this.panelDirection = EditUtil.VectorToDirection(point.normal); Mesh mesh = this.block.GetMesh(this.panelDirection); if (mesh != null) { // 面が選択されている this.objectSelected = false; this.SetMesh(mesh); } else { mesh = this.block.GetObjectMesh(); if (mesh != null) { // オブジェクトが選択されている this.objectSelected = true; this.SetMesh(mesh); } else { this.SetBlock(); } } Vector3 position = point.position + point.normal * 0.01f; this.transform.position = new Vector3(Mathf.Round(position.x), Mathf.Round(position.y * 2.0f) * 0.5f, Mathf.Round(position.z)); this.transform.rotation = Quaternion.AngleAxis( EditUtil.DirectionToAngle(this.block.direction) + 180.0f, Vector3.up); this.transform.localScale = Vector3.one; } break; case EditManager.Tool.Model: if (cursorEnabled) { // 手前に立体カーソルを置く visible = true; this.point = EditUtil.ResolvePosition(point.position + new Vector3(point.normal.x, point.normal.y * 0.5f, point.normal.z)); this.transform.position = this.point; this.transform.rotation = Quaternion.AngleAxis( EditUtil.DirectionToAngle(this.blockDirection), Vector3.up); this.transform.localScale = Vector3.one; } break; case EditManager.Tool.RoutePath: case EditManager.Tool.MetaInfo: if (cursorEnabled && this.block != null && EditUtil.VectorToDirection(point.normal) == BlockDirection.Yplus ) { this.point = point.position; visible = true; // 面カーソルを置く this.SetPanel(); Vector3 position = point.position + point.normal * 0.01f; this.transform.position = new Vector3(Mathf.Round(position.x), Mathf.Round(position.y * 2.0f) * 0.5f + 0.25f, Mathf.Round(position.z)); this.panelDirection = BlockDirection.Yplus; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } break; } this.visible = visible; this.guide.gameObject.SetActive(visible); }
private void Thumb_DragCompleted(object sender, DragCompletedEventArgs e) { _resized = false; Frm.EndLengthBatch(); EditUtil.RefreshSeekBar(); }
public void MoveObjects(Block[] blocks, Model[] models, Vector3 moveVector, Vector3 centerPosition, int rotation) { EditLayer layer = this.CurrentLayer; Block[] removedBlocks = null; // 上書きされたブロック Model[] removedModels = null; // 上書きされたモデル if (blocks.Length == 0 && models.Length == 0) { return; } this.AddCommand(new Command( () => { // レイヤーから一旦削除 layer.RemoveBlocks(blocks); layer.RemoveModels(models, false); // ブロックを移動回転させる foreach (var block in blocks) { Vector3 offset = block.position - centerPosition; offset = EditUtil.RotatePosition(offset, rotation); block.SetPosition(centerPosition + offset + moveVector); block.SetDirection(EditUtil.RotateDirection(block.direction, rotation)); } // モデルを移動回転させる foreach (var model in models) { Vector3 offset = model.position - centerPosition; offset = EditUtil.RotatePosition(offset, rotation); model.SetPosition(centerPosition + offset + moveVector); model.SetRotation(model.rotation + rotation * 90); } // レイヤーに戻す removedBlocks = layer.AddBlocks(blocks); removedModels = layer.AddModels(models); }, () => { // レイヤーから一旦削除 layer.RemoveBlocks(blocks); layer.RemoveModels(models, false); // 退避したブロックを復活させる layer.AddBlocks(removedBlocks); layer.AddModels(removedModels); removedBlocks = null; removedModels = null; // ブロックを逆方向に移動回転させる foreach (var block in blocks) { Vector3 offset = block.position - centerPosition - moveVector; offset = EditUtil.RotatePosition(offset, -rotation); block.SetPosition(centerPosition + offset); block.SetDirection(EditUtil.RotateDirection(block.direction, -rotation)); } // モデルを逆方向に移動回転させる foreach (var model in models) { Vector3 offset = model.position - centerPosition - moveVector; offset = EditUtil.RotatePosition(offset, -rotation); model.SetPosition(centerPosition + offset); model.SetRotation(model.rotation - rotation * 90); } // レイヤーに戻す layer.AddBlocks(blocks); layer.AddModels(models); })); }
// 選択ブロックを開放 public void ReleaseBlocks() { if (!this.HasCapturedBlocks()) { return; } Block[] blocks = this.capturedBlocks; Model[] models = this.capturedModels; this.captureLayer.RemoveBlocks(blocks); this.captureLayer.RemoveModels(models, false); Vector3 moveVector = this.transform.position - this.capturedCenter; // キャプチャ対象のモデルの位置を戻す foreach (var model in models) { if (model.gameObject != null) { model.gameObject.transform.parent = EditManager.Instance.CurrentLayer.transform; } } if (this.captureMode == CaptureMode.Moving) { // 一旦実在レイヤーに戻して移動コマンドを打つ EditManager.Instance.CurrentLayer.AddBlocks(blocks); EditManager.Instance.CurrentLayer.AddModels(models); EditManager.Instance.MoveObjects(blocks, models, moveVector, this.capturedCenter, this.capturedRotation); } else { // ブロック追加コマンドを打つ foreach (var block in blocks) { Vector3 offset = block.position - this.capturedCenter; offset = EditUtil.RotatePosition(offset, this.capturedRotation); block.SetPosition(this.capturedCenter + offset + moveVector); block.SetDirection(EditUtil.RotateDirection(block.direction, this.capturedRotation)); } foreach (var model in models) { Vector3 offset = model.position - this.capturedCenter; offset = EditUtil.RotatePosition(offset, this.capturedRotation); model.SetPosition(this.capturedCenter + offset + moveVector); model.SetRotation(model.rotation + this.capturedRotation * 90); } EditManager.Instance.AddObjects(blocks, models); } this.transform.position = Vector3.zero; this.captureLayer.transform.position = Vector3.zero; this.selectedBlockGuide.transform.position = Vector3.zero; this.selectedModelGuide.transform.position = Vector3.zero; this.transform.rotation = Quaternion.identity; this.capturedRotation = 0; this.capturedBlocks = null; this.Set(blocks, models); this.dirtyMesh = true; // マテリアルをを選択中の色に変更 this.SetColorMode(ColorMode.Selection); // モデルのプロパティ編集を許可 EditManager.Instance.ModelProperties.SetModels(this.GetSelectedModels()); }
private void uiScaleSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { EditUtil.SetScale(e.NewValue); }
// ブロックメッシュをマージ public void Merge(Mesh mesh, Vector3 position, BlockDirection direction, Vector3 scale, bool divideChipVert, int textureId, int meshId) { var chip = TexturePalette.Instance.GetChip(textureId); int vertexOffset = this.vertexPos.Count; Vector3[] vertexPos = mesh.vertices; Vector3[] vertexNormal = mesh.normals; Vector2[] vertexUv = mesh.uv; int[] indices = mesh.GetIndices(0); float[] heights = new float[vertexUv.Length]; // Vが0.0~1.0の範囲外の場合は高さを調整する for (int j = 0; j < indices.Length; j += 3) { Vector2 uv0 = vertexUv[indices[j + 0]]; Vector2 uv1 = vertexUv[indices[j + 1]]; Vector2 uv2 = vertexUv[indices[j + 2]]; float height = position.y; if (uv0.y < 0.0f || uv1.y < 0.0f || uv2.y < 0.0f) { height += 0.5f; } else if (uv0.y > 1.0f || uv1.y > 1.0f || uv2.y > 1.0f) { height -= 0.5f; } heights[indices[j + 0]] = height; heights[indices[j + 1]] = height; heights[indices[j + 2]] = height; } for (int j = 0; j < vertexPos.Length; j++) { Vector3 localPosition = Vector3.Scale(vertexPos[j], Vector3.Scale(new Vector3(-1, 1, -1), scale)); Vector3 localNormal = Vector3.Scale(vertexNormal[j], new Vector3(-1, 1, -1)); this.vertexPos.Add(position + EditUtil.RotatePosition(localPosition, direction)); this.vertexNormal.Add(EditUtil.RotatePosition(localNormal, direction)); this.vertexUv.Add(chip.ApplyUV(vertexUv[j], divideChipVert, heights[j])); this.vertexMeta.Add(new Vector2((float)meshId, 0.0f)); } for (int j = 0; j < indices.Length; j++) { this.triangles.Add(vertexOffset + indices[j]); } if (this.subMeshMerger != null) { int key = EditUtil.PositionToHashCode(new Vector3( Mathf.Floor(position.x / this.subMeshDivs.x), Mathf.Floor(position.y / this.subMeshDivs.y), Mathf.Floor(-position.z / this.subMeshDivs.z))); if (!this.subMeshMerger.ContainsKey(key)) { this.subMeshMerger.Add(key, new BlockMeshMerger()); } this.subMeshMerger[key].Merge(mesh, position, direction, scale, divideChipVert, textureId, meshId); } }