Example #1
0
        public Hashtable Import3Ds(string name, string path, bool addtoscene)
        {
            if (_scene == null)
            {
                return(null);
            }

            Hashtable         list   = null;
            warp_3ds_Importer studio = new warp_3ds_Importer();

            try
            {
                list = studio.importFromFile(name, path);

                if (addtoscene)
                {
                    foreach (DictionaryEntry myDE in list)
                    {
                        string      key = (string)myDE.Key;
                        warp_Object o   = (warp_Object)myDE.Value;

                        _scene.addObject(key, o);
                    }
                }

                _scene.rebuild();
                _models.Add(name, list);
            }
            catch (Exception)
            {
                return(null);
            }

            return(list);
        }
Example #2
0
 public void addObject(String key, warp_Object obj)
 {
     obj.name = key;
     objectData.Add(key, obj);
     obj.parent           = this;
     objectsNeedRebuild   = true;
     preparedForRendering = false;
 }
Example #3
0
        public warp_FXLensFlare(String name, warp_Scene scene, bool zBufferSensitive) : base(scene)
        {
            this.zBufferSensitive = zBufferSensitive;

            flareObject = new warp_Object();
            flareObject.addVertex(new warp_Vertex(1f, 1f, 1f));
            flareObject.rebuild();

            scene.addObject(name, flareObject);
        }
Example #4
0
        public static void projectCylindric(warp_Object obj)
        {
            obj.rebuild();
            warp_Vector min = obj.minimum();
            warp_Vector max = obj.maximum();
            float       dz  = 1 / (max.z - min.z);

            for (int i = 0; i < obj.vertices; i++)
            {
                obj.fastvertex[i].pos.buildCylindric();
                obj.fastvertex[i].u = obj.fastvertex[i].pos.theta / (2 * 3.14159265f);
                obj.fastvertex[i].v = (obj.fastvertex[i].pos.z - min.z) * dz;
            }
        }
Example #5
0
        public static void projectFrontal(warp_Object obj)
        {
            obj.rebuild();
            warp_Vector min = obj.minimum();
            warp_Vector max = obj.maximum();
            float       du  = 1 / (max.x - min.x);
            float       dv  = 1 / (max.y - min.y);

            for (int i = 0; i < obj.vertices; i++)
            {
                obj.fastvertex[i].u = (obj.fastvertex[i].pos.x - min.x) * du;
                obj.fastvertex[i].v = 1 - (obj.fastvertex[i].pos.y - min.y) * dv;
            }
        }
Example #6
0
        public static warp_Object BOX(float xsize, float ysize, float zsize)
        {
            float x = (float)Math.Abs(xsize / 2);
            float y = (float)Math.Abs(ysize / 2);
            float z = (float)Math.Abs(zsize / 2);

            float xx, yy, zz;

            warp_Object n = new warp_Object();

            int[] xflag = new int[6];
            int[] yflag = new int[6];
            int[] zflag = new int[6];

            xflag[0] = 10;
            yflag[0] = 3;
            zflag[0] = 0;
            xflag[1] = 10;
            yflag[1] = 15;
            zflag[1] = 3;
            xflag[2] = 15;
            yflag[2] = 3;
            zflag[2] = 10;
            xflag[3] = 10;
            yflag[3] = 0;
            zflag[3] = 12;
            xflag[4] = 0;
            yflag[4] = 3;
            zflag[4] = 5;
            xflag[5] = 5;
            yflag[5] = 3;
            zflag[5] = 15;

            for (int side = 0; side < 6; side++)
            {
                for (int i = 0; i < 4; i++)
                {
                    xx = ((xflag[side] & (1 << i)) > 0) ? x : -x;
                    yy = ((yflag[side] & (1 << i)) > 0) ? y : -y;
                    zz = ((zflag[side] & (1 << i)) > 0) ? z : -z;
                    n.addVertex(xx, yy, zz, i & 1, (i & 2) >> 1);
                }
                int t = side << 2;
                n.addTriangle(t, t + 2, t + 3);
                n.addTriangle(t, t + 3, t + 1);
            }

            return(n);
        }
Example #7
0
        public static warp_Object ROTATIONOBJECT(warp_Vector[] path, int sides)
        {
            int         steps = sides + 1;
            warp_Object newObject = new warp_Object();
            double      alpha = 2 * pi / ((double)steps - 1);
            float       qx, qz;
            int         nodes = path.GetLength(0);
            warp_Vertex vertex = null;
            float       u, v;       // Texture coordinates

            for (int j = 0; j < steps; j++)
            {
                u = (float)(steps - j - 1) / (float)(steps - 1);
                for (int i = 0; i < nodes; i++)
                {
                    v  = (float)i / (float)(nodes - 1);
                    qx = (float)(path[i].x * Math.Cos(j * alpha) +
                                 path[i].z * Math.Sin(j * alpha));
                    qz = (float)(path[i].z * Math.Cos(j * alpha) -
                                 path[i].x * Math.Sin(j * alpha));
                    vertex   = new warp_Vertex(qx, path[i].y, qz);
                    vertex.u = u;
                    vertex.v = v;
                    newObject.addVertex(vertex);
                }
            }

            for (int j = 0; j < steps - 1; j++)
            {
                for (int i = 0; i < nodes - 1; i++)
                {
                    newObject.addTriangle(i + nodes * j, i + nodes * (j + 1),
                                          i + 1 + nodes * j);
                    newObject.addTriangle(i + nodes * (j + 1),
                                          i + 1 + nodes * (j + 1),
                                          i + 1 + nodes * j);
                }
            }

            for (int i = 0; i < nodes - 1; i++)
            {
                newObject.addTriangle(i + nodes * (steps - 1), i,
                                      i + 1 + nodes * (steps - 1));
                newObject.addTriangle(i, i + 1, i + 1 + nodes * (steps - 1));
            }
            return(newObject);
        }
