Пример #1
0
        public static warp_Matrix quaternionMatrix(warp_Quaternion quat)
        {
            warp_Matrix m = new warp_Matrix();


            float xx = quat.X * quat.X;
            float xy = quat.X * quat.Y;
            float xz = quat.X * quat.Z;
            float xw = quat.X * quat.W;
            float yy = quat.Y * quat.Y;
            float yz = quat.Y * quat.Z;
            float yw = quat.Y * quat.W;
            float zz = quat.Z * quat.Z;
            float zw = quat.Z * quat.W;

            m.m00 = 1 - 2 * (yy + zz);
            m.m01 = 2 * (xy - zw);
            m.m02 = 2 * (xz + yw);
            m.m10 = 2 * (xy + zw);
            m.m11 = 1 - 2 * (xx + zz);
            m.m12 = 2 * (yz - xw);
            m.m20 = 2 * (xz - yw);
            m.m21 = 2 * (yz + xw);
            m.m22 = 1 - 2 * (xx + yy);

            m.m03 = m.m13 = m.m23 = m.m30 = m.m31 = m.m32 = 0;
            m.m33 = 1;

            return(m);
        }
Пример #2
0
        public warp_Matrix rotateMatrix(warp_Quaternion quat)
        {
            reset();

            warp_Matrix temp   = quaternionMatrix(quat);
            warp_Matrix result = multiply(this, temp);

            return(result);
        }
Пример #3
0
        public static warp_Matrix scaleMatrix(float dx, float dy, float dz)
        {
            warp_Matrix m = new warp_Matrix();

            m.m00 = dx;
            m.m11 = dy;
            m.m22 = dz;

            return(m);
        }
Пример #4
0
        public static warp_Matrix shiftMatrix(float dx, float dy, float dz)
        // matrix for shifting
        {
            warp_Matrix m = new warp_Matrix();

            m.m03 = dx;
            m.m13 = dy;
            m.m23 = dz;
            return(m);
        }
Пример #5
0
        public warp_Matrix inverse()
        {
            warp_Matrix m = new warp_Matrix();

            float q1  = m12;
            float q6  = m10 * m01;
            float q7  = m10 * m21;
            float q8  = m02;
            float q13 = m20 * m01;
            float q14 = m20 * m11;
            float q21 = m02 * m21;
            float q22 = m03 * m21;
            float q25 = m01 * m12;
            float q26 = m01 * m13;
            float q27 = m02 * m11;
            float q28 = m03 * m11;
            float q29 = m10 * m22;
            float q30 = m10 * m23;
            float q31 = m20 * m12;
            float q32 = m20 * m13;
            float q35 = m00 * m22;
            float q36 = m00 * m23;
            float q37 = m20 * m02;
            float q38 = m20 * m03;
            float q41 = m00 * m12;
            float q42 = m00 * m13;
            float q43 = m10 * m02;
            float q44 = m10 * m03;
            float q45 = m00 * m11;
            float q48 = m00 * m21;
            float q49 = q45 * m22 - q48 * q1 - q6 * m22 + q7 * q8;
            float q50 = q13 * q1 - q14 * q8;
            float q51 = 1 / (q49 + q50);

            m.m00 = (m11 * m22 * m33 - m11 * m23 * m32 - m21 * m12 * m33 + m21 * m13 * m32 + m31 * m12 * m23 - m31 * m13 * m22) * q51;
            m.m01 = -(m01 * m22 * m33 - m01 * m23 * m32 - q21 * m33 + q22 * m32) * q51;
            m.m02 = (q25 * m33 - q26 * m32 - q27 * m33 + q28 * m32) * q51;
            m.m03 = -(q25 * m23 - q26 * m22 - q27 * m23 + q28 * m22 + q21 * m13 - q22 * m12) * q51;
            m.m10 = -(q29 * m33 - q30 * m32 - q31 * m33 + q32 * m32) * q51;
            m.m11 = (q35 * m33 - q36 * m32 - q37 * m33 + q38 * m32) * q51;
            m.m12 = -(q41 * m33 - q42 * m32 - q43 * m33 + q44 * m32) * q51;
            m.m13 = (q41 * m23 - q42 * m22 - q43 * m23 + q44 * m22 + q37 * m13 - q38 * m12) * q51;
            m.m20 = (q7 * m33 - q30 * m31 - q14 * m33 + q32 * m31) * q51;
            m.m21 = -(q48 * m33 - q36 * m31 - q13 * m33 + q38 * m31) * q51;
            m.m22 = (q45 * m33 - q42 * m31 - q6 * m33 + q44 * m31) * q51;
            m.m23 = -(q45 * m23 - q42 * m21 - q6 * m23 + q44 * m21 + q13 * m13 - q38 * m11) * q51;

            return(m);
        }
