/// <summary> /// Actualiza la caja en base a los valores configurados /// </summary> public void updateValues() { //Crear grilla de 4x4 caras rectangulares bool triangleSide1 = true; int vIndex = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { //Los 4 vertices que forman la cara EditableVertex tl = editableVertices[i * 5 + j]; EditableVertex tr = editableVertices[i * 5 + j + 1]; EditableVertex bl = editableVertices[(i + 1) * 5 + j]; EditableVertex br = editableVertices[(i + 1) * 5 + j + 1]; if (triangleSide1) { //Sentido 1 //Primer triangulo: tl - br - bl vertices[vIndex] = new CustomVertex.PositionTextured(tl.Pos, uvOffset.X + uvTiling.X * tl.UV.X, uvOffset.Y + uvTiling.Y * tl.UV.Y); vertices[vIndex + 1] = new CustomVertex.PositionTextured(br.Pos, uvOffset.X + uvTiling.X * br.UV.X, uvOffset.Y + uvTiling.Y * br.UV.Y); vertices[vIndex + 2] = new CustomVertex.PositionTextured(bl.Pos, uvOffset.X + uvTiling.X * bl.UV.X, uvOffset.Y + uvTiling.Y * bl.UV.Y); //Segundo triangulo: tl - tr - br vertices[vIndex + 3] = new CustomVertex.PositionTextured(tl.Pos, uvOffset.X + uvTiling.X * tl.UV.X, uvOffset.Y + uvTiling.Y * tl.UV.Y); vertices[vIndex + 4] = new CustomVertex.PositionTextured(tr.Pos, uvOffset.X + uvTiling.X * tr.UV.X, uvOffset.Y + uvTiling.Y * tr.UV.Y); vertices[vIndex + 5] = new CustomVertex.PositionTextured(br.Pos, uvOffset.X + uvTiling.X * br.UV.X, uvOffset.Y + uvTiling.Y * br.UV.Y); } else { //Sentido 2 //bl - tl - tr vertices[vIndex] = new CustomVertex.PositionTextured(bl.Pos, uvOffset.X + uvTiling.X * bl.UV.X, uvOffset.Y + uvTiling.Y * bl.UV.Y); vertices[vIndex + 1] = new CustomVertex.PositionTextured(tl.Pos, uvOffset.X + uvTiling.X * tl.UV.X, uvOffset.Y + uvTiling.Y * tl.UV.Y); vertices[vIndex + 2] = new CustomVertex.PositionTextured(tr.Pos, uvOffset.X + uvTiling.X * tr.UV.X, uvOffset.Y + uvTiling.Y * tr.UV.Y); //bl - tr - br vertices[vIndex + 3] = new CustomVertex.PositionTextured(bl.Pos, uvOffset.X + uvTiling.X * bl.UV.X, uvOffset.Y + uvTiling.Y * bl.UV.Y); vertices[vIndex + 4] = new CustomVertex.PositionTextured(tr.Pos, uvOffset.X + uvTiling.X * tr.UV.X, uvOffset.Y + uvTiling.Y * tr.UV.Y); vertices[vIndex + 5] = new CustomVertex.PositionTextured(br.Pos, uvOffset.X + uvTiling.X * br.UV.X, uvOffset.Y + uvTiling.Y * br.UV.Y); } vIndex += 6; //Invertir proximo sentido (salvo el ultimo de la fila) if (j != 3) { triangleSide1 = !triangleSide1; } } } vertexBuffer.SetData(vertices, 0, LockFlags.None); updateBoundingBox(); }
public void Initialize(EditableMesh parent, EditableVertex point0, EditableVertex point1, int tIndex) { this.parent = parent; this.point0 = point0; this.point1 = point1; tIndices.Add(tIndex); transform.parent = parent.transform; CalculateTransform(); }
public void Initialize(EditableObject parent, EditableVertex point0, EditableVertex point1, int tIndex) { this.parent = parent; this.point0 = point0; this.point1 = point1; tIndices.Add(tIndex); transform.parent = parent.transform; CalculateTransform(); meshRenderer = GetComponent <MeshRenderer>(); meshRenderer.enabled = false; }
private void OnVertDeselected(EditableVertex vert) { U.interactable = false; V.interactable = false; NX.interactable = false; NY.interactable = false; NZ.interactable = false; colorPickerButton.interactable = false; if (colorPicker.gameObject.activeSelf) { OnCloseColorPickerClicked(); } UpdateUV(); UpdateNormal(); }
private void OnVertSelected(EditableVertex vert) { U.interactable = true; V.interactable = true; NX.interactable = true; NY.interactable = true; NZ.interactable = true; colorPickerButton.interactable = true; var v = vert.primitive.info.vertices[vert.vertIndex]; U.text = v.uv.x.ToString(System.Globalization.CultureInfo.InvariantCulture); V.text = v.uv.y.ToString(System.Globalization.CultureInfo.InvariantCulture); NX.text = v.normal.x.ToString(System.Globalization.CultureInfo.InvariantCulture); NY.text = v.normal.y.ToString(System.Globalization.CultureInfo.InvariantCulture); NZ.text = v.normal.z.ToString(System.Globalization.CultureInfo.InvariantCulture); colorPicker.PickerColor = v.color; }
/// <summary> /// Crea el terreno /// </summary> public TgcEditableLand() { Device d3dDevice = GuiController.Instance.D3dDevice; //16 caras, 32 triangulos, 96 vertices vertices = new CustomVertex.PositionTextured[96]; vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), vertices.Length, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default); //Crear los 25 vertices editables, formando una grilla de 5x5 vertices editableVertices = new EditableVertex[25]; float uvStep = 1f / 4f; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { EditableVertex v = new EditableVertex(); v.Pos = new Vector3(j * PATCH_SIZE, 0, i * PATCH_SIZE); v.UV = new Vector2(j * uvStep, i * uvStep); editableVertices[i * 5 + j] = v; } } this.autoTransformEnable = true; this.transform = Matrix.Identity; this.translation = new Vector3(0, 0, 0); this.rotation = new Vector3(0, 0, 0); this.scale = new Vector3(1, 1, 1); this.enabled = true; this.alphaBlendEnable = false; this.uvOffset = new Vector2(0, 0); this.uvTiling = new Vector2(1, 1); //BoundingBox boundingBox = new TgcBoundingBox(); updateBoundingBox(); //Shader this.effect = GuiController.Instance.Shaders.VariosShader; this.technique = TgcShaders.T_POSITION_TEXTURED; }
public void UpdateVertex(EditableVertex vertex, List <int> indices, Vector3 deltaPosition) { updated = true; deltaPosition = Quaternion.Inverse(transform.rotation) * deltaPosition; deltaPosition.x /= meshTransform.localScale.x; deltaPosition.y /= meshTransform.localScale.y; deltaPosition.z /= meshTransform.localScale.z; foreach (var index in indices) { vertices[index] += deltaPosition; } // Alert update to listeners foreach (var child in listeningList[vertex]) { child.UpdateChild(); } }
/// <summary> /// Crea el terreno /// </summary> public TgcEditableLand() { //16 caras, 32 triangulos, 96 vertices vertices = new CustomVertex.PositionTextured[96]; vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), vertices.Length, D3DDevice.Instance.Device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default); //Crear los 25 vertices editables, formando una grilla de 5x5 vertices editableVertices = new EditableVertex[25]; var uvStep = 1f / 4f; for (var i = 0; i < 5; i++) { for (var j = 0; j < 5; j++) { var v = new EditableVertex(); v.Pos = new Vector3(j * PATCH_SIZE, 0, i * PATCH_SIZE); v.UV = new Vector2(j * uvStep, i * uvStep); editableVertices[i * 5 + j] = v; } } AutoTransformEnable = true; Transform = Matrix.Identity; translation = new Vector3(0, 0, 0); rotation = new Vector3(0, 0, 0); scale = new Vector3(1, 1, 1); Enabled = true; AlphaBlendEnable = false; UVOffset = new Vector2(0, 0); UVTiling = new Vector2(1, 1); //BoundingBox BoundingBox = new TgcBoundingBox(); updateBoundingBox(); //Shader effect = TgcShaders.Instance.VariosShader; technique = TgcShaders.T_POSITION_TEXTURED; }
/// <summary> /// Crea el terreno /// </summary> public TgcEditableLand() { Device d3dDevice = GuiController.Instance.D3dDevice; //16 caras, 32 triangulos, 96 vertices vertices = new CustomVertex.PositionTextured[96]; vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), vertices.Length, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default); //Crear los 25 vertices editables, formando una grilla de 5x5 vertices editableVertices = new EditableVertex[25]; float uvStep = 1f / 4f; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { EditableVertex v = new EditableVertex(); v.Pos = new Vector3(j * PATCH_SIZE, 0, i * PATCH_SIZE); v.UV = new Vector2(j * uvStep, i * uvStep); editableVertices[i * 5 + j] = v; } } this.autoTransformEnable = true; this.transform = Matrix.Identity; this.translation = new Vector3(0,0,0); this.rotation = new Vector3(0,0,0); this.scale = new Vector3(1, 1, 1); this.enabled = true; this.alphaBlendEnable = false; this.uvOffset = new Vector2(0, 0); this.uvTiling = new Vector2(1, 1); //BoundingBox boundingBox = new TgcBoundingBox(); updateBoundingBox(); //Shader this.effect = GuiController.Instance.Shaders.VariosShader; this.technique = TgcShaders.T_POSITION_TEXTURED; }
public void Init() { editableVertexPrefab = EditManager.Instance.editableVertexPrefab; editableLinePrefab = EditManager.Instance.editableLinePrefab; mesh = GetComponentInChildren <MeshFilter>().mesh; Dictionary <Vector3, List <int> > vertexDict = new Dictionary <Vector3, List <int> >(); Vector3[] vertices = mesh.vertices; for (int v = 0; v < vertices.Length; v++) { if (!vertexDict.ContainsKey(vertices[v])) { vertexDict[vertices[v]] = new List <int>(); } vertexDict[vertices[v]].Add(v); this.vertices.Add(vertices[v]); } EditableVertex[] eVertices = new EditableVertex[mesh.vertexCount]; foreach (var vertex in vertexDict.Keys) { Vector3 scaleVertex = vertex; scaleVertex.x *= meshTransform.localScale.x; scaleVertex.y *= meshTransform.localScale.y; scaleVertex.z *= meshTransform.localScale.z; EditableVertex eVertex = Instantiate(editableVertexPrefab, scaleVertex + transform.position, Quaternion.identity); eVertex.Initialize(this, vertexDict[vertex]); foreach (var idx in vertexDict[vertex]) { eVertices[idx] = eVertex; } } int[] aArr = new int[] { 0, 0, 1 }; int[] bArr = new int[] { 1, 2, 2 }; var lines = new Dictionary <LineKey, EditableLine>(); int[] triangles = mesh.triangles; for (int t = 0; t < triangles.Length; t += 3) { int idx = triangles[t]; for (int i = 0; i < 3; i++) { int ta = t + aArr[i]; int tb = t + bArr[i]; LineKey key = new LineKey(eVertices[triangles[ta]], eVertices[triangles[tb]]); if (lines.ContainsKey(key)) { lines[key].tIndices.Add(idx); } else { EditableLine line = Instantiate(editableLinePrefab); line.Initialize(this, eVertices[triangles[ta]], eVertices[triangles[tb]], idx); lines[key] = line; } } } var pairsToDelete = new List <KeyValuePair <LineKey, EditableLine> >(); Vector3[] normals = mesh.normals; foreach (var linePair in lines) { print(linePair.Value.tIndices.Count); bool delete = true; EditableLine line = linePair.Value; Vector3 normal = normals[line.tIndices[0]]; for (int i = 1; i < line.tIndices.Count; i++) { if (normals[line.tIndices[i]] != normal) { delete = false; break; } } if (delete) { pairsToDelete.Add(linePair); } } foreach (var pair in pairsToDelete) { lines.Remove(pair.Key); Destroy(pair.Value.gameObject); } foreach (var line in lines.Values) { //things.Add(line); if (!listeningList.ContainsKey(line.point0)) { listeningList[line.point0] = new List <IUpdatable>(); } listeningList[line.point0].Add(line); if (!listeningList.ContainsKey(line.point1)) { listeningList[line.point1] = new List <IUpdatable>(); } listeningList[line.point1].Add(line); } }
public LineKey(EditableVertex p0, EditableVertex p1) { this.p0 = p0; this.p1 = p1; }