Example #8
0
        public bool ProjectCylindric(string name)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = _scene.sceneobject(name);

            if (o == null)
            {
                return(false);
            }

            warp_TextureProjector.projectCylindric(o);

            return(true);
        }
Example #9
0
        public bool ScaleObject(string name, float s)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = _scene.sceneobject(name);

            if (o == null)
            {
                return(false);
            }

            o.scale(s);

            return(true);
        }
Example #10
0
        public bool AddPlane(string name, float size, bool doubleSide)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = warp_ObjectFactory.SIMPLEPLANE(size, doubleSide);

            if (o == null)
            {
                return(false);
            }

            _scene.addObject(name, o);

            return(true);
        }
Example #11
0
        public bool RotateSelf(string name, warp_Matrix m)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = _scene.sceneobject(name);

            if (o == null)
            {
                return(false);
            }

            o.rotateSelf(m);

            return(true);
        }
Example #12
0
        public bool RotateSelf(string name, warp_Quaternion quat)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = _scene.sceneobject(name);

            if (o == null)
            {
                return(false);
            }

            o.rotateSelf(quat);

            return(true);
        }
Example #13
0
        public bool SetPos(string name, float x, float y, float z)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = _scene.sceneobject(name);

            if (o == null)
            {
                return(false);
            }

            o.setPos(x, y, z);

            return(true);
        }
Example #14
0
        public bool RotateSelf(string name, float x, float y, float z)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = _scene.sceneobject(name);

            if (o == null)
            {
                return(false);
            }

            o.rotateSelf(x, y, z);

            return(true);
        }
Example #15
0
        public bool AddCube(string name, float size)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = warp_ObjectFactory.CUBE(size);

            if (o == null)
            {
                return(false);
            }

            _scene.addObject(name, o);
            _scene.rebuild();

            return(true);
        }
Example #16
0
        public bool AddSphere(string name, float radius, int segments)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = warp_ObjectFactory.SPHERE(radius, segments);

            if (o == null)
            {
                return(false);
            }

            _scene.addObject(name, o);
            _scene.rebuild();

            return(true);
        }
Example #17
0
        public bool AddBox(string name, float x, float y, float z)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Object o = warp_ObjectFactory.BOX(x, y, z);

            if (o == null)
            {
                return(false);
            }

            _scene.addObject(name, o);
            _scene.rebuild();

            return(true);
        }
Example #18
0
        public warp_Object getClone()
        {
            warp_Object obj = new warp_Object();

            rebuild();
            for (int i = 0; i < vertices; i++)
            {
                obj.addVertex(fastvertex[i].getClone());
            }
            for (int i = 0; i < triangles; i++)
            {
                obj.addTriangle(fasttriangle[i].getClone());
            }
            obj.name         = name + " [cloned]";
            obj.material     = material;
            obj.matrix       = matrix.getClone();
            obj.normalmatrix = normalmatrix.getClone();
            obj.rebuild();
            return(obj);
        }
Example #19
0
        public static warp_Object SIMPLEPLANE(float size, bool doubleSided)
        {
            warp_Object newObject = new warp_Object();

            newObject.addVertex(new warp_Vertex(-size, 0f, size, 0, 0));
            newObject.addVertex(new warp_Vertex(size, 0f, size, 1f, 0));
            newObject.addVertex(new warp_Vertex(size, 0f, -size, 1f, 1f));
            newObject.addVertex(new warp_Vertex(-size, 0f, -size, 0, 1f));

            newObject.addTriangle(0, 3, 2);
            newObject.addTriangle(0, 2, 1);

            if (doubleSided)
            {
                newObject.addTriangle(0, 2, 3);
                newObject.addTriangle(0, 1, 2);
            }

            return(newObject);
        }
Example #20
0
        public void loadFastMaterial(warp_Object obj)
        {
            color        = obj.fastcolor;
            reflectivity = obj.fastreflectivity;
            texture      = obj.fasttexture;
            envmap       = obj.fastenvmappixels;

            if (texture != null)
            {
                tpixels = obj.fasttpixels;
                tw      = obj.fasttw;
                th      = obj.fastth;
                tbitW   = obj.fasttbitw;
                tbitH   = obj.fasttbith;
            }

            mode           = obj.fastmode;
            shademode      = mode & SHADED;
            materialLoaded = true;
            ready          = lightmapLoaded;
        }