Пример #6
0
        public void transform(warp_Matrix n)
        {
            warp_Matrix m = getClone();

            m00 = n.m00 * m.m00 + n.m01 * m.m10 + n.m02 * m.m20;
            m01 = n.m00 * m.m01 + n.m01 * m.m11 + n.m02 * m.m21;
            m02 = n.m00 * m.m02 + n.m01 * m.m12 + n.m02 * m.m22;
            m03 = n.m00 * m.m03 + n.m01 * m.m13 + n.m02 * m.m23 + n.m03;
            m10 = n.m10 * m.m00 + n.m11 * m.m10 + n.m12 * m.m20;
            m11 = n.m10 * m.m01 + n.m11 * m.m11 + n.m12 * m.m21;
            m12 = n.m10 * m.m02 + n.m11 * m.m12 + n.m12 * m.m22;
            m13 = n.m10 * m.m03 + n.m11 * m.m13 + n.m12 * m.m23 + n.m13;
            m20 = n.m20 * m.m00 + n.m21 * m.m10 + n.m22 * m.m20;
            m21 = n.m20 * m.m01 + n.m21 * m.m11 + n.m22 * m.m21;
            m22 = n.m20 * m.m02 + n.m21 * m.m12 + n.m22 * m.m22;
            m23 = n.m20 * m.m03 + n.m21 * m.m13 + n.m22 * m.m23 + n.m23;
        }
Пример #7
0
        public void preTransform(warp_Matrix n)
        {
            warp_Matrix m = getClone();

            m00 = m.m00 * n.m00 + m.m01 * n.m10 + m.m02 * n.m20;
            m01 = m.m00 * n.m01 + m.m01 * n.m11 + m.m02 * n.m21;
            m02 = m.m00 * n.m02 + m.m01 * n.m12 + m.m02 * n.m22;
            m03 = m.m00 * n.m03 + m.m01 * n.m13 + m.m02 * n.m23 + m.m03;
            m10 = m.m10 * n.m00 + m.m11 * n.m10 + m.m12 * n.m20;
            m11 = m.m10 * n.m01 + m.m11 * n.m11 + m.m12 * n.m21;
            m12 = m.m10 * n.m02 + m.m11 * n.m12 + m.m12 * n.m22;
            m13 = m.m10 * n.m03 + m.m11 * n.m13 + m.m12 * n.m23 + m.m13;
            m20 = m.m20 * n.m00 + m.m21 * n.m10 + m.m22 * n.m20;
            m21 = m.m20 * n.m01 + m.m21 * n.m11 + m.m22 * n.m21;
            m22 = m.m20 * n.m02 + m.m21 * n.m12 + m.m22 * n.m22;
            m23 = m.m20 * n.m03 + m.m21 * n.m13 + m.m22 * n.m23 + m.m23;
        }
