public void setBlock(byte x, byte y, byte z, Block b)
        {
            if (b.Type == BlockType.Water)
            {
                if (lowestNoneBlock.Y > y)
                {
                    lowestNoneBlock = new Vector3b(x, y, z);
                }
            }

            if (b.Type == BlockType.None)
            {
                if (lowestNoneBlock.Y > y)
                {
                    lowestNoneBlock = new Vector3b(x, y, z);
                }
            }
            else if (highestSolidBlock.Y < y)
            {
                highestSolidBlock = new Vector3b(x, y, z);
            }

            //comment this line : you should have nothing on screen, else you ve been setting blocks directly in array !
            Blocks[x * Chunk.FlattenOffset + z * Chunk.SIZE.Y + y] = b;
            dirty = true;
        }
Example #2
0
 public MyTexture(Bitmap bitmap)
 {
     this.File   = null;
     this.Bitmap = bitmap;
     this.TransparentColorUsed = false;
     this.TransparentColor     = Vector3b.Black;
 }
Example #3
0
 public MyTexture(string file, Vector3b transparentColor)
 {
     this.File   = file;
     this.Bitmap = null;
     this.TransparentColorUsed = true;
     this.TransparentColor     = transparentColor;
 }
Example #4
0
 public static Vector3b Cross(Vector3b v1, Vector3b v2)
 {
     return new Vector3b( (v1.y * v2.z) - (v1.z * v2.y),
                        (v1.z * v2.x) - (v1.x * v2.z),
                        (v1.x * v2.y) - (v1.y * v2.x)
                      );
 }
Example #5
0
 public MyTexture(string file)
 {
     this.File   = file;
     this.Bitmap = null;
     this.TransparentColorUsed = false;
     this.TransparentColor     = Vector3b.Black;
 }
Example #6
0
 public static Vector3b Cross(Vector3b v1, Vector3b v2)
 {
     return(new Vector3b((v1.y * v2.z) - (v1.z * v2.y),
                         (v1.z * v2.x) - (v1.x * v2.z),
                         (v1.x * v2.y) - (v1.y * v2.x)
                         ));
 }
Example #7
0
		// --- constructors ---
		
		internal MeshBuilder() {
			this.Vertices = new List<MeshBuilderVertex>();
			this.Faces = new List<MeshBuilderFace>();
			this.DaytimeTexture = null;
			this.TransparentColor = Vector3b.Black;
			this.TransparentColorUsed = false;
		}
Example #8
0
 public static Vector3b operator *(Vector3b v1, double factor)
 {
     Vector3b result = new Vector3b( v1.x * factor,
                                 v1.y * factor,
                                 v1.z * factor
                                );
     return result;
 }
Example #9
0
        // --- constructors ---

        internal MeshBuilder()
        {
            this.Vertices             = new List <MeshBuilderVertex>();
            this.Faces                = new List <MeshBuilderFace>();
            this.DaytimeTexture       = null;
            this.TransparentColor     = Vector3b.Black;
            this.TransparentColorUsed = false;
        }
Example #10
0
        public static Vector3b operator *(Vector3b v1, double factor)
        {
            Vector3b result = new Vector3b(v1.x * factor,
                                           v1.y * factor,
                                           v1.z * factor
                                           );

            return(result);
        }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Vector8b"/> using the specified vector and values.
 /// </summary>
 /// <param name="value">A vector containing the values with which to initialize the first 3 components</param>
 /// <param name="v3">Value for the V3 component of the vector.</param>
 /// <param name="v4">Value for the V4 component of the vector.</param>
 /// <param name="v5">Value for the V5 component of the vector.</param>
 /// <param name="v6">Value for the V6 component of the vector.</param>
 /// <param name="v7">Value for the V7 component of the vector.</param>
 public Vector8b(Vector3b value, byte v3, byte v4, byte v5, byte v6, byte v7, byte v8, byte v9, byte v10)
 {
     V0 = value.X;
     V1 = value.Y;
     V2 = value.Z;
     V3 = v3;
     V4 = v4;
     V5 = v5;
     V6 = v6;
     V7 = v7;
 }
Example #12
0
        public Texture2DArray(GL gl, Vector3i size, WrapMode wrapMode, FilterMode filterMode) : base(gl, TextureTarget.Texture2DArray)
        {
            if (Vector3b.Any(size < 0))
            {
                throw new ArgumentOutOfRangeException(nameof(size), "All components must be >=0");
            }

            Size = size;

            AssignPixelFormats <TPixel>();
            AssignTextureParameters(GetWrapModeAsGLEnum(wrapMode), GetFilterModeAsGLEnum(filterMode));
            GL.TextureStorage3D(Handle, 1, _InternalFormat, (uint)size.X, (uint)size.Y, (uint)size.Z);
        }