Example #21
0
        public bool ScaleModel(string name, float scale)
        {
            if (_scene == null)
            {
                return(false);
            }

            Hashtable model = (Hashtable)_models[name];

            if (model == null)
            {
                return(false);
            }

            foreach (DictionaryEntry myDE in model)
            {
                string      key = ( string )myDE.Key;
                warp_Object o   = ( warp_Object )myDE.Value;

                o.scaleSelf(scale);
            }

            return(true);
        }
Example #22
0
        public bool TranslateModel(string name, float x, float y, float z)
        {
            if (_scene == null)
            {
                return(false);
            }

            Hashtable model = ( Hashtable )_models[name];

            if (model == null)
            {
                return(false);
            }

            foreach (DictionaryEntry myDE in model)
            {
                string      key = ( string )myDE.Key;
                warp_Object o   = ( warp_Object )myDE.Value;

                o.shift(x, y, z);
            }

            return(true);
        }
Example #23
0
        // Material loader
        public void loadMaterial(warp_Object obj)
        {
            warp_Material material = obj.material;

            color        = material.color;
            reflectivity = material.reflectivity;
            texture      = material.texture;
            if (material.envmap != null)
            {
                envmap = material.envmap.pixel;
            }
            else
            {
                envmap = null;
            }

            if (texture != null)
            {
                if (obj.projectedmaxMips < 2)
                {
                    color   = warp_Color.multiply(color, texture.averageColor);
                    texture = null;
                }
                else
                {
                    int mip = obj.projectedmaxMips - 1;
                    if (mip > texture.maxmips)
                    {
                        mip = texture.maxmips;
                    }

                    if (texture.mips[mip] != null)
                    {
                        tpixels = texture.mips[mip];
                        tbitW   = texture.mipsBitWidth[mip];
                        tbitH   = texture.mipsBitHeight[mip];
                        tw      = texture.mipstw[mip] - 1;
                        th      = texture.mipsth[mip] - 1;
                    }
                    else
                    {
                        tpixels = texture.pixel;
                        tw      = texture.width - 1;
                        th      = texture.height - 1;
                        tbitW   = texture.bitWidth;
                        tbitH   = texture.bitHeight;
                    }
                }
            }

            mode = 0;
            if (!material.flat)
            {
                mode |= P;
            }
            if (envmap != null)
            {
                mode |= E;
            }
            if (texture != null)
            {
                mode |= T;
            }
            if (material.wireframe)
            {
                mode |= W;
            }

            shademode      = mode & SHADED;
            materialLoaded = true;
            ready          = lightmapLoaded;
        }
Example #24
0
        public static warp_Object TUBE(warp_Vector[] path, float r, int steps, bool closed)
        {
            warp_Vector[] circle = new warp_Vector[steps];
            float         angle;

            for (int i = 0; i < steps; i++)
            {
                angle     = 2 * 3.14159265f * (float)i / (float)steps;
                circle[i] = new warp_Vector(r * warp_Math.cos(angle),
                                            r * warp_Math.sin(angle), 0f);
            }

            warp_Object newObject = new warp_Object();
            int         segments = path.GetLength(0);
            warp_Vector forward, up, right;
            warp_Matrix frenetmatrix;
            warp_Vertex tempvertex;
            float       relx, rely;
            int         a, b, c, d;

            for (int i = 0; i < segments; i++)
            {
                // Calculate frenet frame matrix

                if (i != segments - 1)
                {
                    forward = warp_Vector.sub(path[i + 1], path[i]);
                }
                else
                {
                    if (!closed)
                    {
                        forward = warp_Vector.sub(path[i], path[i - 1]);
                    }
                    else
                    {
                        forward = warp_Vector.sub(path[1], path[0]);
                    }
                }

                forward.normalize();
                up           = new warp_Vector(0f, 0f, 1f);
                right        = warp_Vector.getNormal(forward, up);
                up           = warp_Vector.getNormal(forward, right);
                frenetmatrix = new warp_Matrix(right, up, forward);
                frenetmatrix.shift(path[i].x, path[i].y, path[i].z);

                // Add nodes

                relx = (float)i / (float)(segments - 1);
                for (int k = 0; k < steps; k++)
                {
                    rely         = (float)k / (float)steps;
                    tempvertex   = new warp_Vertex(circle[k].transform(frenetmatrix));
                    tempvertex.u = relx;
                    tempvertex.v = rely;
                    newObject.addVertex(tempvertex);
                }
            }

            for (int i = 0; i < segments - 1; i++)
            {
                for (int k = 0; k < steps - 1; k++)
                {
                    a = i * steps + k;
                    b = a + 1;
                    c = a + steps;
                    d = b + steps;
                    newObject.addTriangle(a, c, b);
                    newObject.addTriangle(b, c, d);
                }
                a = (i + 1) * steps - 1;
                b = a + 1 - steps;
                c = a + steps;
                d = b + steps;
                newObject.addTriangle(a, c, b);
                newObject.addTriangle(b, c, d);
            }

            return(newObject);
        }