Пример #8
0
        public static warp_Matrix rotateMatrix(float dx, float dy, float dz)
        {
            warp_Matrix res = new warp_Matrix();

            float SIN;
            float COS;

            if (!warp_Math.FloatApproxEqual(dx, 0))
            {
                warp_Matrix m = new warp_Matrix();
                SIN   = warp_Math.sin(dx);
                COS   = warp_Math.cos(dx);
                m.m11 = COS;
                m.m12 = SIN;
                m.m21 = -SIN;
                m.m22 = COS;

                res.transform(m);
            }
            if (!warp_Math.FloatApproxEqual(dy, 0))
            {
                warp_Matrix m = new warp_Matrix();
                SIN   = warp_Math.sin(dy);
                COS   = warp_Math.cos(dy);
                m.m00 = COS;
                m.m02 = SIN;
                m.m20 = -SIN;
                m.m22 = COS;

                res.transform(m);
            }
            if (!warp_Math.FloatApproxEqual(dz, 0))
            {
                warp_Matrix m = new warp_Matrix();
                SIN   = warp_Math.sin(dz);
                COS   = warp_Math.cos(dz);
                m.m00 = COS;
                m.m01 = SIN;
                m.m10 = -SIN;
                m.m11 = COS;

                res.transform(m);
            }

            return(res);
        }
Пример #9
0
        public static warp_Matrix Ode2WarpMatrix(Ode.Matrix3 m)
        {
            warp_Matrix result = new warp_Matrix();

            result.m11 = ( float )m.m11;
            result.m12 = ( float )m.m12;
            result.m13 = ( float )m.m13;

            result.m21 = ( float )m.m21;
            result.m22 = ( float )m.m22;
            result.m23 = ( float )m.m23;

            result.m31 = ( float )m.m31;
            result.m32 = ( float )m.m32;
            result.m33 = ( float )m.m33;

            return(result);
        }
Пример #10
0
        public static Ode.Matrix3 Warp2OdeMatrix3(warp_Matrix m)
        {
            Ode.Matrix3 odeM = new Ode.Matrix3();

            odeM.m11 = m.m11;
            odeM.m12 = m.m12;
            odeM.m13 = m.m13;

            odeM.m21 = m.m21;
            odeM.m22 = m.m22;
            odeM.m23 = m.m23;

            odeM.m31 = m.m31;
            odeM.m32 = m.m32;
            odeM.m33 = m.m33;

            return(odeM);
        }
Пример #11
0
        public static warp_Matrix multiply(warp_Matrix m1, warp_Matrix m2)
        {
            warp_Matrix m = new warp_Matrix();

            m.m00 = m1.m00 * m2.m00 + m1.m01 * m2.m10 + m1.m02 * m2.m20;
            m.m01 = m1.m00 * m2.m01 + m1.m01 * m2.m11 + m1.m02 * m2.m21;
            m.m02 = m1.m00 * m2.m02 + m1.m01 * m2.m12 + m1.m02 * m2.m22;
            m.m03 = m1.m00 * m2.m03 + m1.m01 * m2.m13 + m1.m02 * m2.m23 + m1.m03;
            m.m10 = m1.m10 * m2.m00 + m1.m11 * m2.m10 + m1.m12 * m2.m20;
            m.m11 = m1.m10 * m2.m01 + m1.m11 * m2.m11 + m1.m12 * m2.m21;
            m.m12 = m1.m10 * m2.m02 + m1.m11 * m2.m12 + m1.m12 * m2.m22;
            m.m13 = m1.m10 * m2.m03 + m1.m11 * m2.m13 + m1.m12 * m2.m23 + m1.m13;
            m.m20 = m1.m20 * m2.m00 + m1.m21 * m2.m10 + m1.m22 * m2.m20;
            m.m21 = m1.m20 * m2.m01 + m1.m21 * m2.m11 + m1.m22 * m2.m21;
            m.m22 = m1.m20 * m2.m02 + m1.m21 * m2.m12 + m1.m22 * m2.m22;
            m.m23 = m1.m20 * m2.m03 + m1.m21 * m2.m13 + m1.m22 * m2.m23 + m1.m23;

            return(m);
        }
