Ejemplo n.º 1
0
        public override Model Clone()
        {
            Joint j = new Joint();

            j.copyFrom(this);

            j.jointIndex = this.jointIndex;
            j.BindMat    = this.BindMat;
            j.invBMat    = this.invBMat;
            j.color      = this.color;

            j.meshVao    = new GLMeshVao();
            j.instanceId = GLMeshBufferManager.addInstance(ref j.meshVao, j);
            GLMeshBufferManager.setInstanceWorldMat(j.meshVao, j.instanceId, Matrix4.Identity);
            j.meshVao.type     = TYPES.JOINT;
            j.meshVao.metaData = new MeshMetaData();
            //TODO: Find a place to keep references from the Joint GLMeshVAOs
            j.meshVao.vao      = new Primitives.LineSegment(this.children.Count, new Vector3(1.0f, 0.0f, 0.0f)).getVAO();
            j.meshVao.material = Common.RenderState.activeResMgr.GLmaterials["jointMat"];

            //Clone children
            foreach (Model child in children)
            {
                Model new_child = child.Clone();
                new_child.parent = j;
                j.children.Add(new_child);
            }

            return(j);
        }
Ejemplo n.º 2
0
        public override Model Clone()
        {
            Scene new_s = new Scene();

            new_s.copyFrom(this);

            new_s.meshVao    = this.meshVao;
            new_s.instanceId = GLMeshBufferManager.addInstance(ref new_s.meshVao, this);

            //Clone children
            foreach (Model child in children)
            {
                Model new_child = child.Clone();
                new_child.parent = new_s;
                new_s.children.Add(new_child);
            }

            //Recursively update parentScene to all the new objects
            new_s.setParentScene(new_s);

            //Initialize jointDictionary
            new_s.jointDict.Clear();
            new_s.setupJointDict(new_s);

            return(new_s);
        }
Ejemplo n.º 3
0
        protected Light(Light input) : base(input)
        {
            Color      = input.Color;
            intensity  = input.intensity;
            falloff    = input.falloff;
            fov        = input.fov;
            light_type = input.light_type;
            strct      = input.strct;

            //Initialize new MeshVao
            meshVao                     = new GLMeshVao();
            meshVao.type                = TYPES.LIGHT;
            meshVao.vao                 = new Primitives.LineSegment(1, new Vector3(1.0f, 0.0f, 0.0f)).getVAO();
            meshVao.metaData            = new MeshMetaData();
            meshVao.metaData.batchcount = 2;
            meshVao.material            = RenderState.activeResMgr.GLmaterials["lightMat"];
            instanceId                  = GLMeshBufferManager.addInstance(ref meshVao, this); //Add instance


            //Copy Matrices
            lightProjectionMatrix = input.lightProjectionMatrix;
            lightSpaceMatrices    = new Matrix4[6];
            for (int i = 0; i < 6; i++)
            {
                lightSpaceMatrices[i] = input.lightSpaceMatrices[i];
            }

            update_struct();
            RenderState.activeResMgr.GLlights.Add(this);
        }
Ejemplo n.º 4
0
        public override void updateMeshInfo(bool lod_filter = false)
        {
            //We do not apply frustum occlusion on joint objects
            if (renderable && (children.Count > 0))
            {
                //Update Vertex Buffer based on the new positions
                float[] verts     = new float[2 * children.Count * 3];
                int     arraysize = 2 * children.Count * 3 * sizeof(float);

                for (int i = 0; i < children.Count; i++)
                {
                    verts[i * 6 + 0] = worldPosition.X;
                    verts[i * 6 + 1] = worldPosition.Y;
                    verts[i * 6 + 2] = worldPosition.Z;
                    verts[i * 6 + 3] = children[i].worldPosition.X;
                    verts[i * 6 + 4] = children[i].worldPosition.Y;
                    verts[i * 6 + 5] = children[i].worldPosition.Z;
                }

                meshVao.metaData.batchcount = 2 * children.Count;

                GL.BindVertexArray(meshVao.vao.vao_id);
                GL.BindBuffer(BufferTarget.ArrayBuffer, meshVao.vao.vertex_buffer_object);
                //Add verts data, color data should stay the same
                GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)arraysize, verts);
                instanceId = GLMeshBufferManager.addInstance(meshVao, this, Matrix4.Identity, Matrix4.Identity, Matrix4.Identity);
            }

            base.updateMeshInfo();
        }
