Options object for a FigureElementPrimitive of a generic 3D shape. Extends OBJ_Generic3All and OBJ_FigurePrimitive
OBJ_GenericGL can be used for shape creation with custom shaders.
But for many custom shapes, only points and normals of the shape need to be defined, without needing to customize the shaders.
OBJ_Generic3 Provides the ability to create many custom shapes that don't need shader customization.
To test examples, append them to the boilerplate
// Cubes with texture on each facefigure.scene.setProjection({ style: 'orthographic' });figure.scene.setCamera({ position: [1, 1, 2] });figure.scene.setLight({ directional: [0.7, 0.5, 1] });const [points, normals] = Fig.cube({ side: 0.8 });figure.add({ make: 'generic3', points, normals, texture: { src: './flowers.jpeg', coords: [ 0, 0, 0.333, 0, 0.333, 0.5, 0, 0, 0.333, 0.5, 0, 0.5, 0.333, 0, 0.666, 0, 0.666, 0.5, 0.333, 0, 0.666, 0.5, 0.333, 0.5, 0.666, 0, 1, 0, 1, 0.5, 0.666, 0, 1, 0.5, 0.666, 0.5, 0, 0.5, 0.333, 1, 0, 1, 0, 0.5, 0.333, 0.5, 0.333, 1, 0.333, 0.5, 0.666, 1, 0.333, 1, 0.333, 0.5, 0.666, 0.5, 0.666, 1, 0.666, 0.5, 1, 1, 0.666, 1, 0.666, 0.5, 1, 0.5, 1, 1, ], loadColor: [0, 0, 0, 0], },}); Copy
// Cubes with texture on each facefigure.scene.setProjection({ style: 'orthographic' });figure.scene.setCamera({ position: [1, 1, 2] });figure.scene.setLight({ directional: [0.7, 0.5, 1] });const [points, normals] = Fig.cube({ side: 0.8 });figure.add({ make: 'generic3', points, normals, texture: { src: './flowers.jpeg', coords: [ 0, 0, 0.333, 0, 0.333, 0.5, 0, 0, 0.333, 0.5, 0, 0.5, 0.333, 0, 0.666, 0, 0.666, 0.5, 0.333, 0, 0.666, 0.5, 0.333, 0.5, 0.666, 0, 1, 0, 1, 0.5, 0.666, 0, 1, 0.5, 0.666, 0.5, 0, 0.5, 0.333, 1, 0, 1, 0, 0.5, 0.333, 0.5, 0.333, 1, 0.333, 0.5, 0.666, 1, 0.333, 1, 0.333, 0.5, 0.666, 0.5, 0.666, 1, 0.666, 0.5, 1, 1, 0.666, 1, 0.666, 0.5, 1, 0.5, 1, 1, ], loadColor: [0, 0, 0, 0], },});
// Create a a ring around a sphere.figure.scene.setProjection({ style: 'orthographic' });figure.scene.setCamera({ position: [1, 1, 2] });figure.scene.setLight({ directional: [0.7, 0.5, 1] });const { sphere, polygon, revolve } = Fig;const [spherePoints, sphereNormals] = sphere({ radius: 0.15 });// The ring is a flattened doughnutconst [ringPoints, ringNormals] = revolve({ profile: polygon({ close: true, sides: 20, radius: 0.05, center: [0, 0.3], direction: -1, transform: ['s', 0.1, 1, 1], }), normals: 'curve', sides: 50, transform: ['d', 0, 1, 0],});const a = figure.add({ make: 'generic3', points: [...spherePoints, ...ringPoints], normals: [...sphereNormals, ...ringNormals], color: [1, 0, 0, 1], transform: [['r', 0.15, 1, 0, 0], ['r', 0.3, 0, 1, 0]],});// Animate the shape to slowly rotate around the x and y axesa.animations.new() .custom({ callback: (t) => { a.transform.updateRotation(t * 0.15); a.transform.updateRotation(t * 0.3, null, 1); }, duration: null, }) .start();@interface Copy
// Create a a ring around a sphere.figure.scene.setProjection({ style: 'orthographic' });figure.scene.setCamera({ position: [1, 1, 2] });figure.scene.setLight({ directional: [0.7, 0.5, 1] });const { sphere, polygon, revolve } = Fig;const [spherePoints, sphereNormals] = sphere({ radius: 0.15 });// The ring is a flattened doughnutconst [ringPoints, ringNormals] = revolve({ profile: polygon({ close: true, sides: 20, radius: 0.05, center: [0, 0.3], direction: -1, transform: ['s', 0.1, 1, 1], }), normals: 'curve', sides: 50, transform: ['d', 0, 1, 0],});const a = figure.add({ make: 'generic3', points: [...spherePoints, ...ringPoints], normals: [...sphereNormals, ...ringNormals], color: [1, 0, 0, 1], transform: [['r', 0.15, 1, 0, 0], ['r', 0.3, 0, 1, 0]],});// Animate the shape to slowly rotate around the x and y axesa.animations.new() .custom({ callback: (t) => { a.transform.updateRotation(t * 0.15); a.transform.updateRotation(t * 0.3, null, 1); }, duration: null, }) .start();@interface
Options object for a FigureElementPrimitive of a generic 3D shape. Extends OBJ_Generic3All and OBJ_FigurePrimitive
OBJ_GenericGL can be used for shape creation with custom shaders.
But for many custom shapes, only points and normals of the shape need to be defined, without needing to customize the shaders.
OBJ_Generic3 Provides the ability to create many custom shapes that don't need shader customization.
See
To test examples, append them to the boilerplate
Example
Example