Пример #12
0
        /*
         * public string toString()
         * {
         *      // todo
         * }
         */
        public warp_Matrix getClone()
        {
            warp_Matrix m = new warp_Matrix();

            m.m00 = m00;
            m.m01 = m01;
            m.m02 = m02;
            m.m03 = m03;
            m.m10 = m10;
            m.m11 = m11;
            m.m12 = m12;
            m.m13 = m13;
            m.m20 = m20;
            m.m21 = m21;
            m.m22 = m22;
            m.m23 = m23;
            m.m30 = m30;
            m.m31 = m31;
            m.m32 = m32;
            m.m33 = m33;

            return(m);
        }
Пример #13
0
        private void CreatePrim(WarpRenderer renderer, SceneObjectPart prim)
        {
            if ((PCode)prim.Shape.PCode != PCode.Prim)
            {
                return;
            }

            Vector3 ppos = prim.GetWorldPosition();

            if (ppos.Z < m_renderMinHeight || ppos.Z > m_renderMaxHeight)
            {
                return;
            }

            warp_Vector     primPos = ConvertVector(ppos);
            warp_Quaternion primRot = ConvertQuaternion(prim.GetWorldRotation());
            warp_Matrix     m       = warp_Matrix.quaternionMatrix(primRot);

            float screenFactor = renderer.Scene.EstimateBoxProjectedArea(primPos, ConvertVector(prim.Scale), m);

            if (screenFactor < 0)
            {
                return;
            }

            const float log2inv = -1.442695f;
            int         p2      = (int)((float)Math.Log(screenFactor) * log2inv * 0.25 - 1);

            if (p2 < 0)
            {
                p2 = 0;
            }
            else if (p2 > 3)
            {
                p2 = 3;
            }

            DetailLevel lod = (DetailLevel)(3 - p2);

            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
                    AssetBase sculptAsset = m_scene.AssetService.Get(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.Data);
                            FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, lod, out renderMesh);
                            meshAsset = null;
                        }
                        else // It's sculptie
                        {
                            if (m_imgDecoder != null)
                            {
                                Image sculpt = m_imgDecoder.DecodeToImage(sculptAsset.Data);
                                if (sculpt != null)
                                {
                                    renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, lod);
                                    sculpt.Dispose();
                                }
                            }
                        }
                    }
                    else
                    {
                        m_log.WarnFormat("[Warp3D] failed to get mesh or sculpt asset {0} of prim {1} at {2}",
                                         omvPrim.Sculpt.SculptTexture.ToString(), prim.Name, prim.GetWorldPosition().ToString());
                    }
                }
            }

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

            if (renderMesh == null)
            {
                return;
            }

            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 + i.ToString();

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

                warp_Object faceObj = new warp_Object();

                Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i);
                Color4 faceColor = teFace.RGBA;
                if (faceColor.A == 0)
                {
                    continue;
                }

                string materialName = string.Empty;
                if (m_texturePrims)
                {
                    // if(lod > DetailLevel.Low)
                    {
                        // materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID, lod == DetailLevel.Low);
                        materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID, false, prim);
                        if (String.IsNullOrEmpty(materialName))
                        {
                            continue;
                        }
                        int c = renderer.Scene.material(materialName).getColor();
                        if ((c & warp_Color.MASKALPHA) == 0)
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    materialName = GetOrCreateMaterial(renderer, faceColor);
                }

                if (renderer.Scene.material(materialName).getTexture() == null)
                {
                    // uv map details dont not matter for color;
                    for (int j = 0; j < face.Vertices.Count; j++)
                    {
                        Vertex      v    = face.Vertices[j];
                        warp_Vector pos  = ConvertVector(v.Position);
                        warp_Vertex vert = new warp_Vertex(pos, v.TexCoord.X, v.TexCoord.Y);
                        faceObj.addVertex(vert);
                    }
                }
                else
                {
                    float tu;
                    float tv;
                    float offsetu  = teFace.OffsetU + 0.5f;
                    float offsetv  = teFace.OffsetV + 0.5f;
                    float scaleu   = teFace.RepeatU;
                    float scalev   = teFace.RepeatV;
                    float rotation = teFace.Rotation;
                    float rc       = 0;
                    float rs       = 0;
                    if (rotation != 0)
                    {
                        rc = (float)Math.Cos(rotation);
                        rs = (float)Math.Sin(rotation);
                    }

                    for (int j = 0; j < face.Vertices.Count; j++)
                    {
                        warp_Vertex vert;
                        Vertex      v   = face.Vertices[j];
                        warp_Vector pos = ConvertVector(v.Position);
                        if (teFace.TexMapType == MappingType.Planar)
                        {
                            UVPlanarMap(v, prim.Scale, out tu, out tv);
                        }
                        else
                        {
                            tu = v.TexCoord.X - 0.5f;
                            tv = 0.5f - v.TexCoord.Y;
                        }
                        if (rotation != 0)
                        {
                            float tur = tu * rc - tv * rs;
                            float tvr = tu * rs + tv * rc;
                            tur *= scaleu;
                            tur += offsetu;

                            tvr *= scalev;
                            tvr += offsetv;
                            vert = new warp_Vertex(pos, tur, tvr);
                        }
                        else
                        {
                            tu  *= scaleu;
                            tu  += offsetu;
                            tv  *= scalev;
                            tv  += offsetv;
                            vert = new warp_Vertex(pos, tu, tv);
                        }

                        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]);
                }

                faceObj.scaleSelf(prim.Scale.X, prim.Scale.Z, prim.Scale.Y);
                faceObj.transform(m);
                faceObj.setPos(primPos);

                renderer.Scene.addObject(meshName, faceObj);
                renderer.SetObjectMaterial(meshName, materialName);
            }
        }