Ejemplo n.º 5
0
        public Light()
        {
            type       = TYPES.LIGHT;
            fov        = 360;
            intensity  = 1.0f;
            falloff    = ATTENUATION_TYPE.CONSTANT;
            light_type = LIGHT_TYPE.POINT;

            //Initialize new MeshVao
            meshVao                     = new GLMeshVao();
            meshVao.type                = TYPES.LIGHT;
            meshVao.vao                 = new Primitives.LineSegment(1, new Vector3(1.0f, 0.0f, 0.0f)).getVAO();
            meshVao.metaData            = new MeshMetaData();
            meshVao.metaData.batchcount = 2;
            meshVao.material            = Common.RenderState.activeResMgr.GLmaterials["lightMat"];
            instanceId                  = GLMeshBufferManager.addInstance(ref meshVao, this); // Add instance

            //Init projection Matrix
            lightProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathUtils.radians(90), 1.0f, 1.0f, 300f);

            //Init lightSpace Matrices
            lightSpaceMatrices = new Matrix4[6];
            for (int i = 0; i < 6; i++)
            {
                lightSpaceMatrices[i] = Matrix4.Identity * lightProjectionMatrix;
            }

            //Catch changes to MVector from the UI
            color = new MVector4(1.0f);
            color.PropertyChanged += catchPropertyChanged;
        }
Ejemplo n.º 6
0
        public override void updateMeshInfo(bool lod_filter = false)
        {
            if (lod_filter)
            {
                strct.position.W = 0.0f; //Force not renderable
                base.updateMeshInfo();
                RenderStats.occludedNum += 1;
            }
            else if (RenderState.renderViewSettings.RenderLights && renderable)
            {
                //End Point
                Vector4 ep;
                //Lights with 360 FOV are points
                if (Math.Abs(FOV - 360.0f) <= 1e-4)
                {
                    ep         = new Vector4(0.0f, 0.0f, 0.0f, 1.0f);
                    light_type = LIGHT_TYPE.POINT;
                }
                else
                {
                    ep         = new Vector4(0.0f, 0.0f, -1.0f, 0.0f);
                    light_type = LIGHT_TYPE.SPOT;
                }

                ep        = ep * _localRotation;
                direction = ep.Xyz; //Set spotlight direction
                update_struct();

                //Update Vertex Buffer based on the new data
                float[] verts     = new float[6];
                int     arraysize = 6 * sizeof(float);

                //Origin Point
                verts[0] = worldPosition.X;
                verts[1] = worldPosition.Y;
                verts[2] = worldPosition.Z;

                ep.X += worldPosition.X;
                ep.Y += worldPosition.Y;
                ep.Z += worldPosition.Z;

                verts[3] = ep.X;
                verts[4] = ep.Y;
                verts[5] = ep.Z;

                GL.BindVertexArray(meshVao.vao.vao_id);
                GL.BindBuffer(BufferTarget.ArrayBuffer, meshVao.vao.vertex_buffer_object);
                //Add verts data, color data should stay the same
                GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)arraysize, verts);

                //Uplod worldMat to the meshVao
                instanceId = GLMeshBufferManager.addInstance(meshVao, this, Matrix4.Identity, Matrix4.Identity, Matrix4.Identity); //Add instance
            }
            else
            {
                base.updateMeshInfo();
                updated = false; //All done
            }
        }
Ejemplo n.º 7
0
        public gizmo()
        {
            type = TYPES.GIZMO;

            //Assemble geometry in the constructor
            meshVao    = Common.RenderState.activeResMgr.GLPrimitiveMeshVaos["default_translation_gizmo"];
            instanceId = GLMeshBufferManager.addInstance(ref meshVao, this);
        }
Ejemplo n.º 8
0
        public override void updateMeshInfo(bool lod_filter = false)
        {
            if (renderable)
            {
                instanceId = GLMeshBufferManager.addInstance(ref meshVao, this);
                base.updateMeshInfo(lod_filter);
                return;
            }

            base.updateMeshInfo(lod_filter);
        }
