/// <summary> /// Performs further custom initialization for this instance. /// </summary> protected override void Initialize() { if (string.IsNullOrEmpty(this.ModelPath)) { this.BoundingBox = this.InternalModel.BoundingBox; } else { this.InternalModel = Assets.LoadAsset<InternalStaticModel>(this.ModelPath); this.BoundingBox = this.InternalModel.BoundingBox; } }
/// <summary> /// Refresh the barrel distortion mesh scene /// </summary> private void RefreshBarrelDistortionScene() { this.RefreshEyeTextures(); if (this.isBarrelDistortionEnabled && this.cachedVRMode != VRMode.AttachedMode) { if (this.barrelDistortionEntity == null) { if (this.distortionMesh == null) { var assembly = ReflectionHelper.GetTypeAssembly(typeof(CardboardVRProvider)); using (var stream = ResourceLoader.GetEmbeddedResourceStream(assembly, "WaveEngine.Cardboard.BarrelDistortionMesh.wpk")) { this.distortionMesh = this.Assets.LoadAsset <InternalStaticModel>(BarrelDistortionModel, stream); } } if (this.RenderManager.FindLayer(typeof(VRLensLayer)) == null) { this.RenderManager.RegisterLayer(new VRLensLayer(this.RenderManager)); } Dictionary <string, Material> materials = new Dictionary <string, Material>(); materials.Add("vrMeshLeft", new StandardMaterial() { LightingEnabled = false, Diffuse = this.eyeTextures[0].RenderTarget, LayerType = typeof(VRLensLayer), SamplerMode = AddressMode.LinearClamp }); materials.Add("vrMeshRight", new StandardMaterial() { LightingEnabled = false, Diffuse = this.eyeTextures[1].RenderTarget, LayerType = typeof(VRLensLayer), SamplerMode = AddressMode.LinearClamp }); MaterialsMap materialsMap = new MaterialsMap(materials); this.barrelDistortionEntity = new Entity("_VRCardboardDistortMesh"); Entity distortMeshEntity = new Entity("VRMesh") .AddComponent(new Transform3D()) .AddComponent(new Model(BarrelDistortionModel)) .AddComponent(materialsMap) .AddComponent(new ModelRenderer()); var vrCamera = new FixedCamera3D("VRDistortCamera", new Vector3(0, 1, 0), Vector3.Zero); var camera = vrCamera.Entity.FindComponent <Camera3D>(); camera.UpVector = -Vector3.UnitZ; camera.SetCustomProjection(Matrix.CreateOrthographic(1, 1, 0.1f, 100)); camera.LayerMaskDefaultValue = false; camera.LayerMask.Add(typeof(VRLensLayer), true); this.barrelDistortionEntity.AddChild(distortMeshEntity); this.barrelDistortionEntity.AddChild(vrCamera.Entity); this.EntityManager.Add(this.barrelDistortionEntity); } } else { if (this.barrelDistortionEntity != null) { this.EntityManager.Remove(this.barrelDistortionEntity); this.barrelDistortionEntity = null; var lensLayer = this.RenderManager.FindLayer(typeof(VRLensLayer)); if (lensLayer != null) { this.RenderManager.RemoveLayer(lensLayer); } } } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (this.isPrimitive && this.InternalModel != null) { this.InternalModel.Unload(); this.InternalModel = null; } }