Пример #14
0
 public void project(warp_Matrix m)
 {
     matrix2 = m.getClone();
     matrix2.transform(m);
     v2 = v.transform(matrix2);
 }
Пример #15
0
 public void project(warp_Matrix normalProjection)
 {
     n2   = n.transform(normalProjection);
     dist = getDist();
 }
Пример #16
0
        private void CreatePrim(WarpRenderer renderer, SceneObjectPart prim,
                                bool useTextures)
        {
            const float MIN_SIZE_SQUARE = 4f;

            if ((PCode)prim.Shape.PCode != PCode.Prim)
            {
                return;
            }
            float primScaleLenSquared = prim.Scale.LengthSquared();

            if (primScaleLenSquared < MIN_SIZE_SQUARE)
            {
                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;
            }

            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 + i.ToString();

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

                warp_Object faceObj = new warp_Object();
                for (int j = 0; j < face.Vertices.Count; j++)
                {
                    Vertex      v    = face.Vertices[j];
                    warp_Vector pos  = ConvertVector(v.Position);
                    warp_Vertex vert = new warp_Vertex(pos, 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 && primScaleLenSquared > m_texturePrimSize * m_texturePrimSize)
                {
                    materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID);
                }
                else
                {
                    materialName = GetOrCreateMaterial(renderer, faceColor);
                }

                warp_Vector     primPos = ConvertVector(prim.GetWorldPosition());
                warp_Quaternion primRot = ConvertQuaternion(prim.GetWorldRotation());
                warp_Matrix     m       = warp_Matrix.quaternionMatrix(primRot);
                faceObj.transform(m);
                faceObj.setPos(primPos);
                faceObj.scaleSelf(prim.Scale.X, prim.Scale.Z, prim.Scale.Y);

                renderer.Scene.addObject(meshName, faceObj);
                renderer.SetObjectMaterial(meshName, materialName);
            }
        }
Пример #17
0
 public void rotateSelf(warp_Matrix m)
 {
     preTransform(m);
 }
Пример #18
0
		public void rotate (warp_Matrix m)
		{
			transform (m);
		}
