Exemple #1
0
        public static GfxObj Get(uint gfxObjID)
        {
            Requests++;

            //if (Requests % 100 == 0)
            //Console.WriteLine($"GfxObjCache: Requests={Requests}, Hits={Hits}");

            if (GfxObjs.TryGetValue(gfxObjID, out var result))
            {
                if (result.TryGetTarget(out var target))
                {
                    Hits++;
                    return(target);
                }
            }

            var _gfxObj = DBObj.GetGfxObj(gfxObjID);

            // not cached, add it
            var gfxObj = new GfxObj(_gfxObj);

            //gfxObj = GfxObjs.GetOrAdd(_gfxObj.Id, gfxObj);
            GfxObjs[_gfxObj.Id] = new WeakReference <GfxObj>(gfxObj);
            return(gfxObj);
        }
Exemple #2
0
 /// <summary>
 /// Calculates the lowest z-coordinate from all vertices
 /// For placing the model on the ground
 /// </summary>
 public void CalcLowestZ(GfxObj gfxObj)
 {
     foreach (var v in gfxObj.VertexArray.Vertices.Values)
     {
         LowestZ = Math.Min(v.Z, LowestZ);
     }
 }
Exemple #3
0
        public void DrawPointSprite(GfxObj gfxObj, PhysicsPart part, Texture2D texture)
        {
            GraphicsDevice.SetVertexBuffer(Billboard.VertexBuffer);
            GraphicsDevice.Indices = Billboard.IndexBuffer;

            var translateWorld = Matrix.CreateTranslation(part.Pos.Frame.Origin.ToXna()) * Matrix.CreateFromQuaternion(part.Pos.Frame.Orientation.ToXna());

            Effect.CurrentTechnique = Effect.Techniques["PointSprite"];
            Effect.Parameters["xWorld"].SetValue(translateWorld);
            Effect.Parameters["xTextures"].SetValue(texture);
            Effect.Parameters["xCamPos"].SetValue(Camera.Position);
            Effect.Parameters["xCamUp"].SetValue(Camera.Up);
            Effect.Parameters["xPointSpriteSizeX"].SetValue(part.GfxObjScale.X);
            Effect.Parameters["xPointSpriteSizeY"].SetValue(part.GfxObjScale.Y);
            Effect.Parameters["xOpacity"].SetValue(1.0f - part.CurTranslucency);

            foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
            {
                if (gfxObj.Surfaces[0].Type.HasFlag(SurfaceType.Additive))
                {
                    GraphicsDevice.BlendState = BlendState.Additive;
                }
                else
                {
                    GraphicsDevice.BlendState = BlendState.NonPremultiplied;
                }
                pass.Apply();

                GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 2);
            }
        }
Exemple #4
0
        public bool LoadGfxObjArray(uint rootObjectID /*, GfxObjDegradeInfo newDegrades*/)
        {
            var gfxObj = (DatLoader.FileTypes.GfxObj)DBObj.Get(new QualifiedDataID(6, rootObjectID));

            GfxObj = GfxObjCache.Get(gfxObj);
            // degrades omitted
            return(GfxObj != null);
        }
        public GfxObjInstance_Shared(GfxObj gfxObj, Dictionary <TextureFormat, TextureAtlasChain> textureAtlasChains, Dictionary <uint, uint> textureChanges = null, PaletteChanges paletteChanges = null)
        {
            GfxObj = gfxObj;

            BuildStatic(gfxObj, textureAtlasChains, textureChanges, paletteChanges);

            Instances = new List <VertexInstance>();
        }
Exemple #6
0
        public R_GfxObj(GfxObj gfxObj, Vector3 scale)
        {
            GfxObj = gfxObj;
            Scale  = scale;

            BuildVertices();
            BuildIndices();
        }
Exemple #7
0
 public bool MorphToExistingObject(PhysicsPart template)
 {
     // copy constructor?
     GfxObj      = template.GfxObj;
     GfxObjScale = template.GfxObjScale;
     Pos         = template.Pos;
     //DrawPos = template.DrawPos;
     //OriginalPaletteID = template.OriginalPaletteID;
     // removed surfaces
     return(true);
 }
        public void BuildStatic(GfxObj gfxObj, Dictionary <TextureFormat, TextureAtlasChain> textureAtlasChains, Dictionary <uint, uint> textureChanges = null, PaletteChanges paletteChanges = null)
        {
            BaseFormats_Solid = new Dictionary <TextureFormatChain, GfxObjInstance_TextureFormat>();

            BaseFormats_Alpha = new Dictionary <TextureFormatChain, GfxObjInstance_TextureFormat>();

            Vertices = new List <VertexPositionNormalTextures>();

            var vertexTable = new Dictionary <VertexPositionNormalTextures, short>();

            foreach (var poly in gfxObj.Polygons)
            {
                // get actual transformed texture -- cannot rely on poly.Texture original format
                var surfaceIdx = poly._polygon.PosSurface;
                var surfaceID  = gfxObj._gfxObj.Surfaces[surfaceIdx];

                var textureId = TextureCache.GetSurfaceTextureID(surfaceID, textureChanges);
                var texture   = TextureCache.Get(surfaceID, textureId, paletteChanges);

                var textureFormat = new TextureFormat(texture.Format, texture.Width, texture.Height, gfxObj.HasWrappingUVs);

                if (!textureAtlasChains.TryGetValue(textureFormat, out var textureAtlasChain))
                {
                    textureAtlasChain = new TextureAtlasChain(textureFormat);
                    textureAtlasChains.Add(textureFormat, textureAtlasChain);
                }

                var surface = DatManager.PortalDat.ReadFromDat <ACE.DatLoader.FileTypes.Surface>(surfaceID);

                var surfaceTextureId = TextureCache.GetSurfaceTextureID(surfaceID, textureChanges);

                var surfaceTexturePalette = new SurfaceTexturePalette(surfaceID, surfaceTextureId, paletteChanges);

                var atlasIdx = textureAtlasChain.GetAtlasIdx(surfaceTexturePalette);

                var textureAtlas = textureAtlasChain.TextureAtlases[atlasIdx];

                var baseFormats = (surface.Type & AlphaSurfaceTypes) == 0 ? BaseFormats_Solid : BaseFormats_Alpha;

                if (!baseFormats.TryGetValue(textureAtlas.TextureFormatChain, out var baseFormat))
                {
                    baseFormat = new GfxObjInstance_TextureFormat(textureAtlas);
                    baseFormats.Add(textureAtlas.TextureFormatChain, baseFormat);
                }

                var textureIdx = textureAtlas.Textures[surfaceTexturePalette];

                baseFormat.AddPolygon(poly, gfxObj.VertexArray, surfaceID, Vertices, vertexTable, textureIdx);
            }
        }