Example #13
0
        public void SetPixels(Vector3i offset, Vector3i size, ReadOnlySpan <TPixel> pixels)
        {
            if (Vector3b.Any(offset < 0))
            {
                throw new ArgumentOutOfRangeException(nameof(size), "All components must be >=0");
            }
            else if (Vector3b.Any(size < 0))
            {
                throw new ArgumentOutOfRangeException(nameof(size), "All components must be >=0 and <TexSize");
            }

            GL.TextureSubImage3D(Handle, 0, offset.X, offset.Y, offset.Z, (uint)size.X, (uint)size.Y, (uint)size.Z, _PixelFormat, _PixelType, pixels);
        }
Example #14
0
            public override Texture Add(string file, Vector3b transparentColor)
            {
                MyTexture t = new MyTexture(file, transparentColor);

                for (int i = 0; i < this.Textures.Count; i++)
                {
                    if (this.Textures[i].Equals(t))
                    {
                        return(this.Textures[i]);
                    }
                }
                this.Textures.Add(t);
                return(this.Textures[this.Textures.Count - 1]);
            }
Example #15
0
			public MyTexture(Bitmap bitmap) {
				this.File = null;
				this.Bitmap = bitmap;
				this.TransparentColorUsed = false;
				this.TransparentColor = Vector3b.Black;
			}
Example #16
0
 public static double Dot(Vector3b v1, Vector3b v2)
 {
     return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
 }
Example #17
0
 public static double Dot(Vector3b v1, Vector3b v2)
 {
     return((v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z));
 }
Example #18
0
        /// <summary>
        /// Builds CTR model from raw data arrays.
        /// </summary>
        /// <param name="name">Model name.</param>
        /// <param name="vertices">Vertex array.</param>
        /// <param name="colors">Color array.</param>
        /// <param name="faces">Face indices array.</param>
        /// <returns>CtrHeader object.</returns>
        public static CtrMesh FromRawData(string name, List <Vector3f> vertices, List <Vector4b> colors, List <Vector3i> faces)
        {
            CtrMesh model = new CtrMesh();

            model.name        = name + "_hi";
            model.lodDistance = -1;

            List <Vector4b> cc = new List <Vector4b>();

            foreach (var c in colors)
            {
                System.Drawing.Color cl = Tim.Convert16(Tim.ConvertTo16(System.Drawing.Color.FromArgb(c.W, c.Z, c.Y, c.X)), false);

                if (cl.R == 255 && cl.G == 0 && cl.B == 255)
                {
                    cl = System.Drawing.Color.Black;
                }

                cc.Add(new Vector4b(cl.R, cl.G, cl.B, 0));
            }

            colors = cc;

            //get distinct values from input lists
            List <Vector3f> dVerts  = new List <Vector3f>();
            List <Vector4b> dColors = new List <Vector4b>();

            foreach (var v in vertices)
            {
                if (!dVerts.Contains(v))
                {
                    dVerts.Add(v);
                }
            }

            foreach (var c in colors)
            {
                if (!dColors.Contains(c))
                {
                    dColors.Add(c);
                }
            }


            //recalculate indices for distinct arrays
            List <Vector3i> vfaces = new List <Vector3i>();
            List <Vector3i> cfaces = new List <Vector3i>();

            if (dVerts.Count != vertices.Count)
            {
                foreach (var f in faces)
                {
                    vfaces.Add(new Vector3i(
                                   dVerts.IndexOf(vertices[f.X]),
                                   dVerts.IndexOf(vertices[f.Y]),
                                   dVerts.IndexOf(vertices[f.Z])
                                   ));
                }
            }

            if (dColors.Count != colors.Count)
            {
                foreach (var f in faces)
                {
                    cfaces.Add(new Vector3i(
                                   dColors.IndexOf(colors[f.X]),
                                   dColors.IndexOf(colors[f.Y]),
                                   dColors.IndexOf(colors[f.Z])
                                   ));
                }
            }

            if (vfaces.Count == 0)
            {
                vfaces = faces;
            }
            if (cfaces.Count == 0)
            {
                cfaces = faces;
            }

            int clutlimit = 128;

            //check for clut overflow
            if (dColors.Count > clutlimit)
            {
                Helpers.Panic("CtrHeader", "More than 128 distinct colors! Truncating...");
                dColors = dColors.GetRange(0, clutlimit);

                foreach (var x in cfaces)
                {
                    if (x.X >= clutlimit)
                    {
                        x.X = 0;
                    }
                    if (x.Y >= clutlimit)
                    {
                        x.Y = 0;
                    }
                    if (x.Z >= clutlimit)
                    {
                        x.Z = 0;
                    }
                }
            }


            //get bbox
            BoundingBox bb = BoundingBox.GetBB(dVerts);

            //offset the bbox to world origin
            BoundingBox bb2 = bb - bb.minf;

            //offset all vertices to world origin
            for (int i = 0; i < dVerts.Count; i++)
            {
                dVerts[i] -= bb.minf;
            }

            //save converted offset to model
            model.posOffset = new Vector4s(
                (short)(bb.minf.X / bb2.maxf.X * 255),
                (short)(bb.minf.Y / bb2.maxf.Y * 255),
                (short)(bb.minf.Z / bb2.maxf.Z * 255),
                0);

            //save scale to model
            model.scale = new Vector4s(
                (short)(bb2.maxf.X * 1000f),
                (short)(bb2.maxf.Y * 1000f),
                (short)(bb2.maxf.Z * 1000f),
                0);


            //compress vertices to byte vector
            model.vtx.Clear();

            foreach (var v in dVerts)
            {
                Vector3b vv = new Vector3b(
                    (byte)(v.X / bb2.maxf.X * 255),
                    (byte)(v.Z / bb2.maxf.Z * 255),
                    (byte)(v.Y / bb2.maxf.Y * 255)
                    );

                model.vtx.Add(vv);
            }


            //save colors
            if (dColors.Count > 0)
            {
                model.cols = dColors;
            }
            else
            {
                model.cols.Add(new Vector4b(0x40, 0x40, 0x40, 0));
                model.cols.Add(new Vector4b(0x80, 0x80, 0x80, 0));
                model.cols.Add(new Vector4b(0xC0, 0xC0, 0xC0, 0));
            }


            //create new vertex array and loop through all faces
            List <Vector3b> newlist = new List <Vector3b>();

            for (int i = 0; i < faces.Count; i++)
            {
                CtrDraw[] cmd = new CtrDraw[3];

                cmd[0] = new CtrDraw()
                {
                    texIndex   = 0,
                    colorIndex = (byte)cfaces[i].X,
                    stackIndex = 87,
                    flags      = CtrDrawFlags.s | CtrDrawFlags.d //| CtrDrawFlags.k
                };

                cmd[1] = new CtrDraw()
                {
                    texIndex   = 0,
                    colorIndex = (byte)cfaces[i].Z,
                    stackIndex = 88,
                    flags      = CtrDrawFlags.d //| CtrDrawFlags.k
                };

                cmd[2] = new CtrDraw()
                {
                    texIndex   = 0,
                    colorIndex = (byte)cfaces[i].Y,
                    stackIndex = 89,
                    flags      = CtrDrawFlags.d //| CtrDrawFlags.k
                };

                newlist.Add(model.vtx[vfaces[i].X]);
                newlist.Add(model.vtx[vfaces[i].Z]);
                newlist.Add(model.vtx[vfaces[i].Y]);

                model.drawList.AddRange(cmd);
            }

            model.vtx = newlist;

            return(model);
        }
Example #19
0
 /// <summary>Read a <see cref="Vector3b"/>.</summary>
 public static void ReadVector3b(this BinaryReader reader , out Vector3b result)
 {
     result.X = reader.ReadByte();
                                 result.Y = reader.ReadByte();
                                 result.Z = reader.ReadByte();
             return;
 }
Example #20
0
 /// <summary>Read an array of <c>Vector3b</c> values.</summary>
 public static Vector3b[] ReadArrayVector3b(this BinaryReader reader, int count)
 {
     Vector3b[] array = new Vector3b[count]; reader.ReadArray(array, 0, count); return array;
 }
Example #21
0
 public abstract Texture Add(string file, Vector3b transparentColor);
Example #22
0
			public override Texture Add(string file, Vector3b transparentColor) {
				MyTexture t = new MyTexture(file, transparentColor);
				for (int i = 0; i < this.Textures.Count; i++) {
					if (this.Textures[i].Equals(t)) {
						return this.Textures[i];
					}
				}
				this.Textures.Add(t);
				return this.Textures[this.Textures.Count - 1];
			}
Example #23
0
		public abstract Texture Add(string file, Vector3b transparentColor);
Example #24
0
			public MyTexture(string file) {
				this.File = file;
				this.Bitmap = null;
				this.TransparentColorUsed = false;
				this.TransparentColor = Vector3b.Black;
			}
Example #25
0
			public MyTexture(string file, Vector3b transparentColor) {
				this.File = file;
				this.Bitmap = null;
				this.TransparentColorUsed = true;
				this.TransparentColor = transparentColor;
			}