Example #1
0
        public warp_Vertex getClone()
        {
            warp_Vertex newVertex = new warp_Vertex();

            newVertex.pos = pos;
            newVertex.n   = n;
            newVertex.u   = u;
            newVertex.v   = v;

            return(newVertex);
        }
        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(new warp_Vector(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);
        }
        public void render(warp_Triangle tri)
        {
            if (!ready)
            {
                return;
            }
            if (tri.parent == null)
            {
                return;
            }
            if ((mode & W) != 0)
            {
                drawWireframe(tri, color);
                if ((mode & W) == 0)
                {
                    return;
                }
            }

            p1 = tri.p1;
            p2 = tri.p2;
            p3 = tri.p3;

            if (p1.y > p2.y)
            {
                tempVertex = p1;
                p1         = p2;
                p2         = tempVertex;
            }
            if (p2.y > p3.y)
            {
                tempVertex = p2;
                p2         = p3;
                p3         = tempVertex;
            }
            if (p1.y > p2.y)
            {
                tempVertex = p1;
                p1         = p2;
                p2         = tempVertex;
            }

            if (p1.y >= height)
            {
                return;
            }
            if (p3.y < 0)
            {
                return;
            }
            if (p1.y == p3.y)
            {
                return;
            }

            if (mode == F)
            {
                lutID        = (int)(tri.n2.x * 127 + 127) + ((int)(tri.n2.y * 127 + 127) << 8);
                c            = warp_Color.multiply(color, diffuse [lutID]);
                s            = warp_Color.scale(specular [lutID], reflectivity);
                currentColor = warp_Color.add(c, s);
            }

            currentId = (tri.parent.id << 16) | tri.id;

            x1 = p1.x << 8;
            x2 = p2.x << 8;
            x3 = p3.x << 8;
            y1 = p1.y;
            y2 = p2.y;
            y3 = p3.y;

            x4   = x1 + (x3 - x1) * (y2 - y1) / (y3 - y1);
            x1 <<= 8;
            x2 <<= 8;
            x3 <<= 8;
            x4 <<= 8;

            z1  = p1.z;
            z2  = p2.z;
            z3  = p3.z;
            nx1 = p1.nx << 16;
            nx2 = p2.nx << 16;
            nx3 = p3.nx << 16;
            ny1 = p1.ny << 16;
            ny2 = p2.ny << 16;
            ny3 = p3.ny << 16;

            sw1 = 1.0f / p1.sw;
            sw2 = 1.0f / p2.sw;
            sw3 = 1.0f / p3.sw;

            tx1 = p1.tx * sw1;
            tx2 = p2.tx * sw2;
            tx3 = p3.tx * sw3;
            ty1 = p1.ty * sw1;
            ty2 = p2.ty * sw2;
            ty3 = p3.ty * sw3;

            dx = (x4 - x2) >> 16;
            if (dx == 0)
            {
                return;
            }

            temp = 256 * (y2 - y1) / (y3 - y1);

            z4  = z1 + ((z3 - z1) >> 8) * temp;
            nx4 = nx1 + ((nx3 - nx1) >> 8) * temp;
            ny4 = ny1 + ((ny3 - ny1) >> 8) * temp;

            float tf = (float)(y2 - y1) / (float)(y3 - y1);

            tx4 = tx1 + ((tx3 - tx1) * tf);
            ty4 = ty1 + ((ty3 - ty1) * tf);

            sw4 = sw1 + ((sw3 - sw1) * tf);

            dz  = (z4 - z2) / dx;
            dnx = (nx4 - nx2) / dx;
            dny = (ny4 - ny2) / dx;
            dtx = (tx4 - tx2) / dx;
            dty = (ty4 - ty2) / dx;
            dsw = (sw4 - sw2) / dx;

            if (dx < 0)
            {
                temp = x2;
                x2   = x4;
                x4   = temp;
                z2   = z4;
                tx2  = tx4;
                ty2  = ty4;
                sw2  = sw4;
                nx2  = nx4;
                ny2  = ny4;
            }
            if (y2 >= 0)
            {
                dy = y2 - y1;
                if (dy != 0)
                {
                    dxL     = (x2 - x1) / dy;
                    dxR     = (x4 - x1) / dy;
                    dzBase  = (z2 - z1) / dy;
                    dnxBase = (nx2 - nx1) / dy;
                    dnyBase = (ny2 - ny1) / dy;
                    dtxBase = (tx2 - tx1) / dy;
                    dtyBase = (ty2 - ty1) / dy;
                    dswBase = (sw2 - sw1) / dy;
                }

                xBase  = x1;
                xMax   = x1;
                zBase  = z1;
                nxBase = nx1;
                nyBase = ny1;
                txBase = tx1;
                tyBase = ty1;
                swBase = sw1;

                if (y1 < 0)
                {
                    xBase  -= y1 * dxL;
                    xMax   -= y1 * dxR;
                    zBase  -= y1 * dzBase;
                    nxBase -= y1 * dnxBase;
                    nyBase -= y1 * dnyBase;
                    txBase -= y1 * dtxBase;
                    tyBase -= y1 * dtyBase;
                    swBase -= y1 * dswBase;
                    y1      = 0;
                }

                y2     = (y2 < height) ? y2 : height;
                offset = y1 * width;
                for (y = y1; y < y2; y++)
                {
                    renderLine();
                }
            }

            if (y2 < height)
            {
                dy = y3 - y2;
                if (dy != 0)
                {
                    dxL     = (x3 - x2) / dy;
                    dxR     = (x3 - x4) / dy;
                    dzBase  = (z3 - z2) / dy;
                    dnxBase = (nx3 - nx2) / dy;
                    dnyBase = (ny3 - ny2) / dy;
                    dtxBase = (tx3 - tx2) / dy;
                    dtyBase = (ty3 - ty2) / dy;
                    dswBase = (sw3 - sw2) / dy;
                }

                xBase  = x2;
                xMax   = x4;
                zBase  = z2;
                nxBase = nx2;
                nyBase = ny2;
                txBase = tx2;
                tyBase = ty2;
                swBase = sw2;

                if (y2 < 0)
                {
                    xBase  -= y2 * dxL;
                    xMax   -= y2 * dxR;
                    zBase  -= y2 * dzBase;
                    nxBase -= y2 * dnxBase;
                    nyBase -= y2 * dnyBase;
                    txBase -= y2 * dtxBase;
                    tyBase -= y2 * dtyBase;
                    swBase -= y2 * dswBase;
                    y2      = 0;
                }

                y3     = (y3 < height) ? y3 : height;
                offset = y2 * width;

                for (y = y2; y < y3; y++)
                {
                    renderLine();
                }
            }
        }