Exemple #9
0
        public bool MorphToExistingObject(PhysicsPart template)
        {
            GfxObj = template.GfxObj;   // TODO: deep copy
            var scale = new Vector3(template.GfxObjScale.X, template.GfxObjScale.Y, template.GfxObjScale.Z);

            Pos.ObjCellID = template.Pos.ObjCellID;
            // frame copy constructor?
            Pos.Frame         = template.Pos.Frame;
            DrawPos.ObjCellID = template.DrawPos.ObjCellID;
            DrawPos.Frame     = template.DrawPos.Frame;
            OriginalPaletteID = template.OriginalPaletteID;
            // removed surfaces
            return(true);
        }
Exemple #10
0
        public void DrawGfxObj(GfxObj gfxObj, PhysicsPart part, Texture2D texture)
        {
            if (gfxObj.VertexBuffer == null)
            {
                gfxObj.BuildVertexBuffer();
            }

            GraphicsDevice.SetVertexBuffer(gfxObj.VertexBuffer);

            var translateWorld = Matrix.CreateScale(part.GfxObjScale.ToXna()) * Matrix.CreateTranslation(part.Pos.Frame.Origin.ToXna()) * Matrix.CreateFromQuaternion(part.Pos.Frame.Orientation.ToXna());

            Effect.CurrentTechnique = Effect.Techniques["TexturedNoShading"];
            Effect.Parameters["xWorld"].SetValue(translateWorld);
            Effect.Parameters["xOpacity"].SetValue(1.0f - part.CurTranslucency);

            foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
            {
                foreach (var poly in gfxObj.Polygons)
                {
                    if (gfxObj.Surfaces[0].Type.HasFlag(SurfaceType.Additive))
                    {
                        GraphicsDevice.BlendState = BlendState.Additive;
                    }
                    else
                    {
                        GraphicsDevice.BlendState = BlendState.NonPremultiplied;
                    }
                    //GraphicsDevice.BlendState = BlendState.AlphaBlend;

                    if (poly.IndexBuffer == null)
                    {
                        poly.BuildIndexBuffer();
                    }

                    GraphicsDevice.Indices = poly.IndexBuffer;
                    Effect.Parameters["xTextures"].SetValue(poly.Texture);
                    pass.Apply();

                    var indexCnt = poly.Indices.Count;
                    GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indexCnt / 3);

                    /*if (poly._polygon.Vertices == null)
                     *  poly._polygon.LoadVertices(gfxObj._gfxObj.VertexArray);
                     *
                     * var vertexCnt = poly._polygon.Vertices.Count;
                     * GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, vertexCnt / 3);*/
                }
            }
        }
Exemple #11
0
        public static GfxObj Get(GfxObj gfxObj)
        {
            Requests++;

            //if (Requests % 100 == 0)
            //Console.WriteLine($"GfxObjCache: Requests={Requests}, Hits={Hits}");

            GfxObjs.TryGetValue(gfxObj.ID, out var result);
            if (result != null)
            {
                Hits++;
                return(result);
            }

            // not cached, add it
            GfxObjs.Add(gfxObj.ID, gfxObj);
            return(gfxObj);
        }
Exemple #12
0
        public static GfxObj Get(uint gfxObjID)
        {
            Requests++;

            //if (Requests % 100 == 0)
            //Console.WriteLine($"GfxObjCache: Requests={Requests}, Hits={Hits}");

            if (GfxObjs.TryGetValue(gfxObjID, out var result))
            {
                Hits++;
                return(result);
            }

            var _gfxObj = DBObj.GetGfxObj(gfxObjID);

            // not cached, add it
            var gfxObj = new GfxObj(_gfxObj);

            gfxObj = GfxObjs.GetOrAdd(_gfxObj.Id, gfxObj);
            return(gfxObj);
        }
Exemple #13
0
 public bool LoadGfxObjArray(uint rootObjectID /*, GfxObjDegradeInfo newDegrades*/)
 {
     GfxObj = GfxObjCache.Get(rootObjectID);
     // degrades omitted
     return(GfxObj != null);
 }