Esempio n. 1
0
        public LevelTerrain(string name, LevelFile levelRes, AtlasMaterial material) : base()
        {
            Name          = name;
            this.levelRes = levelRes;

            TintColor = new Vector4(1, 1, 1, 0);

            this.material = material;
            if (!material.Ready)
            {
                return;
            }

            if (setupGeometry())
            {
                Log.WriteLine("HiOctane Terrain '" + name + "' loaded " +
                              positionVboData.Length + " vertices, " +
                              normalVboData.Length + " normals, " +
                              uvVboData.Length + " UVs, " +
                              indicesVboData.Length + " indices");

                createVBOs();
                createVAOs();

                ready = true;
            }
            else
            {
                Log.WriteLine(Log.LOG_ERROR, "failed setting up game model '" + Name + "'");
            }
        }
Esempio n. 2
0
        /*
         * public Bitmap PreviewImage(AtlasMaterial atlas, Size size)
         * {
         *  Bitmap result = new Bitmap(size.Width, size.Height);
         *  Size halfSize = new Size((int)Math.Floor((float)size.Width * 0.5f), size.Height);
         *
         *  Graphics gfx = Graphics.FromImage(result);
         *  gfx.Clear(Color.Transparent);
         *
         *  gfx.DrawImage(PreviewImageTop(atlas, halfSize), new Point(0, 0));
         *  gfx.DrawImage(PreviewImageBottom(atlas, halfSize), new Point(halfSize.Width, 0));
         *
         *  gfx.Dispose();
         *
         *  return result;
         * }*/

        public Bitmap PreviewImageTop(AtlasMaterial atlas, Size size)
        {
            // top view
            Bitmap result = new Bitmap(size.Width, size.Height);

            Graphics gfx = Graphics.FromImage(result);

            gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //gfx.Clear(Color.Transparent);

            Point center = new Point(size.Width / 2, size.Height / 2);

            Point[] corners = new Point[3];

            corners[0] = center;
            corners[1] = new Point(center.X + 55, center.Y - 32);
            corners[2] = new Point(center.X, center.Y + 64);
            gfx.DrawImage(atlas.Get(S, SMod), corners);

            corners[0] = new Point(center.X - 55, center.Y - 32);
            corners[1] = center;
            corners[2] = new Point(center.X - 55, center.Y + 32);
            gfx.DrawImage(atlas.Get(W, WMod), corners);

            corners[0] = center;
            corners[1] = new Point(center.X - 55, center.Y - 32);
            corners[2] = new Point(center.X + 55, center.Y - 32);
            gfx.DrawImage(atlas.Get(T, TMod), corners);

            gfx.Dispose();

            return(result);
        }
Esempio n. 3
0
        public Column(ColumnDefinition def, Vector3 pos, LevelFile levelRes, AtlasMaterial material)
            : base()
        {
            Name          = "Column at " + pos.X + "/" + pos.Z;
            this.levelRes = levelRes;
            Definition    = def;
            Position      = pos;

            TintColor = new Vector4(1.0f, 0.0f, 0.0f, 0.0f); // alpha is intensity

            this.material = material;
            if (!material.Ready)
            {
                return;
            }

            if (setupGeometry())
            {
                Log.WriteLine("HiOctane '" + Name + "' loaded " +
                              positionVboData.Length + " vertices, " +
                              normalVboData.Length + " normals, " +
                              uvVboData.Length + " UVs, " +
                              indicesVboData.Length + " indices");

                createVBOs();
                createVAOs();

                ready = true;
            }
            else
            {
                Log.WriteLine(Log.LOG_ERROR, "failed setting up game model '" + Name + "'");
            }
        }
Esempio n. 4
0
    public void InitCombinedFloor(CombineInstance[] combine, int atlasIndex)
    {
        MeshFilter filter = this.GetComponent <MeshFilter>();

        filter.mesh = new Mesh();
        filter.mesh.CombineMeshes(combine);

        this.gameObject.SetActive(true);
        this.gameObject.isStatic = true;

        AtlasMaterial material = this.gameObject.GetComponent <AtlasMaterial>();

        material.uvTieX       = 16;
        material.uvTieY       = 16;
        material.initialIndex = atlasIndex;
        material.maxIndex     = material.initialIndex;
        material.fps          = 0;
    }