Example #4
0
		public bool equals (warp_Vertex v)
		{
			return ((pos.x == v.pos.x) && (pos.y == v.pos.y) && (pos.z == v.pos.z));
		}
Example #5
0
		public bool equals (warp_Vertex v, float tolerance)
		{
			return Math.Abs (warp_Vector.sub (pos, v.pos).length ()) < tolerance;	
		}
Example #6
0
 public bool equals(warp_Vertex v, float tolerance)
 {
     return(Math.Abs(warp_Vector.sub(pos, v.pos).length()) < tolerance);
 }
Example #7
0
		public warp_Vertex getClone ()
		{
			warp_Vertex newVertex = new warp_Vertex ();
			newVertex.pos = pos;
			newVertex.n = n;
			newVertex.u = u;
			newVertex.v = v;
	
			return newVertex;
		}
Example #8
0
		public void removeVertex (warp_Vertex v)
		{
			vertexData.Remove (v);
		}
Example #9
0
 public bool equals(warp_Vertex v)
 {
     return(warp_Math.FloatApproxEqual(pos.x, v.pos.x) &&
            warp_Math.FloatApproxEqual(pos.y, v.pos.y) &&
            warp_Math.FloatApproxEqual(pos.z, v.pos.z));
 }
        void drawLine(warp_Vertex a, warp_Vertex b, int color)
        {
            warp_Vertex temp;

            if ((a.clipcode & b.clipcode) != 0)
            {
                return;
            }

            dx = (int)Math.Abs(a.x - b.x);
            dy = (int)Math.Abs(a.y - b.y);
            dz = 0;

            if (dx > dy)
            {
                if (a.x > b.x)
                {
                    temp = a;
                    a    = b;
                    b    = temp;
                }
                if (dx > 0)
                {
                    dz = (b.z - a.z) / dx;
                    dy = ((b.y - a.y) << 16) / dx;
                }
                z = a.z;
                y = a.y << 16;
                for (x = a.x; x <= b.x; x++)
                {
                    y2 = y >> 16;
                    if (warp_Math.inrange(x, 0, width - 1) && warp_Math.inrange(y2, 0, height - 1))
                    {
                        offset = y2 * width;
                        if (z < zBuffer [x + offset])
                        {
                            {
                                screen.pixels [x + offset] = color;
                                zBuffer [x + offset]       = z;
                            }
                        }
                        if (useIdBuffer)
                        {
                            idBuffer [x + offset] = currentId;
                        }
                    }
                    z += dz;
                    y += dy;
                }
            }
            else
            {
                if (a.y > b.y)
                {
                    temp = a;
                    a    = b;
                    b    = temp;
                }
                if (dy > 0)
                {
                    dz = (b.z - a.z) / dy;
                    dx = ((b.x - a.x) << 16) / dy;
                }
                z = a.z;
                x = a.x << 16;
                for (y = a.y; y <= b.y; y++)
                {
                    x2 = x >> 16;
                    if (warp_Math.inrange(x2, 0, width - 1) && warp_Math.inrange(y, 0, height - 1))
                    {
                        offset = y * width;
                        if (z < zBuffer [x2 + offset])
                        {
                            {
                                screen.pixels [x2 + offset] = color;
                                zBuffer [x2 + offset]       = z;
                            }
                        }
                        if (useIdBuffer)
                        {
                            idBuffer [x2 + offset] = currentId;
                        }
                    }
                    z += dz;
                    x += dx;
                }
            }
        }
