コード例 #1
0
 private void InitializeSurfaces()
 {
     this.surfaces.Clear();
     foreach (FaceOrientation faceOrientation in Util.GetValues <FaceOrientation>())
     {
         TrixelEmplacement firstTrixel   = new TrixelEmplacement(FezMath.IsPositive(faceOrientation) ? FezMath.AsVector(faceOrientation) * (this.size * 16f - Vector3.One) : Vector3.Zero);
         TrixelSurface     trixelSurface = new TrixelSurface(faceOrientation, firstTrixel);
         Vector3           mask1         = FezMath.GetMask(FezMath.AsAxis(FezMath.GetTangent(faceOrientation)));
         int     num1  = (int)Vector3.Dot(this.size, mask1) * 16;
         Vector3 mask2 = FezMath.GetMask(FezMath.AsAxis(FezMath.GetBitangent(faceOrientation)));
         int     num2  = (int)Vector3.Dot(this.size, mask2) * 16;
         trixelSurface.RectangularParts.Add(new RectangularTrixelSurfacePart()
         {
             Orientation   = faceOrientation,
             TangentSize   = num1,
             BitangentSize = num2,
             Start         = firstTrixel
         });
         for (int index1 = 0; index1 < num1; ++index1)
         {
             for (int index2 = 0; index2 < num2; ++index2)
             {
                 trixelSurface.Trixels.Add(new TrixelEmplacement(firstTrixel + mask1 * (float)index1 + mask2 * (float)index2));
             }
         }
         this.surfaces.Add(trixelSurface);
     }
 }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }