Beispiel #1
0
        private void WriteColor(EndianBinaryWriter writer, List <Vector4> list, ColorDataTypes type)
        {
            foreach (Vector4 vec in list)
            {
                for (int i = 0; i < 3; i++)
                {
                    switch (type)
                    {
                    case ColorDataTypes.RGB8:
                    case ColorDataTypes.RGBA8:
                        float clampedVal = (float)Math.Max(0.0, Math.Min(1.0, vec[i]));
                        byte  colorByte  = (byte)Math.Floor(clampedVal == 1.0 ? 255 : clampedVal * 256.0);
                        writer.Write(colorByte);
                        break;
                    }
                }

                if ((int)type > 2)
                {
                    switch (type)
                    {
                    case ColorDataTypes.RGBA8:
                        writer.Write((byte)0xFF);
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates an instance of GeometryManager and loads the geometry data from it.
        /// </summary>
        /// <param name="scene">Source of geometry data</param>
        /// <param name="position">Datatype to use for position data</param>
        /// <param name="normal">Datatype to use for normal data</param>
        /// <param name="uv">Datatype to use for UV data</param>
        /// <param name="color">Datatype to use for color data</param>
        public GeometryManager(Grendgine_Collada scene, DrawData drw1, Matrix4 bindShape, DataTypes position = DataTypes.F32, DataTypes normal = DataTypes.F32,
                               DataTypes uv = DataTypes.F32, ColorDataTypes color = ColorDataTypes.RGBA8)
        {
            if (scene.Library_Geometries == null)
            {
                throw new FormatException("Mesh has no geometry!");
            }

            foreach (Grendgine_Collada_Geometry geom in scene.Library_Geometries.Geometry)
            {
                VertexData = new VertexData(geom.Mesh, bindShape, position, normal, uv, color);
                BatchData  = new BatchData(geom.Mesh, drw1);
                BatchData.SetBoundingBoxes(VertexData.Positions);
            }
        }
Beispiel #3
0
        public VertexData(Grendgine_Collada_Mesh mesh, Matrix4 bindShape, DataTypes position = DataTypes.F32, DataTypes normal = DataTypes.F32,
                          DataTypes uv = DataTypes.F32, ColorDataTypes color = ColorDataTypes.RGBA8)
        {
            Vertices = new List <Vertex>();

            Positions = new List <Vector3>();
            Normals   = new List <Vector3>();
            UVData    = new List <Vector2> [8];
            ColorData = new List <Vector4> [2];

            PositionType = position;
            NormalType   = normal;
            UVType       = uv;
            ColorType    = color;

            SortedAttributes = new List <VertexAttributes>();

            activeAttributes = new Dictionary <VertexAttributes, string>();
            GetActiveVertAttributes(mesh);
            FillAttributeLists(mesh);

            PositionFractionalBitVal = GetFractionalVec3(Positions);
            NormalFractionalBitVal   = GetFractionalVec3(Normals);
            UVFractionalBitVal       = 15;

            StringBuilder bld = new StringBuilder();

            bindPose = bindShape;

            foreach (List <Vector2> list2 in UVData)
            {
                if (list2 != null)
                {
                    for (int i = 0; i < list2.Count; i++)
                    {
                        Vector2 vec = list2[i];
                        vec.Y    = 1 - list2[i].Y;
                        list2[i] = vec;
                    }
                }
            }
        }
Beispiel #4
0
        public VertexData(Grendgine_Collada_Mesh mesh, DataTypes position = DataTypes.F32, DataTypes normal = DataTypes.F32,
                          DataTypes uv = DataTypes.F32, ColorDataTypes color = ColorDataTypes.RGB8)
        {
            Vertices = new List <Vertex>();

            Positions = new List <Vector3>();
            Normals   = new List <Vector3>();
            UVData    = new List <Vector2> [8];
            ColorData = new List <Vector3> [2];

            PositionType = position;
            NormalType   = normal;
            UVType       = uv;
            ColorType    = color;

            activeAttributes = new Dictionary <VertexAttributes, string>();
            GetActiveVertAttributes(mesh);
            FillAttributeLists(mesh);

            PositionFractionalBitVal = GetFractionalVec3(Positions);
            NormalFractionalBitVal   = GetFractionalVec3(Normals);
            UVFractionalBitVal       = 15;
        }