예제 #1
0
        public void addVertex(float x, float y, float z, float u, float v)
        {
            warp_Vertex vert = new warp_Vertex(x, y, z);

            vert.setUV(u, v);
            addVertex(vert);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
        private void CreatePrim(WarpRenderer renderer, SceneObjectPart prim,
                bool useTextures)
        {
            const float MIN_SIZE = 2f;

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

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

            if (m_renderMeshes)
            {
                if (omvPrim.Sculpt != null && omvPrim.Sculpt.SculptTexture != UUID.Zero)
                {
                    // Try fetchinng 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
                        {
                            IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>();
                            if (imgDecoder != null)
                            {
                                Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
                                if (sculpt != null)
                                {
                                    renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt,
                                                                                        DetailLevel.Medium);
                                    sculpt.Dispose();
                                }
                            }
                        }
                    }
                }
            }

            // If not a mesh or sculptie, try the regular mesher
            if (renderMesh == null)
            {
                renderMesh = m_primMesher.GenerateFacetedMesh(omvPrim, DetailLevel.Medium);
            }

            if (renderMesh == null)
                return;

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

            warp_Matrix m = warp_Matrix.quaternionMatrix(primRot);

            if (prim.ParentID != 0)
            {
                SceneObjectGroup group = m_scene.SceneGraph.GetGroupByPrim(prim.LocalId);
                if (group != null)
                    m.transform(warp_Matrix.quaternionMatrix(ConvertQuaternion(group.RootPart.RotationOffset)));
            }

            warp_Vector primScale = ConvertVector(prim.Scale);

            string primID = prim.UUID.ToString();

            // Create the prim faces
            // TODO: Implement the useTextures flag behavior
            for (int i = 0; i < renderMesh.Faces.Count; i++)
            {
                Face face = renderMesh.Faces[i];
                string meshName = primID + "-Face-" + i.ToString();

                // Avoid adding duplicate meshes to the scene
                if (renderer.Scene.objectData.ContainsKey(meshName))
                {
                    continue;
                }

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

                for (int j = 0; j < face.Vertices.Count; j++)
                {
                    Vertex v = face.Vertices[j];

                    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 < face.Indices.Count; j += 3)
                {
                    faceObj.addTriangle(
                        face.Indices[j + 0],
                        face.Indices[j + 1],
                        face.Indices[j + 2]);
                }

                Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i);
                Color4 faceColor = GetFaceColor(teFace);
                string materialName = String.Empty;
                if (m_texturePrims && prim.Scale.LengthSquared() > m_texturePrimSize*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);
            }
        }
예제 #5
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;

		}
예제 #6
0
		public void addVertex(warp_Vertex newVertex)
		{
			newVertex.parent=this;
			vertexData.Add(newVertex);
			dirty=true;
		}
예제 #7
0
		public void addVertex(float x, float y, float z, float u, float v)
		{
			warp_Vertex vert=new warp_Vertex(x,y,z);
			vert.setUV(u,v);
			addVertex(vert);
		}
 public warp_Edge(warp_Vertex v1, warp_Vertex v2)
 {
     a = v1;
     b = v2;
 }
예제 #9
0
 public void removeVertex(warp_Vertex v)
 {
     vertexData.Remove(v);
 }
예제 #10
0
 public void addTriangle(warp_Vertex a, warp_Vertex b, warp_Vertex c)
 {
     addTriangle(new warp_Triangle(a, b, c));
 }
예제 #11
0
 public bool equals(warp_Vertex v)
 {
     return((pos.x == v.pos.x) && (pos.y == v.pos.y) && (pos.z == v.pos.z));
 }
예제 #12
0
		public bool equals(warp_Vertex v,float tolerance)
		{
			return Math.Abs(warp_Vector.sub(pos,v.pos).length())<tolerance;	
		}
예제 #13
0
		public bool equals(warp_Vertex v)
		{
			return ((pos.x==v.pos.x)&&(pos.y==v.pos.y)&&(pos.z==v.pos.z));
		}
예제 #14
0
		public warp_Vertex getClone()
		{
			warp_Vertex newVertex=new warp_Vertex();
			newVertex.pos=pos.getClone();
			newVertex.n=n.getClone();
			newVertex.u=u;
			newVertex.v=v;
	
			return newVertex;
		}
예제 #15
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);
        }
        private 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;
                }
            }
        }
예제 #17
0
 public bool equals(warp_Vertex v, float tolerance)
 {
     return(Math.Abs(warp_Vector.sub(pos, v.pos).length()) < tolerance);
 }
예제 #18
0
 public warp_Edge(warp_Vertex v1, warp_Vertex v2)
 {
     a = v1;
     b = v2;
 }
예제 #19
0
 public void addVertex(warp_Vertex newVertex)
 {
     newVertex.parent = this;
     vertexData.Add(newVertex);
     dirty = true;
 }
예제 #20
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();
                }
            }
        }
예제 #21
0
		public warp_Triangle(warp_Vertex a, warp_Vertex b, warp_Vertex c)
		{
			p1=a;
			p2=b;
			p3=c;
		}
예제 #22
0
        private 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;
                }
            }
        }
