Defining a new solid
A Solid()
is defined as a Shape()
and a Material()
(and eventually a PTMaterial()
for the path tracer).
Its role is simply to wrap these data and pass them to the shader (with a proper ID).
To simplify the creation of scenes, it can be useful to build various extension of the Solid()
class, that will
serve as shortcut to define a solid with a specific shape.
Class extension
Every solid should extend the class Solid()
.
Note that Solid()
inherits from Generic()
, which defines methods various method to assign a UUID, a name, a scene ID, to the solid.
The constructor of Solid()
takes the following arguments
shape (
Shape()
) : a shapematerial (
Material()
) : a material (for basic rendering)ptMaterial (
PTMaterial()
) optional : a material for path tracing
Properties and methods
The definition of a solid class does not require any particular property/method. All is already taken care of by the
class Generic()
from which it inherits.
Example
Below is the code used for euclidean balls.
import {Solid} from "../../../core/solids/Solid.js";
import {BallShape} from "../shapes/ball/BallShape.js";
/**
* @class
*
* @classdesc
* Euclidean ball
*/
export class Ball extends Solid {
/**
* @param {Isometry|Point} location - the location of the ball
* @param {number} radius - the radius of the ball
* @param {Material} material - the material of the ball
* @param {PTMaterial} ptMaterial - material for path tracing (optional)
*/
constructor(location, radius, material, ptMaterial = undefined) {
const shape = new BallShape(location, radius);
super(shape, material, ptMaterial);
}
}