Trait Geometry

Source
pub trait Geometry {
    // Required methods
    fn draw(
        &self,
        viewer: &dyn Viewer,
        program: &Program,
        render_states: RenderStates,
    );
    fn vertex_shader_source(&self) -> String;
    fn id(&self) -> GeometryId;
    fn render_with_material(
        &self,
        material: &dyn Material,
        viewer: &dyn Viewer,
        lights: &[&dyn Light],
    );
    fn render_with_effect(
        &self,
        material: &dyn Effect,
        viewer: &dyn Viewer,
        lights: &[&dyn Light],
        color_texture: Option<ColorTexture<'_>>,
        depth_texture: Option<DepthTexture<'_>>,
    );
    fn aabb(&self) -> AxisAlignedBoundingBox;

    // Provided method
    fn animate(&mut self, _time: f32) { ... }
}
Expand description

Represents a 3D geometry that, together with a material, can be rendered using Geometry::render_with_material. Alternatively, a geometry and a material can be combined in a Gm, thereby creating an Object which can be used in a render call, for example RenderTarget::render.

If requested by the material, the geometry has to support the following attributes in the vertex shader source code.

  • position: out vec3 pos; (must be in world space)
  • normal: out vec3 nor;
  • tangent: out vec3 tang;
  • bitangent: out vec3 bitang;
  • uv coordinates: out vec2 uvs; (must be flipped in v compared to standard uv coordinates, ie. do uvs = vec2(uvs.x, 1.0 - uvs.y); in the vertex shader or do the flip before constructing the uv coordinates vertex buffer)
  • color: out vec4 col;

In addition, for the geometry to be pickable using the pick or ray_intersect methods (ie. combined with the IntersectionMaterial), it needs to support flat out int instance_id;. Simply set it to the built-in glsl variable: gl_InstanceID.

Required Methods§

Source

fn draw( &self, viewer: &dyn Viewer, program: &Program, render_states: RenderStates, )

Draw this geometry.

Source

fn vertex_shader_source(&self) -> String

Returns the vertex shader source for this geometry given that the fragment shader needs the given vertex attributes.

Source

fn id(&self) -> GeometryId

Returns a unique ID for each variation of the shader source returned from Geometry::vertex_shader_source.

Note: The last bit is reserved to internally implemented geometries, so if implementing the Geometry trait outside of this crate, always return an id in the public use range as defined by GeometryId.

Source

fn render_with_material( &self, material: &dyn Material, viewer: &dyn Viewer, lights: &[&dyn Light], )

Render the geometry with the given Material. Must be called in the callback given as input to a RenderTarget, ColorTarget or DepthTarget write method. Use an empty array for the lights argument, if the material does not require lights to be rendered.

Source

fn render_with_effect( &self, material: &dyn Effect, viewer: &dyn Viewer, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>>, )

Render the geometry with the given Effect. Must be called in the callback given as input to a RenderTarget, ColorTarget or DepthTarget write method. Use an empty array for the lights argument, if the material does not require lights to be rendered.

Source

fn aabb(&self) -> AxisAlignedBoundingBox

Returns the AxisAlignedBoundingBox for this geometry in the global coordinate system.

Provided Methods§

Source

fn animate(&mut self, _time: f32)

For updating the animation of this geometry if it is animated, if not, this method does nothing. The time parameter should be some continious time, for example the time since start.

Implementations on Foreign Types§

Source§

impl<T: Geometry + ?Sized> Geometry for &T

Source§

fn draw( &self, viewer: &dyn Viewer, program: &Program, render_states: RenderStates, )

Source§

fn vertex_shader_source(&self) -> String

Source§

fn id(&self) -> GeometryId

Source§

fn render_with_material( &self, material: &dyn Material, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_with_effect( &self, material: &dyn Effect, viewer: &dyn Viewer, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>>, )

Source§

fn aabb(&self) -> AxisAlignedBoundingBox

Source§

impl<T: Geometry + ?Sized> Geometry for &mut T

Source§

fn draw( &self, viewer: &dyn Viewer, program: &Program, render_states: RenderStates, )

Source§

fn vertex_shader_source(&self) -> String

Source§

fn id(&self) -> GeometryId

Source§

fn render_with_material( &self, material: &dyn Material, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_with_effect( &self, material: &dyn Effect, viewer: &dyn Viewer, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>>, )

Source§

fn aabb(&self) -> AxisAlignedBoundingBox

Source§

fn animate(&mut self, time: f32)

Source§

impl<T: Geometry> Geometry for Box<T>

Source§

fn draw( &self, viewer: &dyn Viewer, program: &Program, render_states: RenderStates, )

Source§

fn vertex_shader_source(&self) -> String

Source§

fn id(&self) -> GeometryId

Source§

fn render_with_material( &self, material: &dyn Material, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_with_effect( &self, material: &dyn Effect, viewer: &dyn Viewer, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>>, )

Source§

fn aabb(&self) -> AxisAlignedBoundingBox

Source§

impl<T: Geometry> Geometry for Rc<T>

Source§

fn draw( &self, viewer: &dyn Viewer, program: &Program, render_states: RenderStates, )

Source§

fn vertex_shader_source(&self) -> String

Source§

fn id(&self) -> GeometryId

Source§

fn render_with_material( &self, material: &dyn Material, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_with_effect( &self, material: &dyn Effect, viewer: &dyn Viewer, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>>, )

Source§

fn aabb(&self) -> AxisAlignedBoundingBox

Source§

impl<T: Geometry> Geometry for Arc<T>

Source§

fn draw( &self, viewer: &dyn Viewer, program: &Program, render_states: RenderStates, )

Source§

fn vertex_shader_source(&self) -> String

Source§

fn id(&self) -> GeometryId

Source§

fn render_with_material( &self, material: &dyn Material, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_with_effect( &self, material: &dyn Effect, viewer: &dyn Viewer, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>>, )

Source§

fn aabb(&self) -> AxisAlignedBoundingBox

Source§

impl<T: Geometry> Geometry for RefCell<T>

Source§

fn draw( &self, viewer: &dyn Viewer, program: &Program, render_states: RenderStates, )

Source§

fn vertex_shader_source(&self) -> String

Source§

fn id(&self) -> GeometryId

Source§

fn render_with_material( &self, material: &dyn Material, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_with_effect( &self, material: &dyn Effect, viewer: &dyn Viewer, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>>, )

Source§

fn aabb(&self) -> AxisAlignedBoundingBox

Source§

fn animate(&mut self, time: f32)

Source§

impl<T: Geometry> Geometry for RwLock<T>

Source§

fn draw( &self, viewer: &dyn Viewer, program: &Program, render_states: RenderStates, )

Source§

fn vertex_shader_source(&self) -> String

Source§

fn id(&self) -> GeometryId

Source§

fn render_with_material( &self, material: &dyn Material, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_with_effect( &self, material: &dyn Effect, viewer: &dyn Viewer, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>>, )

Source§

fn aabb(&self) -> AxisAlignedBoundingBox

Source§

fn animate(&mut self, time: f32)

Implementors§