Ejemplo n.º 9
0
        //Geometry Setup
        //BSphere calculator
        public GLVao setupBSphere(int instance_id)
        {
            float   radius     = 0.5f * (metaData.AABBMIN - metaData.AABBMAX).Length;
            Vector4 bsh_center = new Vector4(metaData.AABBMIN + 0.5f * (metaData.AABBMAX - metaData.AABBMIN), 1.0f);

            Matrix4 t_mat = GLMeshBufferManager.getInstanceWorldMat(this, instance_id);

            bsh_center = bsh_center * t_mat;

            //Create Sphere vbo
            return(new Primitives.Sphere(bsh_center.Xyz, radius).getVAO());
        }
Ejemplo n.º 10
0
        public Locator()
        {
            //Set type
            type = TYPES.LOCATOR;
            //Set BBOX
            AABBMIN = new Vector3(-0.1f, -0.1f, -0.1f);
            AABBMAX = new Vector3(0.1f, 0.1f, 0.1f);

            //Assemble geometry in the constructor
            meshVao    = Common.RenderState.activeResMgr.GLPrimitiveMeshVaos["default_cross"];
            instanceId = GLMeshBufferManager.addInstance(ref meshVao, this);
        }
Ejemplo n.º 11
0
        protected Joint(Joint input) : base(input)
        {
            this.jointIndex = input.jointIndex;
            this.BindMat    = input.BindMat;
            this.invBMat    = input.invBMat;
            this.color      = input.color;

            meshVao    = new GLMeshVao();
            instanceId = GLMeshBufferManager.addInstance(ref meshVao, this);
            GLMeshBufferManager.setInstanceWorldMat(meshVao, instanceId, Matrix4.Identity);
            meshVao.type     = TYPES.JOINT;
            meshVao.metaData = new MeshMetaData();
            //TODO: Find a place to keep references from the joint GLMeshVAOs
            meshVao.vao      = new Primitives.LineSegment(children.Count, new Vector3(1.0f, 0.0f, 0.0f)).getVAO();
            meshVao.material = Common.RenderState.activeResMgr.GLmaterials["jointMat"];
        }
Ejemplo n.º 12
0
        public override Model Clone()
        {
            Mesh new_m = new Mesh();

            new_m.copyFrom(this);

            new_m.meshVao    = this.meshVao;
            new_m.instanceId = GLMeshBufferManager.addInstance(ref new_m.meshVao, new_m);

            //Clone children
            foreach (Model child in children)
            {
                Model new_child = child.Clone();
                new_child.parent = new_m;
                new_m.children.Add(new_child);
            }

            return(new_m);
        }
Ejemplo n.º 13
0
        public override void updateMeshInfo(bool lod_filter = false)
        {
            if (!renderable || lod_filter)
            {
                base.updateMeshInfo(lod_filter);
                return;
            }

            bool fr_status       = Common.RenderState.activeCam.frustum_occlude(meshVao, worldMat * RenderState.rotMat);
            bool occluded_status = !fr_status && Common.RenderState.renderSettings.UseFrustumCulling;

            //Recalculations && Data uploads
            if (!occluded_status)
            {
                instanceId = GLMeshBufferManager.addInstance(ref meshVao, this);
            }

            base.updateMeshInfo();
            updated = false; //All done
        }
Ejemplo n.º 14
0
        public override void updateMeshInfo(bool lod_filter = false)
        {
#if (DEBUG)
            if (instanceId < 0)
            {
                Console.WriteLine("test");
            }
            if (meshVao.BoneRemapIndicesCount > 128)
            {
                Console.WriteLine("test");
            }
#endif

            if (!active || !renderable || (parentScene.activeLOD != LodLevel) && RenderState.renderSettings.LODFiltering)
            {
                base.updateMeshInfo(true);
                RenderStats.occludedNum += 1;
                return;
            }

            bool fr_status       = Common.RenderState.activeCam.frustum_occlude(meshVao, worldMat * RenderState.rotMat);
            bool occluded_status = !fr_status && Common.RenderState.renderSettings.UseFrustumCulling;

            //Recalculations && Data uploads
            if (!occluded_status)
            {
                /*
                 * //Apply LOD filtering
                 * if (hasLOD && Common.RenderOptions.LODFiltering)
                 * //if (false)
                 * {
                 *  //Console.WriteLine("Active LoD {0}", parentScene.activeLOD);
                 *  if (parentScene.activeLOD != LodLevel)
                 *  {
                 *      meshVao.setInstanceOccludedStatus(instanceId, true);
                 *      base.updateMeshInfo();
                 *      return;
                 *  }
                 * }
                 */

                instanceId = GLMeshBufferManager.addInstance(ref meshVao, this);

                //Upload commonperMeshUniforms
                GLMeshBufferManager.setInstanceUniform4(meshVao, instanceId,
                                                        "gUserDataVec4", CommonPerMeshUniforms["gUserDataVec4"].Vec.Vec);

                if (Skinned)
                {
                    //Update the mesh remap matrices and continue with the transform updates
                    meshVao.setSkinMatrices(parentScene, instanceId);
                    //Fallback
                    //main_Vao.setDefaultSkinMatrices();
                }
            }
            else
            {
                Common.RenderStats.occludedNum += 1;
            }

            //meshVao.setInstanceOccludedStatus(instanceId, occluded_status);
            base.updateMeshInfo();
        }
