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); }
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); }
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); }
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(); }
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; }
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 } }
public gizmo() { type = TYPES.GIZMO; //Assemble geometry in the constructor meshVao = Common.RenderState.activeResMgr.GLPrimitiveMeshVaos["default_translation_gizmo"]; instanceId = GLMeshBufferManager.addInstance(ref meshVao, this); }
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); }
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); }
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"]; }
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); }
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 }
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(); }