Пример #19
0
		public static warp_Matrix scaleMatrix (float dx, float dy, float dz)
		{
			warp_Matrix m = new warp_Matrix ();
			
			m.m00 = dx;
			m.m11 = dy;
			m.m22 = dz;

			return m;
		}
Пример #20
0
		public static warp_Matrix multiply (warp_Matrix m1, warp_Matrix m2)
		{
			warp_Matrix m = new warp_Matrix ();

			m.m00 = m1.m00 * m2.m00 + m1.m01 * m2.m10 + m1.m02 * m2.m20;
			m.m01 = m1.m00 * m2.m01 + m1.m01 * m2.m11 + m1.m02 * m2.m21;
			m.m02 = m1.m00 * m2.m02 + m1.m01 * m2.m12 + m1.m02 * m2.m22;
			m.m03 = m1.m00 * m2.m03 + m1.m01 * m2.m13 + m1.m02 * m2.m23 + m1.m03;
			m.m10 = m1.m10 * m2.m00 + m1.m11 * m2.m10 + m1.m12 * m2.m20;
			m.m11 = m1.m10 * m2.m01 + m1.m11 * m2.m11 + m1.m12 * m2.m21;
			m.m12 = m1.m10 * m2.m02 + m1.m11 * m2.m12 + m1.m12 * m2.m22;
			m.m13 = m1.m10 * m2.m03 + m1.m11 * m2.m13 + m1.m12 * m2.m23 + m1.m13;
			m.m20 = m1.m20 * m2.m00 + m1.m21 * m2.m10 + m1.m22 * m2.m20;
			m.m21 = m1.m20 * m2.m01 + m1.m21 * m2.m11 + m1.m22 * m2.m21;
			m.m22 = m1.m20 * m2.m02 + m1.m21 * m2.m12 + m1.m22 * m2.m22;
			m.m23 = m1.m20 * m2.m03 + m1.m21 * m2.m13 + m1.m22 * m2.m23 + m1.m23;
			
			return m;
		}
Пример #21
0
		public void transform (warp_Matrix n)
		{
			warp_Matrix m = this.getClone ();

			m00 = n.m00 * m.m00 + n.m01 * m.m10 + n.m02 * m.m20;
			m01 = n.m00 * m.m01 + n.m01 * m.m11 + n.m02 * m.m21;
			m02 = n.m00 * m.m02 + n.m01 * m.m12 + n.m02 * m.m22;
			m03 = n.m00 * m.m03 + n.m01 * m.m13 + n.m02 * m.m23 + n.m03;
			m10 = n.m10 * m.m00 + n.m11 * m.m10 + n.m12 * m.m20;
			m11 = n.m10 * m.m01 + n.m11 * m.m11 + n.m12 * m.m21;
			m12 = n.m10 * m.m02 + n.m11 * m.m12 + n.m12 * m.m22;
			m13 = n.m10 * m.m03 + n.m11 * m.m13 + n.m12 * m.m23 + n.m13;
			m20 = n.m20 * m.m00 + n.m21 * m.m10 + n.m22 * m.m20;
			m21 = n.m20 * m.m01 + n.m21 * m.m11 + n.m22 * m.m21;
			m22 = n.m20 * m.m02 + n.m21 * m.m12 + n.m22 * m.m22;
			m23 = n.m20 * m.m03 + n.m21 * m.m13 + n.m22 * m.m23 + n.m23;
		}
Пример #22
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);
            }
        }
Пример #23
0
		public void project(warp_Matrix m)
		{
			matrix2 = m.getClone();
			matrix2.transform(m);
			v2 = v.transform(matrix2);
		}
Пример #24
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);
            }
        }
