public ActionResult VrView(int id) { SpatialData sd = db.SpatialData.Single(c => c.id == id); ViewData["modelname"] = string.IsNullOrEmpty(sd.model)? "SNS000_01" : sd.model; return(View()); }
public void rayTracing(fx_Quad quad, SpatialData camera_spatial) { if (!(_debug_display_voxels && _enabled)) { return; } mipMap(); GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _resolution.W, _resolution.H); _pRayTrace.bind(); GL.Uniform1(_pRayTrace.getUniform("vx_volume_dimensions"), _vx_volume_dimensions); Vector3 vx_position_snapped = -voxelSnap(camera_spatial.position); Matrix4 voxel_volume_position = Matrix4.CreateTranslation(vx_position_snapped); Matrix4 invMVP = Matrix4.Invert(_vx_shift_matrix * voxel_volume_position * camera_spatial.model_view * camera_spatial.perspective); GL.UniformMatrix4(_pRayTrace.getUniform("vx_inv_view_perspective"), false, ref invMVP); GL.Uniform1(_pRayTrace.getUniform("displayMipLevel"), _debug_display_voxels_mip_level); _tVoxelVolume.bind(_pRayTrace.getSamplerUniform(0), 0); quad.renderFullQuad(); }
public void EditVectorization(FormCollection collection) { string id = collection["id"]; string projectName = collection["projectname"]; string projectID = collection["projectid"]; string model = collection["vrmodel"]; try { SpatialData sd = db.SpatialData.SingleOrDefault(c => c.id.ToString() == id); if (sd != null) { if (projectID != "" && projectName != "") { sd.projectID = long.Parse(projectID); sd.projectName = projectName; } if (model != "") { sd.model = model; } db.SaveChanges(); Response.Write("ok"); } } catch (Exception ex) { Response.Write(ex.Message); } }
private static void FindSubSpatialStructure(SpatialData spatial) { HashSet <string> typeName = new HashSet <string>(); foreach (var p in spatial.SubProducts) { if (!typeName.Contains(p.TypeName)) { typeName.Add(p.TypeName); var gameObj = new GameObject(p.TypeName); gameObj.transform.parent = spatial.transform; } p.transform.parent = spatial.transform.Find(p.TypeName); if (p.DecomposedProducts.Count > 0) { foreach (var dp in p.DecomposedProducts) { dp.transform.parent = p.transform; } } } foreach (var ss in spatial.SubSpatialData) { ss.transform.parent = spatial.transform; FindSubSpatialStructure(ss); } }
void Render(SpatialData somePos, ShapeData someShape) { GL.PointSize(4.0f); GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); { RotateCenter(somePos, someShape); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc( BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha ); GL.Begin(BeginMode.LineLoop); foreach (Vector2 point in someShape.Points) { GL.Vertex2( (point * someShape.Size) + new Vector2(somePos.X, somePos.Y) ); } GL.End(); } GL.PopMatrix(); }
public void unfollowCharacter() { if (_following) { _spatial = new SpatialData(_spatial.position, _spatial.look, _spatial.up); _following = false; } }
private void update_Flashlight(SpatialData camera_spatial) { // Flashlight stuff _flashlight.unique_mesh.transformation = Matrix4.Invert(camera_spatial.transformation); _flashlight.bounding_unique_mesh.transformation = _flashlight.bounding_unique_mesh.base_transformation * _flashlight.unique_mesh.transformation; _flashlight.spatial.position = -camera_spatial.position; _flashlight.spatial.rotation_matrix = Matrix4.Transpose(camera_spatial.rotation_matrix); }
void RotateCenter(SpatialData somePos, ShapeData someShape) { Vector2 centroid = someShape.GetCentroid() + new Vector2(somePos.X, somePos.Y); GL.Translate(centroid.X, centroid.Y, 0); // move back to focus of GLuLookAt GL.Rotate(somePos.Rotation, 0.0f, 0.0f, 1.0f); GL.Translate(-centroid.X, -centroid.Y, 0); //move object to center }
void OnTriggerPulled(object someSender, TriggerPulledEventArgs e) { IEntity player = this.DataCenter.GetEntitiesWithTag("Player").Single(); SpatialData playerSpatial = player.GetData <SpatialData> (); VelocityData playerVelocity = player.GetData <VelocityData> (); IEntity projectile = this.DataCenter.CreateEntity(); projectile.Tag = "Projectile"; Vector2 pos = new Vector2(playerSpatial.X, playerSpatial.Y); projectile.AddData( new SpatialData() { X = pos.X, Y = pos.Y, Rotation = playerSpatial.Rotation } ); float rotationRads = (float)(Math.PI / 180.0) * playerSpatial.Rotation; Vector2 vPlayer = new Vector2(playerVelocity.X, playerVelocity.Y); Vector2 v = new Vector2( (float)Math.Cos(rotationRads) * this.ProjectileSpeed, (float)Math.Sin(rotationRads) * this.ProjectileSpeed ); /*float angle = * Vector2.Dot( v, vPlayer ) * / ( v.LengthFast * vPlayer.LengthFast ); * float arcX = angle; * float arcY = (float)Math.Sin( Math.Acos( angle ) );*/ projectile.AddData( new VelocityData() { X = v.X, //+ ( arcX * playerVelocity.X ), Y = v.Y //+ ( arcY * playerVelocity.Y ) } ); projectile.AddData( new ShapeData( 10, new List <Vector2> () { new Vector2(0, 0), new Vector2(0, -0.25f), new Vector2(0.75f, -0.5f), new Vector2(1, 0), new Vector2(0.75f, 0.5f), new Vector2(0, 0.25f), } ) ); }
public void update(SpatialData camera_spatial) { _current_animation_time = _animation_timer.seconds; update_Sun(camera_spatial); update_Flashlight(camera_spatial); _light_manager.update(-camera_spatial.position, _current_animation_time); }
public static void Seed(SpatialContext context, GeometryFactory factory) { context.AddRange(SpatialData.CreatePointEntities(factory)); context.AddRange(SpatialData.CreateGeoPointEntities()); context.AddRange(SpatialData.CreateLineStringEntities(factory)); context.AddRange(SpatialData.CreatePolygonEntities(factory)); context.AddRange(SpatialData.CreateMultiLineStringEntities(factory)); context.SaveChanges(); }
public void render(Scene scene, SpatialData camera_spatial) { //GL.Enable(EnableCap.PolygonOffsetFill); //GL.PolygonOffset(0.5f, 0.2f); render_Spot(scene); render_Point(scene); render_Directional(scene, camera_spatial); //GL.Disable(EnableCap.PolygonOffsetFill); }
private void render_Directional(Scene scene, SpatialData camera_spatial) { _fDirectional.bind(DrawBuffersEnum.ColorAttachment0); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Viewport(0, 0, _tDirectional.width, _tDirectional.height); _pDirectional.bind(); scene.renderMeshes_Basic(BeginMode.Triangles, _pDirectional); _tDirectional.generateMipMap(); }
public Camera(string id, SpatialData spatial_data, float fov, float aspect_ratio, Vector2 near_far) : base(id, spatial_data) { _following = false; _default_fov = _fov_current = _fov_previous = fov; _default_aspect_ratio = aspect_ratio; _default_near_far = near_far; _position_current = _spatial.position; _spatial.setPerspective(_fov_current, _default_aspect_ratio, _default_near_far); _previous_view_matrix = _spatial.model_view; _previous_perspective_matrix = _spatial.perspective; }
private static SpatialData GetSpatialStructure(IIfcObjectDefinition current) { SpatialData sp = default; var spatialElement = current as IIfcSpatialStructureElement; if (spatialElement != null) { sp = InstantiateCurrentSpatial(spatialElement); if (sp != null) { PublicValue.spatialStructures.Add(sp); //考虑一下select需不需要 //疑问,IIfcSpatialStructureElement的ContainsElements和IIfcObjectDefinition的DecomposedBy是不是一致的 var containedElements = spatialElement.ContainsElements.SelectMany(e => e.RelatedElements); if (containedElements.Count() > 0) { foreach (var element in containedElements) { //需要和public value的productsData生成的地方联系起来看看有没有可以优化的地方 var prod = PublicValue.productsData.Find(p => p.BimProduct.entityLabel == element.EntityLabel); if (prod == null) { var go = new GameObject(); prod = go.AddComponent <ProductData>(); //考虑一下这种情况实际上只用到了BimProduct的Label prod.BimProduct = new BimProduct(element.EntityLabel, (short)element.EntityLabel); //这里和小泽写的不太一样 ///prod.SetProductData(element); //sp.SubProducts.Add(prod); prod.SetDecomposedProducts(element.IsDecomposedBy); } prod.SetProductData(element); sp.SubProducts.Add(prod); } } } } foreach (var item in current.IsDecomposedBy.SelectMany(r => r.RelatedObjects)) { sp.SubSpatialData.Add(GetSpatialStructure(item)); } return(sp); }
void OnProcessing(double someDeltaTime) { List <ulong> removeList = new List <ulong> (); List <IEntity> projectiles = this.DataCenter.GetEntitiesWithTag("Projectile"); foreach (IEntity projectile in projectiles) { SpatialData pos = projectile.GetData <SpatialData> (); if (pos.X > this.width || pos.X < 0 || pos.Y > this.height || pos.Y < 0) { removeList.Add(projectile.ID); } } foreach (ulong id in removeList) { this.DataCenter.EntityManager.RemoveEntity(id); } }
public void lightInjection(Scene scene, fx_Shadow shadow, SpatialData camera_spatial) { if (!_enabled) { return; } int workgroup_size = 4; int texture_size = (int)_vx_volume_dimensions * 8; _tTemp.clear(); _pInjection.bind(); GL.Uniform2(_pInjection.getUniform("texture_size"), shadow.tSpot.dimensions.Xy); GL.Uniform1(_pInjection.getUniform("vx_volume_dimensions"), _vx_volume_dimensions); GL.Uniform1(_pInjection.getUniform("vx_volume_scale"), _vx_volume_scale); GL.Uniform3(_pInjection.getUniform("vx_volume_position"), -voxelSnap(camera_spatial.position)); _tVoxelVolume.bindImageUnit(_pInjection.getSamplerUniform(0), 0, TextureAccess.ReadWrite); _tVoxelVolume_Diffuse.bind(_pInjection.getSamplerUniform(1), 1); shadow.tSpot.bind(_pInjection.getSamplerUniform(2), 2); shadow.tPoint.bind(_pInjection.getSamplerUniform(3), 3); shadow.tDirectional.bind(_pInjection.getSamplerUniform(4), 4); _tTemp.bindImageUnit(_pInjection.getSamplerUniform(5), 5, TextureAccess.WriteOnly); GL.DispatchCompute(((int)shadow.tSpot.dimensions.X / workgroup_size), ((int)shadow.tSpot.dimensions.Y / workgroup_size), 1); GL.MemoryBarrier(MemoryBarrierFlags.TextureFetchBarrierBit | MemoryBarrierFlags.ShaderImageAccessBarrierBit); }
//------------------------------------------------------ // Rendering //------------------------------------------------------ public void render(Scene scene, SpatialData camera_spatial_data, float current_fps) { //------------------------------------------------------ // Pre-Processing //------------------------------------------------------ GL.Disable(EnableCap.DepthTest); _fxAtmosphericScattering.precompute(_fxQuad); _fxHDR.calcExposure(_fxFinal.tFinalScene); //------------------------------------------------------ // Scene Processing //------------------------------------------------------ GL.DepthMask(true); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); _fxVXGI.voxelizeScene(scene, camera_spatial_data.position); _fxShadow.render(scene, camera_spatial_data); _fxVXGI.lightInjection(scene, _fxShadow, camera_spatial_data); _fxGBuffer.pass_DeferredShading(scene, _fxShadow); _fxSkyBox.render(_fxQuad, _fxGBuffer.fGBuffer, scene.circadian_timer.position); //------------------------------------------------------ // Post-processing //------------------------------------------------------ GL.Disable(EnableCap.DepthTest); _fxVXGI.coneTracing(_fxQuad, _fxGBuffer.tDiffuse_ID, _fxGBuffer.tNormal_Depth, _fxGBuffer.tSpecular, camera_spatial_data); _fxAtmosphericScattering.render(_fxQuad, _fxGBuffer.tNormal_Depth, _fxGBuffer.tDiffuse_ID, _fxGBuffer.tSpecular, scene.circadian_timer.position, _fxShadow.tDirectional); _fxGBuffer.pass_LightAccumulation(_fxQuad, _fxAtmosphericScattering.tAtmosphere, _fxVXGI.tConeTrace_Diffuse, _fxFinal.fFinalScene); _fxDepthOfField.render(_fxQuad, _fxSpecial, _fxGBuffer.tNormal_Depth, _fxFinal.fFinalScene, _fxFinal.tFinalScene); _fxHDR.scaleScene(_fxQuad, _fxFinal.fFinalScene, _fxFinal.tFinalScene); _fxLens.render(_fxQuad, _fxSpecial, _fxFinal.tFinalScene, _fxFinal.fFinalScene, camera_spatial_data.rotation_matrix); _fxMotionBlur.render(_fxQuad, _fxSpecial, _fxFinal.fFinalScene, _fxFinal.tFinalScene, _fxGBuffer.tNormal_Depth, _fxGBuffer.tVelocity, current_fps); //------------------------------------------------------ // Render to Screen //------------------------------------------------------ _fxFinal.render(_fxQuad); //------------------------------------------------------ // Take Screenshot when requested //------------------------------------------------------ takeScreenshot(); //------------------------------------------------------ // Debug Views //------------------------------------------------------ _fxVXGI.rayTracing(_fxQuad, camera_spatial_data); if (_enable_debug_views) { //_fxQuad.render_Texture(_fxDepthOfField.tDOF_Scene, 1f, 0); //_fxQuad.render_Texture(_fxMotionBlur.tFinal, 1f, 0); //_fxQuad.render_Texture(_fxVXGI.tConeTrace_Diffuse, 0.5f, 1); //_fxQuad.render_Texture(_fxVXGI._tVoxelVolume, 0.33f, 1, 150); //_fxQuad.render_Texture(_fxAtmosphericScattering.tAtmosphere, 0.25f, 2); //_fxQuad.render_Texture(_fxMotionBlur.tVelocity_2, 0.25f, 3); //_fxQuad.render_Texture(_fxMotionBlur.tVelocity_1, 0.25f, 2); //_fxQuad.render_Texture(_fxShadow.tSpot, 0.25f, 2); //_fxQuad.render_Texture(_fxVXGI._tTemp, 0.25f, 1); _fxQuad.render_Texture(_fxGBuffer.tDiffuse_ID, 0.25f, 0); // CSM Cascades //_fxQuad.render_Texture(_fxShadow.tDirectional, 0.25f, 3, 3); //_fxQuad.render_Texture(_fxShadow.tDirectional, 0.25f, 2, 2); //_fxQuad.render_Texture(_fxShadow.tDirectional, 0.25f, 1, 1); //_fxQuad.render_Texture(_fxShadow.tDirectional, 0.25f, 0, 0); } //------------------------------------------------------ // Overlays //------------------------------------------------------ _fxCrosshair.render(scene.current_animation_time); }
public Character(string id, SpatialData spatial_data, float movement_speed_walk, float movement_speed_run) : base(id, spatial_data, movement_speed_walk, movement_speed_run) { }
public void update_Cascades(SpatialData camera_spatial, Vector3 light_direction) { Matrix4[] temp_view_matrices = new Matrix4[_num_cascades]; Matrix4[] temp_ortho_matrices = new Matrix4[_num_cascades]; float cascade_backup_distance = 20.0f; float shadow_texture_width = 840.0f; for (int cascade = 0; cascade < _num_cascades; cascade++) { float near = _cascade_splits[cascade]; float far = _cascade_splits[cascade + 1]; //------------------------------------------------------ // Create Frustum Bounds //------------------------------------------------------ float frustum_near = -1.0f; float frustum_far = 1.0f; Vector3[] frustum_corners = { // Near Plane new Vector3(-1.0f, 1.0f, frustum_near), new Vector3(1.0f, 1.0f, frustum_near), new Vector3(1.0f, -1.0f, frustum_near), new Vector3(-1.0f, -1.0f, frustum_near), // Far Plane new Vector3(-1.0f, 1.0f, frustum_far), new Vector3(1.0f, 1.0f, frustum_far), new Vector3(1.0f, -1.0f, frustum_far), new Vector3(-1.0f, -1.0f, frustum_far), }; frustum_corners = frustum_corners.Select(corner => { return(Vector3.TransformPerspective(corner, Matrix4.Invert(camera_spatial.model_view * _cascade_perspective_matrices[cascade]))); }).ToArray(); //------------------------------------------------------ // Get Frustum center and radius //------------------------------------------------------ Vector3 frustum_center = Vector3.Zero; for (int i = 0; i < 8; i++) { frustum_center = frustum_center + frustum_corners[i]; } frustum_center = frustum_center / 8.0f; float radius_max = 0.0f; for (int i = 0; i < 8; i++) { radius_max = (float)Math.Max((frustum_center - frustum_corners[i]).Length, radius_max); } radius_max *= 2.0f; float radius = radius_max; //------------------------------------------------------ // Trying to fix shimmering //------------------------------------------------------ radius = (float)Math.Floor(radius * shadow_texture_width) / shadow_texture_width; float scaler = shadow_texture_width / (radius * (shadow_texture_width / 5.0f)); frustum_center *= scaler; frustum_center.X = (float)Math.Floor(frustum_center.X); frustum_center.Y = (float)Math.Floor(frustum_center.Y); frustum_center.Z = (float)Math.Floor(frustum_center.Z); frustum_center /= scaler; //------------------------------------------------------ // Create Matrices //------------------------------------------------------ Vector3 eye = frustum_center + (light_direction * (radius / 2.0f * cascade_backup_distance)); temp_view_matrices[cascade] = Matrix4.LookAt(eye, frustum_center, Vector3.UnitY); temp_ortho_matrices[cascade] = Matrix4.CreateOrthographic(radius, radius, _cascade_splits[0], radius * cascade_backup_distance); } _shadow_view_matrices = temp_view_matrices; _shadow_ortho_matrices = temp_ortho_matrices; }
public void coneTracing(fx_Quad quad, Texture diffuse_texture, Texture normal_texture, Texture specular_texture, SpatialData camera_spatial) { if (!_enabled) { _tConeTrace_Diffuse.clear(); return; } mipMap(); _fConeTrace.bind(DrawBuffersEnum.ColorAttachment0); GL.Viewport(0, 0, _tConeTrace_Diffuse.width, _tConeTrace_Diffuse.height); _pConeTrace.bind(); GL.Uniform1(_pConeTrace.getUniform("vx_volume_dimensions"), _vx_volume_dimensions); GL.Uniform1(_pConeTrace.getUniform("vx_volume_scale"), _vx_volume_scale); Vector3 vx_position_snapped = -voxelSnap(camera_spatial.position); Matrix4 voxel_volume_position = Matrix4.CreateTranslation(vx_position_snapped); GL.Uniform3(_pConeTrace.getUniform("vx_volume_position"), vx_position_snapped); GL.Uniform1(_pConeTrace.getUniform("maxMipLevels"), _tVoxelVolume.getMaxMipMap()); normal_texture.bind(_pConeTrace.getSamplerUniform(0), 0); specular_texture.bind(_pConeTrace.getSamplerUniform(1), 1); diffuse_texture.bind(_pConeTrace.getSamplerUniform(2), 2); _tVoxelVolume.bind(_pConeTrace.getSamplerUniform(3), 3); quad.renderFullQuad(); }
//------------------------------------------------------ // Update Scene //------------------------------------------------------ private void update_Sun(SpatialData camera_spatial) { _sun.spatial.position = _circadian_timer.position; _sun.update_Cascades(camera_spatial, Vector3.Normalize(_circadian_timer.position)); }
public PlayableCharacter(string name, SpatialData spatial_data, float movement_speed_walk, float movement_speed_run) : base(name, spatial_data, movement_speed_walk, movement_speed_run) { }
void RenderText(TextData someTextData, SpatialData someSpatial) { // Render text using System.Drawing. // Do this only when text changes. using (Graphics gfx = Graphics.FromImage(this.textBitmap)) { gfx.Clear(Color.Transparent); gfx.DrawString( someTextData.Text, someTextData.Font, //new Font( "Arial", 12, FontStyle.Regular ), someTextData.Brush, //Brushes.BlueViolet, someSpatial.X, someSpatial.Y ); } GL.Enable(EnableCap.Texture2D); GL.BindTexture( TextureTarget.Texture2D, this.textTexture ); GL.TexParameter( TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear); GL.TexParameter( TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear); GL.Enable(EnableCap.Blend); GL.BlendFunc( BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha ); BitmapData data = this.textBitmap.LockBits( new Rectangle(0, 0, this.textBitmap.Width, this.textBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); GL.TexImage2D( TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, this.width, this.height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0 ); this.textBitmap.UnlockBits(data); GL.Begin(BeginMode.Quads); GL.TexCoord2(0f, 0f); GL.Vertex2(0f, 0f); GL.TexCoord2(1f, 0f); GL.Vertex2(this.width, 0f); GL.TexCoord2(1f, 1f); GL.Vertex2(this.width, this.height); GL.TexCoord2(0f, 1f); GL.Vertex2(0f, this.height); GL.End(); GL.Disable(EnableCap.Texture2D); }
protected override void Seed(NetTopologySuiteContext context) => SpatialData.Seed(context);