Example #11
0
		void drawLine (warp_Vertex a, warp_Vertex b, int color)
		{
			warp_Vertex temp;
			if ((a.clipcode & b.clipcode) != 0)
				return;

			dx = (int)Math.Abs (a.x - b.x);
			dy = (int)Math.Abs (a.y - b.y);
			dz = 0;

			if (dx > dy)
			{
				if (a.x > b.x)
				{
					temp = a;
					a = b;
					b = temp;
				}
				if (dx > 0)
				{
					dz = (b.z - a.z) / dx;
					dy = ((b.y - a.y) << 16) / dx;
				}
				z = a.z;
				y = a.y << 16;
				for (x = a.x; x <= b.x; x++)
				{
					y2 = y >> 16;
					if (warp_Math.inrange (x, 0, width - 1) && warp_Math.inrange (y2, 0, height - 1))
					{
						offset = y2 * width;
						if (z < zBuffer [x + offset])
						{
							{
								screen.pixels [x + offset] = color;
								zBuffer [x + offset] = z;
							}
						}
						if (useIdBuffer)
							idBuffer [x + offset] = currentId;
					}
					z += dz;
					y += dy;
				}
			} else
			{
				if (a.y > b.y)
				{
					temp = a;
					a = b;
					b = temp;
				}
				if (dy > 0)
				{
					dz = (b.z - a.z) / dy;
					dx = ((b.x - a.x) << 16) / dy;
				}
				z = a.z;
				x = a.x << 16;
				for (y = a.y; y <= b.y; y++)
				{
					x2 = x >> 16;
					if (warp_Math.inrange (x2, 0, width - 1) && warp_Math.inrange (y, 0, height - 1))
					{
						offset = y * width;
						if (z < zBuffer [x2 + offset])
						{
							{
								screen.pixels [x2 + offset] = color;
								zBuffer [x2 + offset] = z;
							}
						}
						if (useIdBuffer)
							idBuffer [x2 + offset] = currentId;
					}
					z += dz;
					x += dx;
				}
			}
		}