Esempio n. 5
0
    private void Start()
    {
        if (this.surface == null)
        {
            this.enabled = false;
            return;
        }
        if (this.shadow == null)
        {
            this.enabled = false;
            return;
        }

        this.surfaceAtlasRef = this.surface.GetComponent <AtlasMaterial>();
        if (this.surfaceAtlasRef == null)
        {
            this.enabled = false;
            return;
        }

        this.shadowAtlasRef = this.shadow.GetComponent <AtlasMaterial>();
        if (this.shadowAtlasRef == null)
        {
            this.enabled = false;
            return;
        }

        this.surfaceBillboardRef = this.surface.GetComponent <Billboard>();
        if (this.surfaceBillboardRef == null)
        {
            this.enabled = false;
            return;
        }

        if (this.data.type == -1)
        {
            this.data.type = this.initialType;
        }

        this.Turn(this.initialDirection);
    }
Esempio n. 6
0
        protected override bool setup()
        {
            #region setup world
            // scene light
            Vector3 lightDir = new Vector3(1f, -1f, 1f);
            light = new DirectionalLight(lightDir.Normalized(), new Vector3(1, 1, 1));
            AddLight(light);

            // shadow material (unused)
            //ShadowMaterial = new ShadowMaterial();
            //if (!ShadowMaterial.Ready) return false;

            // create skysphere
            skySphere = new SkySphere(2000f, 2);
            if (!skySphere.Ready)
            {
                return(false);
            }
            AddNode(skySphere);

            // load level file
            Data = new LevelFile(Config.DATA_FOLDER + "maps/level0-" + levelNumber + ".dat");
            if (!Data.Ready)
            {
                return(false);
            }

            Name = Data.Name;

            // load level atlas texture file
            int atlasNumber = levelNumber;
            if (levelNumber == 7)
            {
                atlasNumber = 1;                   // original game has this hardcoded too
            }
            Atlas = new AtlasMaterial("images/level0-" + atlasNumber + ".png", false);
            if (!Atlas.Ready)
            {
                return(false);
            }

            // create terrain
            Terrain = new LevelTerrain("Terrain Level " + levelNumber, Data, Atlas);
            if (!Terrain.Ready)
            {
                return(false);
            }
            AddNode(Terrain);

            // player (camera controller really)
            Camera = new CameraController(new Vector3(6f, Terrain.Size.Y + 6f, 6f), new Vector3(10f, Terrain.Size.Y + 5f, 10f));

            // create building node and add columns
            Buildings = new SceneNode();
            AddNode(Buildings);

            columnsByPosition = new Dictionary <int, Column>();

            foreach (var columnPosPair in Data.Columns)
            {
                addColumn(columnPosPair.Value, columnPosPair.Key);
            }

            // create entities and link columns with their morph source
            createEntities();
            #endregion

            #region temporary

            /*
             * mouseLine = new Line(Vector3.Zero, Vector3.UnitZ, new Vector4(1, 1, 1, 1));
             * AddNode(mouseLine);
             *
             */

            /*
             * Craft craft = new Craft("JET0-0", box.Position);
             * AddNode(craft);
             */

            // level bounds rectangle

            /*
             * Line line;
             * line = new Line(new Vector3(0f, Terrain.Size.Y, 0f), new Vector3(256f, Terrain.Size.Y, 0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f));
             * if (!line.Ready) return false;
             * line.Extend(new Vector3(256f, Terrain.Size.Y, 160f)).Extend(new Vector3(0f, Terrain.Size.Y, 160f)).Extend(line.A);
             * AddNode(line);
             */
            #endregion

            #region helpers
            // X / Y / Z
            AddNode(new Line(new Vector3(0f, 0f, 0f), new Vector3(20f, 0f, 0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f)));
            AddNode(new Line(new Vector3(0f, 0f, 0f), new Vector3(0f, 20f, 0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f)));
            AddNode(new Line(new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 20f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)));

            // setup collision helper for superfast Hi-Octane world box collisions
            Collisions = new LevelCollision(this, Data);
            #endregion
            return(true);
        }