Ejemplo n.º 15
0
        public void renderBbox(int pass, int instance_id)
        {
            if (GLMeshBufferManager.getInstanceOccludedStatus(this, instance_id))
            {
                return;
            }

            Matrix4 worldMat = GLMeshBufferManager.getInstanceWorldMat(this, instance_id);

            //worldMat = worldMat.ClearRotation();

            Vector4[] tr_AABB = new Vector4[2];
            //tr_AABB[0] = new Vector4(metaData.AABBMIN, 1.0f) * worldMat;
            //tr_AABB[1] = new Vector4(metaData.AABBMAX, 1.0f) * worldMat;

            tr_AABB[0] = new Vector4(instanceRefs[instance_id].AABBMIN, 1.0f);
            tr_AABB[1] = new Vector4(instanceRefs[instance_id].AABBMAX, 1.0f);

            //tr_AABB[0] = new Vector4(metaData.AABBMIN, 0.0f);
            //tr_AABB[1] = new Vector4(metaData.AABBMAX, 0.0f);

            //Generate all 8 points from the AABB
            float[] verts1 = new float[] { tr_AABB[0].X, tr_AABB[0].Y, tr_AABB[0].Z,
                                           tr_AABB[1].X, tr_AABB[0].Y, tr_AABB[0].Z,
                                           tr_AABB[0].X, tr_AABB[1].Y, tr_AABB[0].Z,
                                           tr_AABB[1].X, tr_AABB[1].Y, tr_AABB[0].Z,

                                           tr_AABB[0].X, tr_AABB[0].Y, tr_AABB[1].Z,
                                           tr_AABB[1].X, tr_AABB[0].Y, tr_AABB[1].Z,
                                           tr_AABB[0].X, tr_AABB[1].Y, tr_AABB[1].Z,
                                           tr_AABB[1].X, tr_AABB[1].Y, tr_AABB[1].Z };

            //Indices
            Int32[] indices = new Int32[] { 0, 1, 2,
                                            2, 1, 3,
                                            1, 5, 3,
                                            5, 7, 3,
                                            5, 4, 6,
                                            5, 6, 7,
                                            0, 2, 4,
                                            2, 6, 4,
                                            3, 6, 2,
                                            7, 6, 3,
                                            0, 4, 5,
                                            1, 0, 5 };
            //Generate OpenGL buffers
            int arraysize = sizeof(float) * verts1.Length;
            int vb_bbox, eb_bbox;

            GL.GenBuffers(1, out vb_bbox);
            GL.GenBuffers(1, out eb_bbox);

            //Upload vertex buffer
            GL.BindBuffer(BufferTarget.ArrayBuffer, vb_bbox);
            //Allocate to NULL
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(2 * arraysize), (IntPtr)null, BufferUsageHint.StaticDraw);
            //Add verts data
            GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)arraysize, verts1);

            ////Upload index buffer
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, eb_bbox);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(sizeof(Int32) * indices.Length), indices, BufferUsageHint.StaticDraw);


            //Render

            GL.BindBuffer(BufferTarget.ArrayBuffer, vb_bbox);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0);
            GL.EnableVertexAttribArray(0);

            //InverseBind Matrices
            //loc = GL.GetUniformLocation(shader_program, "invBMs");
            //GL.UniformMatrix4(loc, this.vbo.jointData.Count, false, this.vbo.invBMats);

            //Render Elements
            GL.PointSize(5.0f);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, eb_bbox);

            GL.DrawRangeElements(PrimitiveType.Triangles, 0, verts1.Length,
                                 indices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero);

            GL.DisableVertexAttribArray(0);

            GL.DeleteBuffer(vb_bbox);
            GL.DeleteBuffer(eb_bbox);
        }