import { Apple, Backdrop, Car, Card, Coin, ContactShadow, Ground, MoneyStack, Peach, StudioFloor, Trees } from "@apricotjs/assets";Ready-made objects built in code, with no files to download. Each is one or two draw calls. Every component also takes transform props (position, rotation, scale) and frees its object on unmount. Changing a prop rebuilds the object, except where noted.
Components#
Food#
Apple is one mesh. Its userData.radius is set, so <Pile> can drop it.
| Prop | Type | Default | Description |
|---|---|---|---|
size |
number | 1 |
Diameter |
color |
colour | "#e8343a" |
Skin colour |
leaf |
boolean | true |
A leaf on the stem |
Peach is two meshes in a group (skin, then stem and leaves), so it is two draw calls. <Pile> can't drop it.
| Prop | Type | Default | Description |
|---|---|---|---|
size |
number | 1 |
Width |
leaves |
boolean | true |
Leaves at the stem |
detail |
0–1 | 1 |
Smoothness. Lower it for many small or blurred copies |
Money#
Coin lies flat, as a cylinder along y. Rotate it by [Math.PI / 2, 0, 0] to face the camera.
| Prop | Type | Default | Description |
|---|---|---|---|
radius |
number | 0.5 |
|
thickness |
number | 0.08 |
|
color |
colour | "#f2c14e" |
MoneyStack is one draw call for the whole stack. Its base is at y = 0.
| Prop | Type | Default | Description |
|---|---|---|---|
bills |
number | 40 |
Number of banknotes |
seed |
number | 1 |
Seed for the stack's random offsets. The same seed gives the same stack |
width |
number | 2.4 |
|
depth |
number | 1.05 |
|
thickness |
number | 0.022 |
Thickness of one bill |
band |
boolean or colour | true |
A paper band round the middle. false for a loose stack |
colors |
Partial<BanknoteColors> |
DEFAULT_BANKNOTE_COLORS |
Banknote colours |
BanknoteColors: { base, ink, highlight, paper }. The defaults in DEFAULT_BANKNOTE_COLORS are #7cc47f, #3f8f46, #c8e6c9 and #eef3e2.
Vehicles#
Car is an emoji-style toy car facing +z, with its wheels on y = 0. Its wheel nodes are named for <Vehicle>, and it is sized for <Vehicle>'s defaults.
| Prop | Type | Default | Description |
|---|---|---|---|
color |
colour | "#f24b3f" |
Body colour |
glass |
colour | "#bfe3ff" |
Window colour |
Product#
Card is a payment card centred on the origin, front facing +z. Changing finish or art swaps its materials without rebuilding it.
| Prop | Type | Default | Description |
|---|---|---|---|
finish |
CardFinish |
"brushed-steel" |
|
art |
THREE.Texture | null |
null |
Engraving mask for the front (opaque is engraved), for example from useTexture |
chip |
boolean | true |
A gold chip on the front |
CardFinish: "brushed-steel" | "chrome" | "gold" | "rose-gold" | "matte-black" | "glossy-paint" | "glass". The engraving is darker on bare metal, bright steel on matte black, white ink on paint, and frosted on glass.
Backdrop is an unlit studio wall facing +z. Glass needs something behind it to show, so place a backdrop behind it, for example at [0, 0, -3].
| Prop | Type | Default | Description |
|---|---|---|---|
size |
[width, height] |
[30, 30] |
|
colors |
[centre, edge] colours |
["#262a31", "#0e0f12"] |
|
lines |
boolean | true |
Faint diagonal lines that see-through materials show bent |
StudioFloor is a round, unlit floor at y = 0 that fades into the background.
| Prop | Type | Default | Description |
|---|---|---|---|
radius |
number | 8 |
|
colors |
[centre, edge] colours |
["#30343b", "#0e0f12"] |
Match the edge colour to the scene's background |
Scenery#
Ground is flat checkered grass at y = 0.
| Prop | Type | Default | Description |
|---|---|---|---|
size |
number | 400 |
Width and depth |
tile |
number | 4 |
Side of one checker tile |
colors |
[colour, colour] |
["#a3d77f", "#97cf72"] |
Trees scatters round and pine trees. The whole forest is two draw calls.
| Prop | Type | Default | Description |
|---|---|---|---|
count |
number | 120 |
|
area |
[minX, minZ, maxX, maxZ] |
[-80, -80, 80, 80] |
Area to scatter in |
clearing |
number | 8 |
Radius of a free circle round the origin |
scale |
[min, max] |
[0.8, 1.4] |
Size range. On Trees, scale is not a transform prop |
seed |
number | 1 |
ContactShadow is a soft shadow blob on the ground, cheaper than real shadows. Put it inside the object's group (or <Vehicle>) so it follows the object.
| Prop | Type | Default | Description |
|---|---|---|---|
width |
number | 1 |
Size along x |
length |
number | 1 |
Size along z |
opacity |
0–1 | 0.35 |
Darkness at the centre |
under |
SceneObject | null |
Sizes and places the shadow by this object's footprint, and again when it changes | |
spread |
number | 1.15 |
With under, how many times wider than the footprint |
Factories#
Each component has a factory that returns a plain three.js object, for <Primitive>, <Instances object> or three.js code. Free the objects you create with disposeObject from @apricotjs/core.
| Factory | Returns |
|---|---|
createApple(options), createCoin(options) |
THREE.Mesh |
createPeach(options), createMoneyStack(options), createCar(options), createCard(options) |
THREE.Group |
createTrees(options), createGround(options), createContactShadow(options), createBackdrop(options), createStudioFloor(options) |
THREE.Object3D |
createSedan() |
A stylised sedan for testing kits: Italian part names (carrozzeria, cofano, bagagliaio, porta_ant_sx…, ruota_*) and materials (vernice, vetro, gomma, cerchio, luce…). sx is left (+x) |
createLaptop(), createLaptopAnimation() |
A closed laptop (parts base, keyboard, trackpad, lid; lid origin at the hinge) and its "LidOpen" clip |
createWheelGeometry(radius?), createRoundTreeGeometry(), createPineTreeGeometry() |
THREE.BufferGeometry |
createCardMaterials(finish, art?), setCardFinish(card, finish, art?) |
Card materials, and a function that switches a card's finish in place |
createBanknoteMaterial(aspect, colors?) |
The banknote shader material |
Constants#
| Constant | Value |
|---|---|
CARD_SIZE |
{ width: 3.37, height: 2.125, thickness: 0.032, radius: 0.125 } |
CARD_FINISHES |
Record<CardFinish, FinishSpec>: { label, preset, color, metalness, roughness, physical?, engraving } per finish |
CAR_DIMENSIONS |
{ length: 2.1, width: 1.1, wheelRadius: 0.3, wheelBase: 1.4, track: 1.04 } |
WHEEL_NAMES |
["wheel_fl", "wheel_fr", "wheel_rl", "wheel_rr"] |
SEDAN_DIMENSIONS |
{ length: 4.5, width: 1.8, height: 1.47, wheelRadius: 0.34 } |
LAPTOP_DIMENSIONS |
{ width: 3, depth: 2.1, base: 0.12, lid: 0.08 } |
DEFAULT_BANKNOTE_COLORS |
See Money |
Related#
- card-tilt recipe, drive-joystick recipe, falling-pile recipe.
- Custom geometry: building your own objects in code.