protected override Entity Create() { var root = base.Create(); pointMesh = new LightPointMesh(GraphicsDevice); pointMesh.Build(); pointMaterial = GizmoUniformColorMaterial.Create(GraphicsDevice, (Color) new Color4(GetLightColor(GraphicsDevice), 1f)); pointEntity = new Entity("Point Mesh of {0}".ToFormat(root.Id)) { new ModelComponent { Model = new Model { pointMaterial, new Mesh { Draw = pointMesh.MeshDraw }, }, RenderGroup = RenderGroup, } }; return(root); }
protected override Entity Create() { var root = base.Create(); var renderingSettings = Game.PackageSettings?.GetConfiguration <RenderingSettings>(); var aspect = (renderingSettings == null) ? 1.7778f : (float)renderingSettings.DefaultBackBufferWidth / (float)renderingSettings.DefaultBackBufferHeight; cameraParameters = new CameraParameters(Component, aspect); frustumMesh = new CameraFrustumMesh(GraphicsDevice); frustumMesh.Build(GraphicsCommandList, cameraParameters); var frustumMaterial = GizmoUniformColorMaterial.Create(GraphicsDevice, new Color(0.75f, 0.75f, 1f, 1f)); frustum = new Entity("Camera frustumMesh of {0}".ToFormat(root.Id)) { new ModelComponent { Model = new Model { frustumMaterial, new Mesh { Draw = frustumMesh.MeshDraw }, }, RenderGroup = RenderGroup, } }; return(root); }
public override void Update() { base.Update(); // update the color of the ray GizmoUniformColorMaterial.UpdateColor(GraphicsDevice, rayMaterial, (Color) new Color4(GetLightColor(GraphicsDevice), 1f)); }
protected override Entity Create() { debugRootEntity = new Entity($"Voxel volume of {Component.Entity.Name}"); material = GizmoUniformColorMaterial.Create(GraphicsDevice, Color.CornflowerBlue); box = new BoxMesh(GraphicsDevice); box.Build(); debugEntity = new Entity($"Voxel volume mesh of {Component.Entity.Name}") { new ModelComponent { Model = new Model { material, new Mesh { Draw = box.MeshDraw }, }, RenderGroup = RenderGroup, } }; return(debugRootEntity); }
protected virtual void UpdateColors() { if (IsEnabled && RedUniformMaterial != null) { GizmoUniformColorMaterial.UpdateColor(GraphicsDevice, RedUniformMaterial, RedUniformColor); GizmoUniformColorMaterial.UpdateColor(GraphicsDevice, GreenUniformMaterial, GreenUniformColor); GizmoUniformColorMaterial.UpdateColor(GraphicsDevice, BlueUniformMaterial, BlueUniformColor); } }
public override void Update() { base.Update(); // update pointEntity aspect pointEntity.Transform.Scale = new Vector3(LightPoint.Radius); // update the spot color GizmoUniformColorMaterial.UpdateColor(GraphicsDevice, pointMaterial, (Color) new Color4(GetLightColor(GraphicsDevice), 1f)); }
protected override Entity Create() { var root = base.Create(); lightRay = new Entity($"Light ray for light gizmo {root.Id}"); rayMaterial = GizmoUniformColorMaterial.Create(GraphicsDevice, (Color) new Color4(GetLightColor(GraphicsDevice), 1f)); // build the ray mesh var coneMesh = GeometricPrimitive.Cone.New(GraphicsDevice, ConeRadius, ConeHeight, GizmoTessellation).ToMeshDraw(); var bodyMesh = GeometricPrimitive.Cylinder.New(GraphicsDevice, BodyLength, BodyRadius, GizmoTessellation).ToMeshDraw(); var coneEntity = new Entity($"Light ray for light gizmo {root.Id}") { new ModelComponent { Model = new Model { rayMaterial, new Mesh { Draw = coneMesh } }, RenderGroup = RenderGroup } }; coneEntity.Transform.Rotation = Quaternion.RotationX(-MathUtil.PiOverTwo); coneEntity.Transform.Position.Z = -BodyLength - ConeHeight * 0.5f; lightRay.AddChild(coneEntity); var bodyEntity = new Entity($"Light ray body for light gizmo {root.Id}") { new ModelComponent { Model = new Model { rayMaterial, new Mesh { Draw = bodyMesh } }, RenderGroup = RenderGroup } }; bodyEntity.Transform.Position.Z = -BodyLength / 2; bodyEntity.Transform.Rotation = Quaternion.RotationX(-MathUtil.PiOverTwo); lightRay.AddChild(bodyEntity); return(root); }
public override void Update() { base.Update(); // Update the frustum mesh to match the changed light settings: bool lightingModeChanged = (LightSpot.ProjectiveTexture == null && currentProjectiveTexture != null) || // <- if texture removed (LightSpot.ProjectiveTexture != null && currentProjectiveTexture == null); // <- if texture added // Check if we need to rebuild the whole mesh: if (lightingModeChanged) { // Rebuild the mesh because we switched between textured and untextured mode: spotMesh.Build(GraphicsCommandList, LightSpot); // TODO: Does "Build()" properly release the resources? // Now assign the new mesh to the model component: UpdateModelComponentMesh(); } // Check if we only need to update the vertex positions: bool GeometryAffectingParametersChanged = !MathUtil.NearEqual(currentAngleOuterInRadians, LightSpot.AngleOuterInRadians) || !MathUtil.NearEqual(currentRange, LightSpot.Range) || !MathUtil.NearEqual(currentAspectRatio, LightSpot.AspectRatio) || // TODO: This will trigger a rebuild even if no texture is being used. !MathUtil.NearEqual(currentProjectionPlaneDistance, LightSpot.ProjectionPlaneDistance) || // TODO: This will trigger a rebuild even if no texture is being used. lightingModeChanged; if (GeometryAffectingParametersChanged) // TODO: PERFORMANCE: We're doing redundant work. If the lighting mode changes, we do a rebuild and then we also update the vertex positions (redundant). { // Save the current state: currentAngleOuterInRadians = LightSpot.AngleOuterInRadians; // "AngleOuterInRadians" already contains the max value between "AngleInner" and "AngleOuter". currentRange = LightSpot.Range; currentAspectRatio = LightSpot.AspectRatio; currentProjectionPlaneDistance = LightSpot.ProjectionPlaneDistance; currentProjectiveTexture = LightSpot.ProjectiveTexture; // Rebuild the mesh based on the new parameters: spotMesh.Rebuild(GraphicsCommandList, LightSpot); } // update the spot color GizmoUniformColorMaterial.UpdateColor(GraphicsDevice, spotMaterial, (Color) new Color4(GetLightColor(GraphicsDevice), 1f)); }
/// <summary> /// Creates a material having a uniform color. /// </summary> /// <param name="color">The color of the material</param> /// <returns>the material</returns> protected Material CreateUniformColorMaterial(Color color) { return(GizmoUniformColorMaterial.Create(GraphicsDevice, color)); }