예제 #23
0
        private void CreatePrim(WarpRenderer renderer, ISceneChildEntity prim)
        {
            try
            {
                const float MIN_SIZE = 2f;

                if ((PCode) prim.Shape.PCode != PCode.Prim)
                    return;
                if (prim.Scale.LengthSquared() < MIN_SIZE*MIN_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 fetchinng 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();
                            }
                        }
                    }
                }
                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 face = renderMesh.Faces[i];
                    string meshName = primID + "-Face-" + i.ToString();

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

                    foreach (Vertex v in face.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 < face.Indices.Count;)
                    {
                        faceObj.addTriangle(
                            face.Indices[j++],
                            face.Indices[j++],
                            face.Indices[j++]);
                    }

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

                    if (m_texturePrims && prim.Scale.LengthSquared() > 48*48)
                    {
                        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);
                }
                renderMesh.Faces.Clear();
                renderMesh = null;
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[Warp3D]: Exception creating prim, " + ex);
            }
        }
예제 #24
0
 public warp_Triangle(warp_Vertex a, warp_Vertex b, warp_Vertex c)
 {
     p1 = a;
     p2 = b;
     p3 = c;
 }
예제 #25
0
		public void addTriangle(warp_Vertex a, warp_Vertex b, warp_Vertex c)
		{
			addTriangle(new warp_Triangle(a,b,c));
		}
예제 #26
0
        private void CreatePrim(WarpRenderer renderer, SceneObjectPart prim,
                bool useTextures)
        {
            const float MIN_SIZE = 2f;

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

            Primitive omvPrim = prim.Shape.ToOmvPrimitive(prim.OffsetPosition, prim.RotationOffset);
            FacetedMesh renderMesh = m_primMesher.GenerateFacetedMesh(omvPrim, DetailLevel.Medium);
            if (renderMesh == null)
                return;

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

            warp_Matrix m = warp_Matrix.quaternionMatrix(primRot);

            if (prim.ParentID != 0)
            {
                SceneObjectGroup group = m_scene.SceneGraph.GetGroupByPrim(prim.LocalId);
                if (group != null)
                    m.transform(warp_Matrix.quaternionMatrix(ConvertQuaternion(group.RootPart.RotationOffset)));
            }

            warp_Vector primScale = ConvertVector(prim.Scale);

            string primID = prim.UUID.ToString();

            // Create the prim faces
            // TODO: Implement the useTextures flag behavior
            for (int i = 0; i < renderMesh.Faces.Count; i++)
            {
                Face face = renderMesh.Faces[i];
                string meshName = primID + "-Face-" + i.ToString();

                // Avoid adding duplicate meshes to the scene
                if (renderer.Scene.objectData.ContainsKey(meshName))
                {
                    continue;
                }

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

                for (int j = 0; j < face.Vertices.Count; j++)
                {
                    Vertex v = face.Vertices[j];

                    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 < face.Indices.Count; j += 3)
                {
                    faceObj.addTriangle(
                        face.Indices[j + 0],
                        face.Indices[j + 1],
                        face.Indices[j + 2]);
                }

                Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i);
                Color4 faceColor = GetFaceColor(teFace);
                string 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);
            }
        }
예제 #27
0
		public void removeVertex(warp_Vertex v)
		{
			vertexData.Remove(v);
		}
        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();
                }
            }
        }
예제 #29
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;
		}
예제 #30
0
        private void CreatePrim(WarpRenderer renderer, LLPrimitive prim, IPrimMesher primMesher)
        {
            const float MIN_SIZE = 2f;

            if (prim.Prim.PrimData.PCode != PCode.Prim)
                return;
            if (prim.Scale.LengthSquared() < MIN_SIZE * MIN_SIZE)
                return;

            RenderingMesh renderMesh;
            DetailLevel lod = DetailLevel.Medium;

            renderMesh = primMesher.GetRenderingMesh(prim, lod);

            if (renderMesh == null)
                return;

            warp_Vector primPos = ConvertVector(prim.ScenePosition);
            warp_Quaternion primRot = ConvertQuaternion(prim.RelativeRotation);

            warp_Matrix m = warp_Matrix.quaternionMatrix(primRot);

            if (prim.Parent != null)
                m.transform(warp_Matrix.quaternionMatrix(ConvertQuaternion(prim.Parent.RelativeRotation)));

            warp_Vector primScale = ConvertVector(prim.Scale);

            string primID = prim.ID.ToString();

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

                warp_Object faceObj = new warp_Object(face.Vertices.Length, face.Indices.Length / 3);

                for (int j = 0; j < face.Vertices.Length; j++)
                {
                    Vertex v = face.Vertices[j];

                    warp_Vector pos = ConvertVector(v.Position);
                    warp_Vector norm = ConvertVector(v.Normal);
                    if (prim.Prim.Sculpt == null || prim.Prim.Sculpt.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 < face.Indices.Length; j += 3)
                {
                    faceObj.addTriangle(
                        face.Indices[j + 0],
                        face.Indices[j + 1],
                        face.Indices[j + 2]);
                }

                Primitive.TextureEntryFace teFace = prim.Prim.Textures.GetFace((uint)i);
                Color4 faceColor = GetFaceColor(teFace);
                string 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);
            }
        }