Esempio n. 7
0
        public void RegistrationComplete()
        {
            IEnumerable <Block> blocks = RegisteredBlocks.Select(kv => kv.Value.Block);

            Texture2D noTexture = (Texture2D)Resources.Load("notexture");

            noTexture.name = "notexture";

            //Figure out what blocks will get what UV
            List <string> texturesToLoad = new List <string>();

            foreach (Block b in blocks)
            {
                foreach (string texture in b.Data.TextureNames)
                {
                    if (texture == "notexture")
                    {
                        continue;                         //Skip 'notexture' textures, because are are already going to load
                    }
                    //those
                    if (!texturesToLoad.Contains(texture))
                    {
                        texturesToLoad.Add(texture);
                    }
                }
            }

            //Load each of the textures, make sure they are square and a power of 2 between 32 and 512.
            List <Texture2D> LoadedTextures    = new List <Texture2D>();
            List <string>    NotLoadedTextures = new List <string>();

            LoadedTextures.Add(noTexture);
            foreach (string t in texturesToLoad)
            {
                if (t == "notexture")
                {
                    continue;
                }
                Texture2D loadedTexture = (Texture2D)Resources.Load(t);
                loadedTexture.name = t;
                if (loadedTexture.width != loadedTexture.height)
                {
                    Debug.Log(string.Format("Texture {0} is not square!", t));
                    NotLoadedTextures.Add(t);
                    continue;
                }
                if (loadedTexture.width < 32 || loadedTexture.width > 512)
                {
                    Debug.Log(string.Format("Texture {0} must be a power of 2 between 32 and 512", t));
                    NotLoadedTextures.Add(t);
                    continue;
                }
                if (!Mathf.IsPowerOfTwo(loadedTexture.width))
                {
                    Debug.Log(string.Format("Texture {0} must be a power of 2 between 32 and 512", t));
                    NotLoadedTextures.Add(t);
                    continue;
                }

                LoadedTextures.Add(loadedTexture);
            }

            //Load and pack the textures
            for (int i = 32; i <= 512; i = i * 2)
            {
                IEnumerable <Texture2D> TexturesOfThisSize = LoadedTextures.Where(t => t.width == i);
                if (TexturesOfThisSize.Count() == 0)
                {
                    continue;
                }

                //Pack them into an atlas
                Texture2D atlas = new Texture2D(1024, 1024, TextureFormat.ARGB32, true, false);
                atlas.anisoLevel = 9;
                atlas.mipMapBias = -.5f;
                atlas.filterMode = FilterMode.Point;
                float percent    = 1f / 8f;
                float atlasWidth = atlas.PackTexturesWithTiling(TexturesOfThisSize.ToArray(), percent, 1024, false);
                atlas.Apply(true);

                AtlasSize thisSize = (AtlasSize)Enum.Parse(typeof(AtlasSize), "_" + i);
                Debug.Log("Building Atlas of size " + thisSize.ToString());

                TextureAtlases[thisSize] = new TextureAtlasLookup()
                {
                    Atlas = atlas,
                    TextureNamesInThisAtlas = TexturesOfThisSize.Select(t => t.name).ToList(),
                    CopyPercent             = percent,
                    PalleteSize             = atlasWidth,
                };
            }

            //Go through the loaded names and assign IDs and Blocks to them.
            foreach (Block b in blocks)
            {
                List <int>       Ids            = new List <int>();
                List <AtlasSize> atlasLocations = new List <AtlasSize>();
                //Find which atlas each block's texture is in
                for (int i = 0; i < 6; i++)
                {
                    string textureName = b.Data.TextureNames[i];

                    //If we have a notexture or failed to load, index directly into 'notexture'
                    if (textureName == "notexture" || NotLoadedTextures.Contains(textureName))
                    {
                        Ids.Add(0); //notexture is the first texture in the 32sized array
                        atlasLocations.Add(AtlasSize._32);
                        continue;
                    }


                    //Find which atlas this texture is in
                    AtlasSize containingAtlas = AtlasSize._32;
                    foreach (KeyValuePair <AtlasSize, TextureAtlasLookup> kv in TextureAtlases)
                    {
                        if (kv.Value.TextureNamesInThisAtlas.Contains(textureName))
                        {
                            containingAtlas = kv.Key;
                            break;
                        }
                    }
                    atlasLocations.Add(containingAtlas);

                    //Find what position it's in
                    int index = TextureAtlases[containingAtlas].TextureNamesInThisAtlas.IndexOf(textureName);
                    Ids.Add(index);
                }

                b.Data.TextureIDs = Ids.ToArray();
                Debug.Log("block:" + b.Data.DisplayName);
                Debug.Log("TextureIds: " + string.Join(",", b.Data.TextureIDs.Select(x => x.ToString()).ToArray()));
                b.Data.AtlasLocations = atlasLocations.ToArray();
            }

            //Set up the material
            AtlasMaterial = (Material)Resources.Load("MCMaterial");
            AtlasMaterial.SetTexture("_Atlas32", TextureAtlases[AtlasSize._32].Atlas);
            AtlasMaterial.SetFloat("_PERCENT", TextureAtlases[AtlasSize._32].CopyPercent);
            AtlasMaterial.SetFloat("_PALLETESIZE", TextureAtlases[AtlasSize._32].PalleteSize);



            foreach (Block b in RegisteredBlocks.Values.Select(x => x.Block))
            {
                b.Data.RenderMaterial = AtlasMaterial;
            }
        }