Example #12
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 (new warp_Vector (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 #13
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;
		}
Example #14
0
 public bool equals(warp_Vertex v)
 {
     return((pos.x == v.pos.x) && (pos.y == v.pos.y) && (pos.z == v.pos.z));
 }
 public void addTriangle(warp_Vertex a, warp_Vertex b, warp_Vertex c)
 {
     addTriangle(new warp_Triangle(a, b, c));
 }
 public void removeVertex(warp_Vertex v)
 {
     vertexData.Remove(v);
 }
 public void addVertex(warp_Vertex newVertex)
 {
     newVertex.parent = this;
     vertexData.Add(newVertex);
     dirty = true;
 }
Example #18
0
		public void addTriangle (warp_Vertex a, warp_Vertex b, warp_Vertex c)
		{
			addTriangle (new warp_Triangle (a, b, c));
		}
Example #19
0
		public void render (warp_Triangle tri)
		{
			if (!ready)
			{
				return;
			}
			if (tri.parent == null)
			{
				return;
			}
			if ((mode & W) != 0)
			{
				drawWireframe (tri, color);
				if ((mode & W) == 0)
				{
					return;
				}
			}

			p1 = tri.p1;
			p2 = tri.p2;
			p3 = tri.p3;

			if (p1.y > p2.y)
			{
				tempVertex = p1;
				p1 = p2;
				p2 = tempVertex;
			}
			if (p2.y > p3.y)
			{
				tempVertex = p2;
				p2 = p3;
				p3 = tempVertex;
			}
			if (p1.y > p2.y)
			{
				tempVertex = p1;
				p1 = p2;
				p2 = tempVertex;
			}

			if (p1.y >= height)
			{
				return;
			}
			if (p3.y < 0)
			{
				return;
			}
			if (p1.y == p3.y)
			{
				return;
			}

			if (mode == F)
			{
				lutID = (int)(tri.n2.x * 127 + 127) + ((int)(tri.n2.y * 127 + 127) << 8);
				c = warp_Color.multiply (color, diffuse [lutID]);
				s = warp_Color.scale (specular [lutID], reflectivity);
				currentColor = warp_Color.add (c, s);
			}

			currentId = (tri.parent.id << 16) | tri.id;

			x1 = p1.x << 8;
			x2 = p2.x << 8;
			x3 = p3.x << 8;
			y1 = p1.y;
			y2 = p2.y;
			y3 = p3.y;

			x4 = x1 + (x3 - x1) * (y2 - y1) / (y3 - y1);
			x1 <<= 8;
			x2 <<= 8;
			x3 <<= 8;
			x4 <<= 8;

			z1 = p1.z;
			z2 = p2.z;
			z3 = p3.z;
			nx1 = p1.nx << 16;
			nx2 = p2.nx << 16;
			nx3 = p3.nx << 16;
			ny1 = p1.ny << 16;
			ny2 = p2.ny << 16;
			ny3 = p3.ny << 16;

			sw1 = 1.0f / p1.sw;
			sw2 = 1.0f / p2.sw;
			sw3 = 1.0f / p3.sw;

			tx1 = p1.tx * sw1;
			tx2 = p2.tx * sw2;
			tx3 = p3.tx * sw3;
			ty1 = p1.ty * sw1;
			ty2 = p2.ty * sw2;
			ty3 = p3.ty * sw3;

			dx = (x4 - x2) >> 16;
			if (dx == 0)
			{
				return;
			}

			temp = 256 * (y2 - y1) / (y3 - y1);

			z4 = z1 + ((z3 - z1) >> 8) * temp;
			nx4 = nx1 + ((nx3 - nx1) >> 8) * temp;
			ny4 = ny1 + ((ny3 - ny1) >> 8) * temp;

			float tf = (float)(y2 - y1) / (float)(y3 - y1);

			tx4 = tx1 + ((tx3 - tx1) * tf);
			ty4 = ty1 + ((ty3 - ty1) * tf);

			sw4 = sw1 + ((sw3 - sw1) * tf);

			dz = (z4 - z2) / dx;
			dnx = (nx4 - nx2) / dx;
			dny = (ny4 - ny2) / dx;
			dtx = (tx4 - tx2) / dx;
			dty = (ty4 - ty2) / dx;
			dsw = (sw4 - sw2) / dx;

			if (dx < 0)
			{
				temp = x2;
				x2 = x4;
				x4 = temp;
				z2 = z4;
				tx2 = tx4;
				ty2 = ty4;
				sw2 = sw4;
				nx2 = nx4;
				ny2 = ny4;
			}
			if (y2 >= 0)
			{
				dy = y2 - y1;
				if (dy != 0)
				{
					dxL = (x2 - x1) / dy;
					dxR = (x4 - x1) / dy;
					dzBase = (z2 - z1) / dy;
					dnxBase = (nx2 - nx1) / dy;
					dnyBase = (ny2 - ny1) / dy;
					dtxBase = (tx2 - tx1) / dy;
					dtyBase = (ty2 - ty1) / dy;
					dswBase = (sw2 - sw1) / dy;
				}

				xBase = x1;
				xMax = x1;
				zBase = z1;
				nxBase = nx1;
				nyBase = ny1;
				txBase = tx1;
				tyBase = ty1;
				swBase = sw1;

				if (y1 < 0)
				{
					xBase -= y1 * dxL;
					xMax -= y1 * dxR;
					zBase -= y1 * dzBase;
					nxBase -= y1 * dnxBase;
					nyBase -= y1 * dnyBase;
					txBase -= y1 * dtxBase;
					tyBase -= y1 * dtyBase;
					swBase -= y1 * dswBase;
					y1 = 0;
				}

				y2 = (y2 < height) ? y2 : height;
				offset = y1 * width;
				for (y = y1; y < y2; y++)
				{
					renderLine ();
				}
			}

			if (y2 < height)
			{
				dy = y3 - y2;
				if (dy != 0)
				{
					dxL = (x3 - x2) / dy;
					dxR = (x3 - x4) / dy;
					dzBase = (z3 - z2) / dy;
					dnxBase = (nx3 - nx2) / dy;
					dnyBase = (ny3 - ny2) / dy;
					dtxBase = (tx3 - tx2) / dy;
					dtyBase = (ty3 - ty2) / dy;
					dswBase = (sw3 - sw2) / dy;
				}

				xBase = x2;
				xMax = x4;
				zBase = z2;
				nxBase = nx2;
				nyBase = ny2;
				txBase = tx2;
				tyBase = ty2;
				swBase = sw2;

				if (y2 < 0)
				{
					xBase -= y2 * dxL;
					xMax -= y2 * dxR;
					zBase -= y2 * dzBase;
					nxBase -= y2 * dnxBase;
					nyBase -= y2 * dnyBase;
					txBase -= y2 * dtxBase;
					tyBase -= y2 * dtyBase;
					swBase -= y2 * dswBase;
					y2 = 0;
				}

				y3 = (y3 < height) ? y3 : height;
				offset = y2 * width;

				for (y = y2; y < y3; y++)
				{
					renderLine ();
				}
			}
		}
        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);
        }
        void CreatePrim (WarpRenderer renderer, ISceneChildEntity prim)
        {
            try {

                if ((PCode)prim.Shape.PCode != PCode.Prim)
                    return;
                if (prim.Scale.LengthSquared () < MIN_PRIM_SIZE * MIN_PRIM_SIZE)
                    return;

                Primitive omvPrim = prim.Shape.ToOmvPrimitive (prim.OffsetPosition, prim.GetRotationOffset ());
                FacetedMesh renderMesh = null;

                // Are we dealing with a sculptie or mesh?
                if (omvPrim.Sculpt != null && omvPrim.Sculpt.SculptTexture != UUID.Zero) {
                    // Try fetching the asset
                    byte [] sculptAsset = m_scene.AssetService.GetData (omvPrim.Sculpt.SculptTexture.ToString ());
                    if (sculptAsset != null) {
                        // Is it a mesh?
                        if (omvPrim.Sculpt.Type == SculptType.Mesh) {
                            AssetMesh meshAsset = new AssetMesh (omvPrim.Sculpt.SculptTexture, sculptAsset);
                            FacetedMesh.TryDecodeFromAsset (omvPrim, meshAsset, DetailLevel.Highest, out renderMesh);
                            meshAsset = null;
                        } else // It's sculptie
                          {
                            Image sculpt = m_imgDecoder.DecodeToImage (sculptAsset);
                            if (sculpt != null) {
                                renderMesh = m_primMesher.GenerateFacetedSculptMesh (omvPrim, (Bitmap)sculpt,
                                                                                    DetailLevel.Medium);
                                sculpt.Dispose ();
                            }
                        }
                        sculptAsset = null;
                    } else {
                        // missing sculpt data... replace with something
                        renderMesh = m_primMesher.GenerateFacetedMesh (omvPrim, DetailLevel.Medium);
                    }

                } else // Prim
                  {
                    renderMesh = m_primMesher.GenerateFacetedMesh (omvPrim, DetailLevel.Medium);
                }

                if (renderMesh == null)
                    return;

                warp_Vector primPos = ConvertVector (prim.GetWorldPosition ());
                warp_Quaternion primRot = ConvertQuaternion (prim.GetRotationOffset ());

                warp_Matrix m = warp_Matrix.quaternionMatrix (primRot);

                if (prim.ParentID != 0) {
                    ISceneEntity group = m_scene.GetGroupByPrim (prim.LocalId);
                    if (group != null)
                        m.transform (warp_Matrix.quaternionMatrix (ConvertQuaternion (group.RootChild.GetRotationOffset ())));
                }

                warp_Vector primScale = ConvertVector (prim.Scale);

                string primID = prim.UUID.ToString ();

                // Create the prim faces
                for (int i = 0; i < renderMesh.Faces.Count; i++) {
                    Face renderFace = renderMesh.Faces [i];
                    string meshName = primID + "-Face-" + i;

                    warp_Object faceObj = new warp_Object (renderFace.Vertices.Count, renderFace.Indices.Count / 3);

                    foreach (Vertex v in renderFace.Vertices) {
                        warp_Vector pos = ConvertVector (v.Position);
                        warp_Vector norm = ConvertVector (v.Normal);

                        if (prim.Shape.SculptTexture == UUID.Zero)
                            norm = norm.reverse ();
                        warp_Vertex vert = new warp_Vertex (pos, norm, v.TexCoord.X, v.TexCoord.Y);

                        faceObj.addVertex (vert);
                    }

                    for (int j = 0; j < renderFace.Indices.Count;) {
                        faceObj.addTriangle (
                            renderFace.Indices [j++],
                            renderFace.Indices [j++],
                            renderFace.Indices [j++]);
                    }

                    Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace ((uint)i);
                    string materialName;
                    Color4 faceColor = GetFaceColor (teFace);

                    if (m_texturePrims && (prim.Scale.LengthSquared () > m_texturePrimSize)) {
                        materialName = GetOrCreateMaterial (renderer, faceColor, teFace.TextureID);
                    } else {
                        materialName = GetOrCreateMaterial (renderer, faceColor);
                    }

                    faceObj.transform (m);
                    faceObj.setPos (primPos);
                    faceObj.scaleSelf (primScale.x, primScale.y, primScale.z);

                    renderer.Scene.addObject (meshName, faceObj);

                    renderer.SetObjectMaterial (meshName, materialName);

                    faceObj = null;
                }
                renderMesh.Faces.Clear ();
                renderMesh = null;
            } catch (Exception ex) {
                MainConsole.Instance.Warn ("[Warp3D]: Exception creating prim, " + ex);
            }
        }
Example #22
0
		public void addVertex (warp_Vertex newVertex)
		{
			newVertex.parent = this;
			vertexData.Add (newVertex);
			dirty = true;
		}