public FMeshFacet AddFacet(FMeshFacet facet) { if (facets == null) { facets = new List <FMeshFacet>(); facetType = facet.facetType; } if (facetType != facet.facetType) //check if the facet type is different from what we already have { Debug.LogError("You can't mix facet types in FMeshData!"); } facets.Add(facet); return(facet); }
public FMeshFacet AddFacet(FMeshFacet facet) { if(facets == null) { facets = new List<FMeshFacet>(); facetType = facet.facetType; } if(facetType != facet.facetType) //check if the facet type is different from what we already have { Debug.LogError("You can't mix facet types in FMeshData!"); } facets.Add(facet); return facet; }
override public void PopulateRenderLayer() { if (_isOnStage && _firstFacetIndex != -1) { _isMeshDirty = false; float a = _concatenatedMatrix.a; float b = _concatenatedMatrix.b; float c = _concatenatedMatrix.c; float d = _concatenatedMatrix.d; float tx = _concatenatedMatrix.tx; float ty = _concatenatedMatrix.ty; Vector3[] vertices = _renderLayer.vertices; Vector2[] uvs = _renderLayer.uvs; Color[] colors = _renderLayer.colors; List <FMeshFacet> facets = _meshData.facets; int facetCount = facets.Count; FMeshVertex vertex; if (_meshData.facetType == FFacetType.Triangle) { int vertexIndex0 = _firstFacetIndex * 3; int vertexIndex1 = vertexIndex0 + 1; int vertexIndex2 = vertexIndex0 + 2; for (int f = 0; f < facetCount; f++) { FMeshFacet facet = facets[f]; //outVector.x = localVector.x*a + localVector.y*c + tx; //outVector.y = localVector.x*b + localVector.y*d + ty; //outVector.z = z; FMeshVertex[] meshVertices = facet.vertices; vertex = meshVertices[0]; vertices[vertexIndex0] = new Vector3(vertex.x * a + vertex.y * c + tx, vertex.x * b + vertex.y * d + ty, _meshZ); vertex = meshVertices[1]; vertices[vertexIndex1] = new Vector3(vertex.x * a + vertex.y * c + tx, vertex.x * b + vertex.y * d + ty, _meshZ); vertex = meshVertices[2]; vertices[vertexIndex2] = new Vector3(vertex.x * a + vertex.y * c + tx, vertex.x * b + vertex.y * d + ty, _meshZ); //this needs to be offset by the element uvs, so that the uvs are relative to the element (add then multiply element uv) uvs[vertexIndex0] = new Vector2(_uvOffsetX + meshVertices[0].u * _uvScaleX, _uvOffsetY + meshVertices[0].v * _uvScaleY); uvs[vertexIndex1] = new Vector2(_uvOffsetX + meshVertices[1].u * _uvScaleX, _uvOffsetY + meshVertices[1].v * _uvScaleY); uvs[vertexIndex2] = new Vector2(_uvOffsetX + meshVertices[2].u * _uvScaleX, _uvOffsetY + meshVertices[2].v * _uvScaleY); //could also use vertex colours here! colors[vertexIndex0] = _alphaColor * meshVertices[0].color; colors[vertexIndex1] = _alphaColor * meshVertices[1].color; colors[vertexIndex2] = _alphaColor * meshVertices[2].color; vertexIndex0 += 3; vertexIndex1 += 3; vertexIndex2 += 3; } } else if (_meshData.facetType == FFacetType.Quad) { int vertexIndex0 = _firstFacetIndex * 4; int vertexIndex1 = vertexIndex0 + 1; int vertexIndex2 = vertexIndex0 + 2; int vertexIndex3 = vertexIndex0 + 3; for (int f = 0; f < facetCount; f++) { FMeshFacet facet = facets[f]; FMeshVertex[] meshVertices = facet.vertices; vertex = meshVertices[0]; vertices[vertexIndex0] = new Vector3(vertex.x * a + vertex.y * c + tx, vertex.x * b + vertex.y * d + ty, _meshZ); vertex = meshVertices[1]; vertices[vertexIndex1] = new Vector3(vertex.x * a + vertex.y * c + tx, vertex.x * b + vertex.y * d + ty, _meshZ); vertex = meshVertices[2]; vertices[vertexIndex2] = new Vector3(vertex.x * a + vertex.y * c + tx, vertex.x * b + vertex.y * d + ty, _meshZ); vertex = meshVertices[3]; vertices[vertexIndex3] = new Vector3(vertex.x * a + vertex.y * c + tx, vertex.x * b + vertex.y * d + ty, _meshZ); //this needs to be offset by the element uvs, so that the uvs are relative to the element (add then multiply element uv) uvs[vertexIndex0] = new Vector2(_uvOffsetX + meshVertices[0].u * _uvScaleX, _uvOffsetY + meshVertices[0].v * _uvScaleY); uvs[vertexIndex1] = new Vector2(_uvOffsetX + meshVertices[1].u * _uvScaleX, _uvOffsetY + meshVertices[1].v * _uvScaleY); uvs[vertexIndex2] = new Vector2(_uvOffsetX + meshVertices[2].u * _uvScaleX, _uvOffsetY + meshVertices[2].v * _uvScaleY); uvs[vertexIndex3] = new Vector2(_uvOffsetX + meshVertices[3].u * _uvScaleX, _uvOffsetY + meshVertices[3].v * _uvScaleY); //could also use vertex colours here! colors[vertexIndex0] = _alphaColor * meshVertices[0].color; colors[vertexIndex1] = _alphaColor * meshVertices[1].color; colors[vertexIndex2] = _alphaColor * meshVertices[2].color; colors[vertexIndex3] = _alphaColor * meshVertices[3].color; vertexIndex0 += 4; vertexIndex1 += 4; vertexIndex2 += 4; vertexIndex3 += 4; } } _renderLayer.HandleVertsChange(); } }