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. douvs = 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§
Sourcefn draw(
&self,
viewer: &dyn Viewer,
program: &Program,
render_states: RenderStates,
)
fn draw( &self, viewer: &dyn Viewer, program: &Program, render_states: RenderStates, )
Draw this geometry.
Sourcefn vertex_shader_source(&self) -> String
fn vertex_shader_source(&self) -> String
Returns the vertex shader source for this geometry given that the fragment shader needs the given vertex attributes.
Sourcefn id(&self) -> GeometryId
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.
Sourcefn render_with_material(
&self,
material: &dyn Material,
viewer: &dyn Viewer,
lights: &[&dyn Light],
)
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.
Sourcefn render_with_effect(
&self,
material: &dyn Effect,
viewer: &dyn Viewer,
lights: &[&dyn Light],
color_texture: Option<ColorTexture<'_>>,
depth_texture: Option<DepthTexture<'_>>,
)
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.
Sourcefn aabb(&self) -> AxisAlignedBoundingBox
fn aabb(&self) -> AxisAlignedBoundingBox
Returns the AxisAlignedBoundingBox for this geometry in the global coordinate system.