public void RebuildGeometry() { int capacity = Enumerable.Sum <TrixelSurface>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, int>)(x => x.RectangularParts.Count)); VertexGroup <VertexPositionNormalTextureInstance> vertexGroup = new VertexGroup <VertexPositionNormalTextureInstance>(capacity * 4); Dictionary <RectangularTrixelSurfacePart, FaceMaterialization <VertexPositionNormalTextureInstance> > dictionary = new Dictionary <RectangularTrixelSurfacePart, FaceMaterialization <VertexPositionNormalTextureInstance> >(capacity); Vector3 vector3_1 = new Vector3(0.5f); foreach (RectangularTrixelSurfacePart key in Enumerable.SelectMany <TrixelSurface, RectangularTrixelSurfacePart>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, IEnumerable <RectangularTrixelSurfacePart> >)(x => (IEnumerable <RectangularTrixelSurfacePart>)x.RectangularParts))) { Vector3 normal = FezMath.AsVector(key.Orientation); Vector3 vector3_2 = FezMath.AsVector(FezMath.GetTangent(key.Orientation)) * (float)key.TangentSize / 16f; Vector3 vector3_3 = FezMath.AsVector(FezMath.GetBitangent(key.Orientation)) * (float)key.BitangentSize / 16f; Vector3 position = key.Start.Position / 16f + (key.Orientation >= FaceOrientation.Right ? 1f : 0.0f) * normal / 16f - vector3_1; if (!dictionary.ContainsKey(key)) { FaceMaterialization <VertexPositionNormalTextureInstance> faceMaterialization = new FaceMaterialization <VertexPositionNormalTextureInstance>() { V0 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(position, normal)), V1 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(position + vector3_2, normal)), V2 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(position + vector3_2 + vector3_3, normal)), V3 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(position + vector3_3, normal)) }; faceMaterialization.SetupIndices(key.Orientation); dictionary.Add(key, faceMaterialization); } } VertexPositionNormalTextureInstance[] normalTextureInstanceArray = new VertexPositionNormalTextureInstance[vertexGroup.Vertices.Count]; int index = 0; foreach (SharedVertex <VertexPositionNormalTextureInstance> sharedVertex in (IEnumerable <SharedVertex <VertexPositionNormalTextureInstance> >)vertexGroup.Vertices) { normalTextureInstanceArray[index] = sharedVertex.Vertex; normalTextureInstanceArray[index].TextureCoordinate = FezMath.ComputeTexCoord <VertexPositionNormalTextureInstance>(normalTextureInstanceArray[index]) * (this.EngineState == null || !this.EngineState.InEditor ? Vector2.One : new Vector2(1.333333f, 1f)); sharedVertex.Index = index++; } int[] numArray = new int[dictionary.Count * 6]; int num = 0; foreach (FaceMaterialization <VertexPositionNormalTextureInstance> faceMaterialization in dictionary.Values) { for (ushort relativeIndex = (ushort)0; (int)relativeIndex < 6; ++relativeIndex) { numArray[num++] = faceMaterialization.GetIndex(relativeIndex); } } if (this.geometry == null) { this.geometry = new ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Vector4>(PrimitiveType.TriangleList, 220); this.geometry.NeedsEffectCommit = true; if (this.group != null) { this.group.Geometry = (IIndexedPrimitiveCollection)this.geometry; } } this.geometry.Vertices = normalTextureInstanceArray; this.geometry.Indices = numArray; this.DetermineFlags(); }
public void RebuildGeometry() { if (this.surfaces == null) { return; } if (this.Geometry == null) { this.Geometry = new ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Matrix>(PrimitiveType.TriangleList, 60); } int capacity = Enumerable.Sum <TrixelSurface>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, int>)(x => x.RectangularParts.Count)); Dictionary <RectangularTrixelSurfacePart, FaceMaterialization <VertexPositionNormalTextureInstance> > dictionary = new Dictionary <RectangularTrixelSurfacePart, FaceMaterialization <VertexPositionNormalTextureInstance> >(capacity * 4); VertexGroup <VertexPositionNormalTextureInstance> vertexGroup = new VertexGroup <VertexPositionNormalTextureInstance>(capacity); Vector3 vector3_1 = this.size / 2f; foreach (RectangularTrixelSurfacePart key in Enumerable.SelectMany <TrixelSurface, RectangularTrixelSurfacePart>((IEnumerable <TrixelSurface>) this.surfaces, (Func <TrixelSurface, IEnumerable <RectangularTrixelSurfacePart> >)(x => (IEnumerable <RectangularTrixelSurfacePart>)x.RectangularParts))) { if (!dictionary.ContainsKey(key)) { Vector3 normal = FezMath.AsVector(key.Orientation); Vector3 vector3_2 = FezMath.AsVector(FezMath.GetTangent(key.Orientation)) * (float)key.TangentSize / 16f; Vector3 vector3_3 = FezMath.AsVector(FezMath.GetBitangent(key.Orientation)) * (float)key.BitangentSize / 16f; Vector3 v = key.Start.Position / 16f + (FezMath.IsPositive(key.Orientation) ? 1f : 0.0f) * normal / 16f - vector3_1; FaceMaterialization <VertexPositionNormalTextureInstance> faceMaterialization = new FaceMaterialization <VertexPositionNormalTextureInstance>() { V0 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(FezMath.Round(v, 4), normal)), V1 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(FezMath.Round(v + vector3_2, 4), normal)), V2 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(FezMath.Round(v + vector3_2 + vector3_3, 4), normal)), V3 = vertexGroup.Reference(new VertexPositionNormalTextureInstance(FezMath.Round(v + vector3_3, 4), normal)) }; faceMaterialization.SetupIndices(key.Orientation); dictionary.Add(key, faceMaterialization); } } VertexPositionNormalTextureInstance[] normalTextureInstanceArray = new VertexPositionNormalTextureInstance[vertexGroup.Vertices.Count]; int index = 0; foreach (SharedVertex <VertexPositionNormalTextureInstance> sharedVertex in (IEnumerable <SharedVertex <VertexPositionNormalTextureInstance> >)vertexGroup.Vertices) { normalTextureInstanceArray[index] = sharedVertex.Vertex; normalTextureInstanceArray[index].TextureCoordinate = FezMath.ComputeTexCoord <VertexPositionNormalTextureInstance>(normalTextureInstanceArray[index], this.size) * new Vector2(1.333333f, 1f); sharedVertex.Index = index++; } int[] numArray = new int[dictionary.Count * 6]; int num = 0; foreach (FaceMaterialization <VertexPositionNormalTextureInstance> faceMaterialization in dictionary.Values) { for (ushort relativeIndex = (ushort)0; (int)relativeIndex < 6; ++relativeIndex) { numArray[num++] = faceMaterialization.GetIndex(relativeIndex); } } this.Geometry.Vertices = normalTextureInstanceArray; this.Geometry.Indices = numArray; if (this.artObject == null) { return; } this.PostInitialize(); }