Пример #25
0
		public static warp_Matrix quaternionMatrix (warp_Quaternion quat)
		{
			warp_Matrix m = new warp_Matrix ();

   
			float xx = quat.X * quat.X;
			float xy = quat.X * quat.Y;
			float xz = quat.X * quat.Z;
			float xw = quat.X * quat.W;
			float yy = quat.Y * quat.Y;
			float yz = quat.Y * quat.Z;
			float yw = quat.Y * quat.W;
			float zz = quat.Z * quat.Z;
			float zw = quat.Z * quat.W;

			m.m00 = 1 - 2 * (yy + zz);
			m.m01 = 2 * (xy - zw);
			m.m02 = 2 * (xz + yw);
			m.m10 = 2 * (xy + zw);
			m.m11 = 1 - 2 * (xx + zz);
			m.m12 = 2 * (yz - xw);
			m.m20 = 2 * (xz - yw);
			m.m21 = 2 * (yz + xw);
			m.m22 = 1 - 2 * (xx + yy);

			m.m03 = m.m13 = m.m23 = m.m30 = m.m31 = m.m32 = 0;
			m.m33 = 1;
            
			return m;
		}
Пример #26
0
		public warp_Matrix inverse ()
		{
			warp_Matrix m = new warp_Matrix ();

			float q1 = m12;
			float q6 = m10 * m01;
			float q7 = m10 * m21;
			float q8 = m02;
			float q13 = m20 * m01;
			float q14 = m20 * m11;
			float q21 = m02 * m21;
			float q22 = m03 * m21;
			float q25 = m01 * m12;
			float q26 = m01 * m13;
			float q27 = m02 * m11;
			float q28 = m03 * m11;
			float q29 = m10 * m22;
			float q30 = m10 * m23;
			float q31 = m20 * m12;
			float q32 = m20 * m13;
			float q35 = m00 * m22;
			float q36 = m00 * m23;
			float q37 = m20 * m02;
			float q38 = m20 * m03;
			float q41 = m00 * m12;
			float q42 = m00 * m13;
			float q43 = m10 * m02;
			float q44 = m10 * m03;
			float q45 = m00 * m11;
			float q48 = m00 * m21;
			float q49 = q45 * m22 - q48 * q1 - q6 * m22 + q7 * q8;
			float q50 = q13 * q1 - q14 * q8;
			float q51 = 1 / (q49 + q50);

			m.m00 = (m11 * m22 * m33 - m11 * m23 * m32 - m21 * m12 * m33 + m21 * m13 * m32 + m31 * m12 * m23 - m31 * m13 * m22) * q51;
			m.m01 = -(m01 * m22 * m33 - m01 * m23 * m32 - q21 * m33 + q22 * m32) * q51;
			m.m02 = (q25 * m33 - q26 * m32 - q27 * m33 + q28 * m32) * q51;
			m.m03 = -(q25 * m23 - q26 * m22 - q27 * m23 + q28 * m22 + q21 * m13 - q22 * m12) * q51;
			m.m10 = -(q29 * m33 - q30 * m32 - q31 * m33 + q32 * m32) * q51;
			m.m11 = (q35 * m33 - q36 * m32 - q37 * m33 + q38 * m32) * q51;
			m.m12 = -(q41 * m33 - q42 * m32 - q43 * m33 + q44 * m32) * q51;
			m.m13 = (q41 * m23 - q42 * m22 - q43 * m23 + q44 * m22 + q37 * m13 - q38 * m12) * q51;
			m.m20 = (q7 * m33 - q30 * m31 - q14 * m33 + q32 * m31) * q51;
			m.m21 = -(q48 * m33 - q36 * m31 - q13 * m33 + q38 * m31) * q51;
			m.m22 = (q45 * m33 - q42 * m31 - q6 * m33 + q44 * m31) * q51;
			m.m23 = -(q45 * m23 - q42 * m21 - q6 * m23 + q44 * m21 + q13 * m13 - q38 * m11) * q51;

			return m;
		}
