Esempio n. 1
0
        /// <summary>
        /// Create a new texture for BTEX, CTEX, etc. subchunks.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        static lwTexture get_texture(string s)
        {
            lwTexture tex = new lwTexture();

            tex.tmap.size.val[0]         =
                tex.tmap.size.val[1]     =
                    tex.tmap.size.val[2] = 1.0f;
            tex.opacity.val = 1.0f;
            tex.enabled     = 1;

            if (s.Contains("Image Map"))
            {
                tex.type = LWID.ID_IMAP;
                if (s.Contains("Planar"))
                {
                    tex.imap.projection = 0;
                }
                else if (s.Contains("Cylindrical"))
                {
                    tex.imap.projection = 1;
                }
                else if (s.Contains("Spherical"))
                {
                    tex.imap.projection = 2;
                }
                else if (s.Contains("Cubic"))
                {
                    tex.imap.projection = 3;
                }
                else if (s.Contains("Front"))
                {
                    tex.imap.projection = 4;
                }
                tex.imap.aa_strength   = 1.0f;
                tex.imap.amplitude.val = 1.0f;
            }
            else
            {
                tex.type      = LWID.ID_PROC;
                tex.proc.name = s;
            }

            return(tex);
        }
Esempio n. 2
0
        lwSurface GetSurface5(BinaryReader fp, int cksize, ref int flen)
        {
            lwSurface surf;
            lwTexture tex  = null;
            lwPlugin  shdr = null;
            string    s;

            float[] v = new float[3];
            uint    id, flags;
            ushort  sz;
            long    pos;
            int     i = 0;

            /* allocate the Surface structure */

            surf = new lwSurface();

            /* non-zero defaults */

            surf.color.rgb[0]   = 0.78431f;
            surf.color.rgb[1]   = 0.78431f;
            surf.color.rgb[2]   = 0.78431f;
            surf.diffuse.val    = 1.0f;
            surf.glossiness.val = 0.4f;
            surf.bump.val       = 1.0f;
            surf.eta.val        = 1.0f;
            surf.sideflags      = 1;

            /* remember where we started */

            flen = 0;
            pos  = fp.BaseStream.Position;

            /* name */

            surf.name = lwio.getS0(fp, ref flen);

            /* first subchunk header */

            id = lwio.getU4(fp, ref flen);
            sz = lwio.getU2(fp, ref flen);
            if (0 > flen)
            {
                goto Fail;
            }

            /* process subchunks as they're encountered */

            while (true)
            {
                sz  += (ushort)(sz & 1);
                flen = 0;

                switch (id)
                {
                case LWID.ID_COLR:
                    surf.color.rgb[0] = lwio.getU1(fp, ref flen) / 255.0f;
                    surf.color.rgb[1] = lwio.getU1(fp, ref flen) / 255.0f;
                    surf.color.rgb[2] = lwio.getU1(fp, ref flen) / 255.0f;
                    break;

                case ID_FLAG:
                    flags = lwio.getU2(fp, ref flen);
                    if ((flags & 4) > 0)
                    {
                        surf.smooth = 1.56207f;
                    }
                    if ((flags & 8) > 0)
                    {
                        surf.color_hilite.val = 1.0f;
                    }
                    if ((flags & 16) > 0)
                    {
                        surf.color_filter.val = 1.0f;
                    }
                    if ((flags & 128) > 0)
                    {
                        surf.dif_sharp.val = 0.5f;
                    }
                    if ((flags & 256) > 0)
                    {
                        surf.sideflags = 3;
                    }
                    if ((flags & 512) > 0)
                    {
                        surf.add_trans.val = 1.0f;
                    }
                    break;

                case LWID.ID_LUMI:
                    surf.luminosity.val = lwio.getI2(fp, ref flen) / 256.0f;
                    break;

                case ID_VLUM:
                    surf.luminosity.val = lwio.getF4(fp, ref flen);
                    break;

                case LWID.ID_DIFF:
                    surf.diffuse.val = lwio.getI2(fp, ref flen) / 256.0f;
                    break;

                case ID_VDIF:
                    surf.diffuse.val = lwio.getF4(fp, ref flen);
                    break;

                case LWID.ID_SPEC:
                    surf.specularity.val = lwio.getI2(fp, ref flen) / 256.0f;
                    break;

                case ID_VSPC:
                    surf.specularity.val = lwio.getF4(fp, ref flen);
                    break;

                case LWID.ID_GLOS:
                    surf.glossiness.val = (float)Math.Log(lwio.getU2(fp, ref flen)) / 20.7944f;
                    break;

                case LWID.ID_SMAN:
                    surf.smooth = lwio.getF4(fp, ref flen);
                    break;

                case LWID.ID_REFL:
                    surf.reflection.val.val = lwio.getI2(fp, ref flen) / 256.0f;
                    break;

                case ID_RFLT:
                    surf.reflection.options = lwio.getU2(fp, ref flen);
                    break;

                case LWID.ID_RIMG:
                    s = lwio.getS0(fp, ref flen);
                    surf.reflection.cindex  = add_clip(ref s, clip, ref nclips);
                    surf.reflection.options = 3;
                    break;

                case LWID.ID_RSAN:
                    surf.reflection.seam_angle = lwio.getF4(fp, ref flen);
                    break;

                case LWID.ID_TRAN:
                    surf.transparency.val.val = lwio.getI2(fp, ref flen) / 256.0f;
                    break;

                case LWID.ID_RIND:
                    surf.eta.val = lwio.getF4(fp, ref flen);
                    break;

                case ID_BTEX:
                    s   = BitConverter.ToString(lwio.getbytes(fp, sz, ref flen));
                    tex = get_texture(s);
                    surf.bump.tex.AddLast(tex);
                    break;

                case ID_CTEX:
                    s   = BitConverter.ToString(lwio.getbytes(fp, sz, ref flen));
                    tex = get_texture(s);
                    surf.color.tex.AddLast(tex);
                    break;

                case ID_DTEX:
                    s   = BitConverter.ToString(lwio.getbytes(fp, sz, ref flen));
                    tex = get_texture(s);
                    surf.diffuse.tex.AddLast(tex);
                    break;

                case ID_LTEX:
                    s   = BitConverter.ToString(lwio.getbytes(fp, sz, ref flen));
                    tex = get_texture(s);
                    surf.luminosity.tex.AddLast(tex);
                    break;

                case ID_RTEX:
                    s   = BitConverter.ToString(lwio.getbytes(fp, sz, ref flen));
                    tex = get_texture(s);
                    surf.reflection.val.tex.AddLast(tex);
                    break;

                case ID_STEX:
                    s   = BitConverter.ToString(lwio.getbytes(fp, sz, ref flen));
                    tex = get_texture(s);
                    surf.specularity.tex.AddLast(tex);
                    break;

                case ID_TTEX:
                    s   = BitConverter.ToString(lwio.getbytes(fp, sz, ref flen));
                    tex = get_texture(s);
                    surf.transparency.val.tex.AddLast(tex);
                    break;

                case ID_TFLG:
                    flags = lwio.getU2(fp, ref flen);

                    if ((flags & 1) > 0)
                    {
                        i = 0;
                    }
                    if ((flags & 2) > 0)
                    {
                        i = 1;
                    }
                    if ((flags & 4) > 0)
                    {
                        i = 2;
                    }
                    tex.axis = (short)i;
                    if (tex.type == LWID.ID_IMAP)
                    {
                        tex.imap.axis = i;
                    }
                    else
                    {
                        tex.proc.axis = i;
                    }

                    if ((flags & 8) > 0)
                    {
                        tex.tmap.coord_sys = 1;
                    }
                    if ((flags & 16) > 0)
                    {
                        tex.negative = 1;
                    }
                    if ((flags & 32) > 0)
                    {
                        tex.imap.pblend = 1;
                    }
                    if ((flags & 64) > 0)
                    {
                        tex.imap.aa_strength = 1.0f;
                        tex.imap.aas_flags   = 1;
                    }
                    break;

                case ID_TSIZ:
                    for (i = 0; i < 3; i++)
                    {
                        tex.tmap.size.val[i] = lwio.getF4(fp, ref flen);
                    }
                    break;

                case ID_TCTR:
                    for (i = 0; i < 3; i++)
                    {
                        tex.tmap.center.val[i] = lwio.getF4(fp, ref flen);
                    }
                    break;

                case ID_TFAL:
                    for (i = 0; i < 3; i++)
                    {
                        tex.tmap.falloff.val[i] = lwio.getF4(fp, ref flen);
                    }
                    break;

                case ID_TVEL:
                    for (i = 0; i < 3; i++)
                    {
                        v[i] = lwio.getF4(fp, ref flen);
                    }
                    tex.tmap.center.eindex = add_tvel(tex.tmap.center.val, v, env, ref nenvs);
                    break;

                case ID_TCLR:
                    if (tex.type == LWID.ID_PROC)
                    {
                        for (i = 0; i < 3; i++)
                        {
                            tex.proc.value[i] = lwio.getU1(fp, ref flen) / 255.0f;
                        }
                    }
                    break;

                case ID_TVAL:
                    tex.proc.value[0] = lwio.getI2(fp, ref flen) / 256.0f;
                    break;

                case ID_TAMP:
                    if (tex.type == LWID.ID_IMAP)
                    {
                        tex.imap.amplitude.val = lwio.getF4(fp, ref flen);
                    }
                    break;

                case ID_TIMG:
                    s = lwio.getS0(fp, ref flen);
                    tex.imap.cindex = add_clip(ref s, clip, ref nclips);
                    break;

                case ID_TAAS:
                    tex.imap.aa_strength = lwio.getF4(fp, ref flen);
                    tex.imap.aas_flags   = 1;
                    break;

                case ID_TREF:
                    tex.tmap.ref_object = BitConverter.ToString(lwio.getbytes(fp, sz, ref flen), sz);
                    break;

                case ID_TOPC:
                    tex.opacity.val = lwio.getF4(fp, ref flen);
                    break;

                case ID_TFP0:
                    if (tex.type == LWID.ID_IMAP)
                    {
                        tex.imap.wrapw.val = lwio.getF4(fp, ref flen);
                    }
                    break;

                case ID_TFP1:
                    if (tex.type == LWID.ID_IMAP)
                    {
                        tex.imap.wraph.val = lwio.getF4(fp, ref flen);
                    }
                    break;

                case LWID.ID_SHDR:
                    shdr      = new lwPlugin();
                    shdr.name = BitConverter.ToString(lwio.getbytes(fp, sz, ref flen));
                    surf.shader.AddLast(shdr);
                    surf.nshaders++;
                    break;

                case ID_SDAT:
                    shdr.data = lwio.getbytes(fp, sz, ref flen);
                    break;

                default:
                    break;
                }

                /* error while reading current subchunk? */

                if (flen < 0 || flen > sz)
                {
                    goto Fail;
                }

                /* skip unread parts of the current subchunk */

                if (flen < sz)
                {
                    fp.BaseStream.Seek(sz - flen, SeekOrigin.Current);
                }

                /* end of the SURF chunk? */

                if (cksize <= fp.BaseStream.Position - pos)
                {
                    break;
                }

                /* get the next subchunk header */

                flen = 0;
                id   = lwio.getU4(fp, ref flen);
                sz   = lwio.getU2(fp, ref flen);
                if (6 != flen)
                {
                    goto Fail;
                }
            }

            return(surf);

Fail:
            //if ( surf ) lwFreeSurface( surf );
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a new texture for BTEX, CTEX, etc. subchunks.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        static lwTexture get_texture(string s)
        {
            lwTexture tex = new lwTexture();

            tex.tmap.size.val[0] =
            tex.tmap.size.val[1] =
            tex.tmap.size.val[2] = 1.0f;
            tex.opacity.val = 1.0f;
            tex.enabled = 1;

            if (s.Contains("Image Map"))
            {
                tex.type = LWID.ID_IMAP;
                if (s.Contains("Planar")) tex.imap.projection = 0;
                else if (s.Contains("Cylindrical")) tex.imap.projection = 1;
                else if (s.Contains("Spherical")) tex.imap.projection = 2;
                else if (s.Contains("Cubic")) tex.imap.projection = 3;
                else if (s.Contains("Front")) tex.imap.projection = 4;
                tex.imap.aa_strength = 1.0f;
                tex.imap.amplitude.val = 1.0f;
            }
            else
            {
                tex.type = LWID.ID_PROC;
                tex.proc.name = s;
            }

            return tex;
        }