Beispiel #1
0
 public MaterialInfo(OMVR.Face face, OMV.Primitive.TextureEntryFace defaultTexture)
 {
     handle      = new EntityHandleUUID();
     faceTexture = face.TextureFace;
     if (faceTexture == null)
     {
         faceTexture = defaultTexture;
     }
     textureID = faceTexture.TextureID;
     if (faceTexture.RGBA.A != 1f)
     {
         fullAlpha = true;
     }
     RGBA     = faceTexture.RGBA;
     bump     = faceTexture.Bump;
     glow     = faceTexture.Glow;
     shiny    = faceTexture.Shiny;
     twoSided = ConvOAR.Globals.parms.P <bool>("DoubleSided");
 }
Beispiel #2
0
 public static void SimpleOutputValue(StreamWriter outt, Object val, int level)
 {
     if (val == null)
     {
         ConvOAR.Globals.log.ErrorFormat("SimpleJSONOutput: called with NULL value");
         val = "null";
     }
     if (val is string)
     {
         // escape any double quotes in the string value
         outt.Write("\"" + ((string)val).Replace("\"", "\\\"") + "\"");
     }
     else if (val is bool)
     {
         outt.Write((bool)val ? "true" : "false");
     }
     else if (val is OMV.Color4)
     {
         OMV.Color4 col = (OMV.Color4)val;
         outt.Write(ParamsToJSONArray(col.R, col.G, col.B, col.A));
     }
     else if (val is OMV.Matrix4)
     {
         OMV.Matrix4 mat = (OMV.Matrix4)val;
         outt.Write(ParamsToJSONArray(
                        mat[0, 0], mat[0, 1], mat[0, 2], mat[0, 3],
                        mat[1, 0], mat[1, 1], mat[1, 2], mat[1, 3],
                        mat[2, 0], mat[2, 1], mat[2, 2], mat[2, 3],
                        mat[3, 0], mat[3, 1], mat[3, 2], mat[3, 3]
                        ));
     }
     else if (val is OMV.Vector3)
     {
         OMV.Vector3 vect = (OMV.Vector3)val;
         outt.Write(ParamsToJSONArray(vect.X, vect.Y, vect.Z));
     }
     else if (val is OMV.Quaternion)
     {
         OMV.Quaternion quan = (OMV.Quaternion)val;
         outt.Write(ParamsToJSONArray(quan.X, quan.Y, quan.Z, quan.W));
     }
     // else if (val.GetType().IsArray) {
     else if (val is Array)
     {
         outt.Write(" [ ");
         // Object[] values = (Object[])val;
         Array values = val as Array;
         bool  first  = true;
         for (int ii = 0; ii < values.Length; ii++)
         {
             if (!first)
             {
                 outt.Write(",");
             }
             first = false;
             SimpleOutputValue(outt, values.GetValue(ii), level + 1);
         }
         outt.Write(" ]");
     }
     else if (val is Dictionary <string, Object> )
     {
         Dictionary <string, Object> dict = (Dictionary <string, Object>)val;
         outt.Write(" { ");
         bool first = true;
         foreach (var key in dict.Keys)
         {
             if (!first)
             {
                 outt.Write(",");
             }
             first = false;
             outt.Write("\n" + Indent(level) + "\"" + key + "\": ");
             SimpleOutputValue(outt, dict[key], level + 1);
         }
         outt.Write("\n" + Indent(level) + " }");
     }
     else if (val is float && Single.IsNaN((float)val))
     {
         ConvOAR.Globals.log.ErrorFormat("JSONHelpers: Value is Single.NaN!!");
         outt.Write("0");
     }
     else if (val is double && Double.IsNaN((double)val))
     {
         ConvOAR.Globals.log.ErrorFormat("JSONHelpers: Value is Double.NaN!!");
         outt.Write("0");
     }
     else
     {
         var ret = val.ToString();
         if (ret == "NaN")
         {
             ConvOAR.Globals.log.ErrorFormat("JSONHelpers: Value is NaN!!");
         }
         else
         {
             outt.Write(val);
         }
     }
 }
        //int[] CubeMapDefines = new int[]
        //{
        //    Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
        //};

        private void RenderPrims(RegionContextBase rcontext, RegionRenderInfo rri)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);

            lock (rri.renderPrimList) {
                bool firstPass = true;
                // GL.Disable(EnableCap.Blend);
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                GL.Enable(EnableCap.DepthTest);

                GL.Enable(EnableCap.Normalize);

                GL.EnableClientState(ArrayCap.TextureCoordArray);
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.EnableClientState(ArrayCap.NormalArray);


StartRender:

                List <RenderablePrim> rpList = new List <RenderablePrim>(rri.renderPrimList.Values);
                // sort back to front
                rpList.Sort(delegate(RenderablePrim rp1, RenderablePrim rp2) {
                    return((int)(((OMV.Vector3.Distance(m_renderer.Camera.Position, rp1.Prim.Position)) -
                                  (OMV.Vector3.Distance(m_renderer.Camera.Position, rp2.Prim.Position))) * 100f));
                });
                foreach (RenderablePrim rp in rpList)
                {
                    // if this prim is not visible, just loop
                    if (!rp.isVisible)
                    {
                        continue;
                    }

                    RenderablePrim prp  = RenderablePrim.Empty;
                    OMV.Primitive  prim = rp.Prim;

                    if (prim.ParentID != 0)
                    {
                        // Get the parent reference
                        if (!rri.renderPrimList.TryGetValue(prim.ParentID, out prp))
                        {
                            // Can't render a child with no parent prim, skip it
                            continue;
                        }
                    }

                    GL.PushName(prim.LocalID);
                    GL.PushMatrix();

                    if (prim.ParentID != 0)
                    {
                        // Apply parent translation and rotation
                        GL.MultMatrix(Math3D.CreateTranslationMatrix(prp.Position));
                        GL.MultMatrix(Math3D.CreateRotationMatrix(prp.Rotation));
                    }

                    // Apply prim translation and rotation
                    GL.MultMatrix(Math3D.CreateTranslationMatrix(rp.Position));
                    // apply region offset for multiple regions
                    GL.MultMatrix(Math3D.CreateTranslationMatrix(CalcRegionOffset(rp.rcontext)));
                    GL.MultMatrix(Math3D.CreateRotationMatrix(rp.Rotation));

                    // Scale the prim
                    GL.Scale(prim.Scale.X, prim.Scale.Y, prim.Scale.Z);

                    // Draw the prim faces
                    for (int j = 0; j < rp.Mesh.Faces.Count; j++)
                    {
                        OMVR.Face  face      = rp.Mesh.Faces[j];
                        FaceData   data      = (FaceData)face.UserData;
                        OMV.Color4 color     = face.TextureFace.RGBA;
                        bool       alpha     = false;
                        int        textureID = 0;

                        if (color.A < 1.0f)
                        {
                            alpha = true;
                        }

                        TextureInfo info;
                        if (face.TextureFace.TextureID != OMV.UUID.Zero &&
                            face.TextureFace.TextureID != OMV.Primitive.TextureEntry.WHITE_TEXTURE &&
                            m_renderer.Textures.TryGetValue(face.TextureFace.TextureID, out info))
                        {
                            if (info.Alpha)
                            {
                                alpha = true;
                            }

                            textureID = info.ID;
                            // if textureID has not been set, need to generate the mipmaps
                            if (textureID == 0)
                            {
                                GenerateMipMaps(rp.acontext, face.TextureFace.TextureID, out textureID);
                                info.ID = textureID;
                            }

                            // Enable texturing for this face
                            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                        }
                        else
                        {
                            if (face.TextureFace.TextureID == OMV.Primitive.TextureEntry.WHITE_TEXTURE ||
                                face.TextureFace.TextureID == OMV.UUID.Zero)
                            {
                                GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill);
                            }
                            else
                            {
                                GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
                            }
                        }

                        // if (firstPass && !alpha || !firstPass && alpha) {
                        // GL.Color4(color.R, color.G, color.B, color.A);
                        float[] matDiffuse = { color.R, color.G, color.B, color.A };
                        GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, matDiffuse);

                        // Bind the texture
                        if (textureID != 0)
                        {
                            GL.Enable(EnableCap.Texture2D);
                            GL.BindTexture(TextureTarget.Texture2D, textureID);
                        }
                        else
                        {
                            GL.Disable(EnableCap.Texture2D);
                        }

                        GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, data.TexCoords);
                        GL.VertexPointer(3, VertexPointerType.Float, 0, data.Vertices);
                        GL.NormalPointer(NormalPointerType.Float, 0, data.Normals);
                        GL.DrawElements(BeginMode.Triangles, data.Indices.Length, DrawElementsType.UnsignedShort, data.Indices);
                        // }
                    }

                    GL.PopMatrix();
                    GL.PopName();
                }

                /*
                 * if (firstPass) {
                 *  firstPass = false;
                 *  GL.Enable(EnableCap.Blend);
                 *  GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                 *  // GL.Disable(EnableCap.DepthTest);
                 *
                 *  goto StartRender;
                 * }
                 */
            }

            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Texture2D);
        }
            /// <summary>
            /// Decodes a byte[] array into a ParticleSystem Object
            /// </summary>
            /// <param name="data">ParticleSystem object</param>
            /// <param name="pos">Start position for BitPacker</param>
            public ParticleSystem(byte[] data, int pos)
            {
                PartStartGlow   = 0f;
                PartEndGlow     = 0f;
                BlendFuncSource = (byte)BlendFunc.SourceAlpha;
                BlendFuncDest   = (byte)BlendFunc.OneMinusSourceAlpha;

                CRC               = PartFlags = 0;
                Pattern           = SourcePattern.None;
                MaxAge            = StartAge = InnerAngle = OuterAngle = BurstRate = BurstRadius = BurstSpeedMin =
                    BurstSpeedMax = 0.0f;
                BurstPartCount    = 0;
                AngularVelocity   = PartAcceleration = Vector3.Zero;
                Texture           = Target = UUID.Zero;
                PartDataFlags     = ParticleDataFlags.None;
                PartMaxAge        = 0.0f;
                PartStartColor    = PartEndColor = Color4.Black;
                PartStartScaleX   = PartStartScaleY = PartEndScaleX = PartEndScaleY = 0.0f;

                int     size = data.Length - pos;
                BitPack pack = new BitPack(data, pos);

                if (size == LegacyDataBlockSize)
                {
                    UnpackSystem(ref pack);
                    UnpackLegacyData(ref pack);
                }
                else if (size > LegacyDataBlockSize && size <= MaxDataBlockSize)
                {
                    int sysSize = pack.UnpackBits(32);
                    if (sysSize != SysDataSize)
                    {
                        return;                         // unkown particle system data size
                    }
                    UnpackSystem(ref pack);
                    int dataSize = pack.UnpackBits(32);
                    UnpackLegacyData(ref pack);


                    if ((PartDataFlags & ParticleDataFlags.DataGlow) == ParticleDataFlags.DataGlow)
                    {
                        if (pack.Data.Length - pack.BytePos < 2)
                        {
                            return;
                        }
                        uint glow = pack.UnpackUBits(8);
                        PartStartGlow = glow / 255f;
                        glow          = pack.UnpackUBits(8);
                        PartEndGlow   = glow / 255f;
                    }

                    if ((PartDataFlags & ParticleDataFlags.DataBlend) == ParticleDataFlags.DataBlend)
                    {
                        if (pack.Data.Length - pack.BytePos < 2)
                        {
                            return;
                        }
                        BlendFuncSource = (byte)pack.UnpackUBits(8);
                        BlendFuncDest   = (byte)pack.UnpackUBits(8);
                    }
                }
            }