Пример #27
0
		public static warp_Matrix rotateMatrix (float dx, float dy, float dz)
		{
			warp_Matrix res = new warp_Matrix ();

			float SIN;
			float COS;

			if (dx != 0)
			{
				warp_Matrix m = new warp_Matrix ();
				SIN = warp_Math.sin (dx);
				COS = warp_Math.cos (dx);
				m.m11 = COS;
				m.m12 = SIN;
				m.m21 = -SIN;
				m.m22 = COS;
				
				res.transform (m);
			}
			if (dy != 0)
			{
				warp_Matrix m = new warp_Matrix ();
				SIN = warp_Math.sin (dy);
				COS = warp_Math.cos (dy);
				m.m00 = COS;
				m.m02 = SIN;
				m.m20 = -SIN;
				m.m22 = COS;
				
				res.transform (m);
			}
			if (dz != 0)
			{
				warp_Matrix m = new warp_Matrix ();
				SIN = warp_Math.sin (dz);
				COS = warp_Math.cos (dz);
				m.m00 = COS;
				m.m01 = SIN;
				m.m10 = -SIN;
				m.m11 = COS;
				
				res.transform (m);
			}

			return res;
		}
 public void rotate(warp_Matrix m)
 {
     matrix.rotate(m);
     normalmatrix.rotate(m);
 }
Пример #29
0
		public void rotateSelf (warp_Matrix m)
		{
			preTransform (m);
		}
Пример #30
0
 public void rotate(warp_Matrix m)
 {
     transform(m);
 }
Пример #31
0
		public void preTransform (warp_Matrix n)
		{
			warp_Matrix m = this.getClone ();

			m00 = m.m00 * n.m00 + m.m01 * n.m10 + m.m02 * n.m20;
			m01 = m.m00 * n.m01 + m.m01 * n.m11 + m.m02 * n.m21;
			m02 = m.m00 * n.m02 + m.m01 * n.m12 + m.m02 * n.m22;
			m03 = m.m00 * n.m03 + m.m01 * n.m13 + m.m02 * n.m23 + m.m03;
			m10 = m.m10 * n.m00 + m.m11 * n.m10 + m.m12 * n.m20;
			m11 = m.m10 * n.m01 + m.m11 * n.m11 + m.m12 * n.m21;
			m12 = m.m10 * n.m02 + m.m11 * n.m12 + m.m12 * n.m22;
			m13 = m.m10 * n.m03 + m.m11 * n.m13 + m.m12 * n.m23 + m.m13;
			m20 = m.m20 * n.m00 + m.m21 * n.m10 + m.m22 * n.m20;
			m21 = m.m20 * n.m01 + m.m21 * n.m11 + m.m22 * n.m21;
			m22 = m.m20 * n.m02 + m.m21 * n.m12 + m.m22 * n.m22;
			m23 = m.m20 * n.m03 + m.m21 * n.m13 + m.m22 * n.m23 + m.m23;
		}
        void CreatePrim(WarpRenderer renderer, ISceneChildEntity prim, bool texturePrims)
        {
            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 (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("[WarpTile generator]: Exception creating prim, " + ex);
            }
        }
Пример #33
0
		/*
		public string toString()
		{
			// todo
		}
*/
		public warp_Matrix getClone ()
		{
			warp_Matrix m = new warp_Matrix ();

			m.m00 = m00;
			m.m01 = m01;
			m.m02 = m02;
			m.m03 = m03;
			m.m10 = m10;
			m.m11 = m11;
			m.m12 = m12;
			m.m13 = m13;
			m.m20 = m20;
			m.m21 = m21;
			m.m22 = m22;
			m.m23 = m23;
			m.m30 = m30;
			m.m31 = m31;
			m.m32 = m32;
			m.m33 = m33;
			
			return m;
		}
Пример #34
0
		public void project (warp_Matrix normalProjection)
		{
			n2 = n.transform (normalProjection);
			dist = getDist ();
		}
Пример #35
0
		public static warp_Matrix shiftMatrix (float dx, float dy, float dz)
			// matrix for shifting
		{
			warp_Matrix m = new warp_Matrix ();
			m.m03 = dx;
			m.m13 = dy;
			m.m23 = dz;
			return m;
		}
 public void transform(warp_Matrix m)
 {
     matrix.transform(m);
     normalmatrix.transform(m);
 }