Make the fold and squeeze sliders do something: both poses live in anchor rotations that no rebuild re-applies, so the controls were inert while the methods worked.
This commit is contained in:
parent
275a76d1f2
commit
314d24cc64
5 changed files with 223 additions and 101 deletions
|
|
@ -75,6 +75,11 @@ export interface FireExtinguisherActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createModel(overrides: Partial<FireExtinguisherConfig> = {}) {
|
export function createModel(overrides: Partial<FireExtinguisherConfig> = {}) {
|
||||||
|
// Shared by the action and the frame hook; they are two properties of one
|
||||||
|
// options object and otherwise have no way to agree.
|
||||||
|
let heldSqueeze = 0
|
||||||
|
let seenSqueeze = Number.NaN
|
||||||
|
|
||||||
return createKitModel<
|
return createKitModel<
|
||||||
FireExtinguisherConfig,
|
FireExtinguisherConfig,
|
||||||
'retroreflective' | 'chrome' | 'steelPainted' | 'rubber' | 'brass',
|
'retroreflective' | 'chrome' | 'steelPainted' | 'rubber' | 'brass',
|
||||||
|
|
@ -603,8 +608,28 @@ export function createModel(overrides: Partial<FireExtinguisherConfig> = {}) {
|
||||||
*/
|
*/
|
||||||
parts.lever.anchor.rotation.z = -Math.min(1, Math.max(0, amount)) * 0.46
|
parts.lever.anchor.rotation.z = -Math.min(1, Math.max(0, amount)) * 0.46
|
||||||
}
|
}
|
||||||
set(getConfig().squeeze)
|
heldSqueeze = getConfig().squeeze
|
||||||
return { squeeze: (amount = 1) => { set(amount) } }
|
seenSqueeze = heldSqueeze
|
||||||
|
set(heldSqueeze)
|
||||||
|
return {
|
||||||
|
squeeze: (amount = 1) => { heldSqueeze = amount; set(amount) },
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ...and the slider has to reach it, which the action alone does not do.
|
||||||
|
*
|
||||||
|
* `squeeze` is both a control and a method. Moving the control calls
|
||||||
|
* `configure()`, which rebuilds the geometry -- and the lever's pose is a
|
||||||
|
* single anchor rotation that no rebuild re-applies, so in the viewer the
|
||||||
|
* slider was inert while the method worked. Adopting the config into the
|
||||||
|
* held value whenever it changes, and re-applying every frame, makes the
|
||||||
|
* two agree without letting either override the other.
|
||||||
|
*/
|
||||||
|
update: (_dt, { parts, getConfig }) => {
|
||||||
|
const wanted = getConfig().squeeze
|
||||||
|
if (wanted !== seenSqueeze) { seenSqueeze = wanted; heldSqueeze = wanted }
|
||||||
|
parts.lever.anchor.rotation.z = -Math.min(1, Math.max(0, heldSqueeze)) * 0.46
|
||||||
},
|
},
|
||||||
}, overrides)
|
}, overrides)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import {
|
||||||
latheGeometry,
|
latheGeometry,
|
||||||
mergeColoured,
|
mergeColoured,
|
||||||
smoothNormals,
|
smoothNormals,
|
||||||
|
type RuntimeContext,
|
||||||
} from '../core/index.ts'
|
} from '../core/index.ts'
|
||||||
|
|
||||||
export interface PavementSignConfig {
|
export interface PavementSignConfig {
|
||||||
|
|
@ -71,7 +72,66 @@ const STAY_AT = 0.62
|
||||||
const reachOf = (Lp: number): number =>
|
const reachOf = (Lp: number): number =>
|
||||||
Lp * STAY_AT * Math.sin(OPEN) - (SECTION_T / 2) * Math.cos(OPEN)
|
Lp * STAY_AT * Math.sin(OPEN) - (SECTION_T / 2) * Math.cos(OPEN)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pose, written once because TWO THINGS drive it.
|
||||||
|
*
|
||||||
|
* `fold` is a slider and a method. Moving the slider calls `configure()`,
|
||||||
|
* which rebuilds the geometry -- and the geometry does not depend on the fold
|
||||||
|
* at all, because the whole pose is anchor rotations. A rebuild does not
|
||||||
|
* re-run the action that set them, so in the viewer the slider was inert.
|
||||||
|
*
|
||||||
|
* Rebuilding also resets each anchor's POSITION to its origin while leaving
|
||||||
|
* its rotation alone. That is the kit's rule and it is the right one, but this
|
||||||
|
* model drives both, so after any rebuild the pin height and the panel angle
|
||||||
|
* disagreed. Hence one function, called from the action and again every frame.
|
||||||
|
*/
|
||||||
|
function applyFold(
|
||||||
|
runtime: RuntimeContext<PavementSignConfig, PavementSignParts>,
|
||||||
|
amount: number,
|
||||||
|
): void {
|
||||||
|
const { parts } = runtime
|
||||||
|
const t = Math.min(1, Math.max(0, amount))
|
||||||
|
const angle = OPEN * (1 - t)
|
||||||
|
parts.front.anchor.rotation.x = angle
|
||||||
|
parts.back.anchor.rotation.x = -angle
|
||||||
|
|
||||||
|
// The pin rises as the panels straighten, because a folded A-board is taller
|
||||||
|
// than an open one and an origin left at the open height buries the feet.
|
||||||
|
const Lp = Math.min(1.4, Math.max(0.5, runtime.getConfig().panel))
|
||||||
|
const hingeY = Lp * Math.cos(angle)
|
||||||
|
for (const part of [parts.front, parts.back, parts.hinges]) {
|
||||||
|
part.anchor.position.setY(hingeY)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ...and then the stay follows, which is two numbers per link.
|
||||||
|
*
|
||||||
|
* The pin sits on the panel's inner face `STAY_AT` of the way down, so where
|
||||||
|
* it ENDS UP is the panel's own rotation applied to that point. The knuckle
|
||||||
|
* is on the centre plane at whatever height a link of fixed length can still
|
||||||
|
* reach from there -- which is what makes the pair go straight when open and
|
||||||
|
* hang when shut, with no case analysis and no clamp.
|
||||||
|
*/
|
||||||
|
const reach = reachOf(Lp)
|
||||||
|
for (const [part, facing] of [[parts.stayFront, -1], [parts.stayBack, 1]] as const) {
|
||||||
|
const rot = -facing * angle
|
||||||
|
const ly = -Lp * STAY_AT
|
||||||
|
const lz = (-facing * SECTION_T) / 2
|
||||||
|
const ay = hingeY + ly * Math.cos(rot) - lz * Math.sin(rot)
|
||||||
|
const az = ly * Math.sin(rot) + lz * Math.cos(rot)
|
||||||
|
part.anchor.position.set(0, ay, az)
|
||||||
|
// Built hanging along -Y, so the angle that points it at the knuckle is
|
||||||
|
// measured from straight down.
|
||||||
|
part.anchor.rotation.x = Math.atan2(az, Math.sqrt(Math.max(0, reach * reach - az * az)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function createModel(overrides: Partial<PavementSignConfig> = {}) {
|
export function createModel(overrides: Partial<PavementSignConfig> = {}) {
|
||||||
|
// Shared by the action and the frame hook, which are two properties of the
|
||||||
|
// same options object and otherwise have no way to agree.
|
||||||
|
let heldFold = 0
|
||||||
|
let seenFold = Number.NaN
|
||||||
|
|
||||||
return createKitModel<
|
return createKitModel<
|
||||||
PavementSignConfig,
|
PavementSignConfig,
|
||||||
'steelPainted' | 'plastic' | 'rubber' | 'stainless',
|
'steelPainted' | 'plastic' | 'rubber' | 'stainless',
|
||||||
|
|
@ -305,46 +365,22 @@ export function createModel(overrides: Partial<PavementSignConfig> = {}) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: ({ parts, getConfig }) => {
|
actions: (runtime) => {
|
||||||
const set = (amount: number): void => {
|
heldFold = runtime.getConfig().fold
|
||||||
const t = Math.min(1, Math.max(0, amount))
|
seenFold = heldFold
|
||||||
const angle = OPEN * (1 - t)
|
applyFold(runtime, heldFold)
|
||||||
parts.front.anchor.rotation.x = angle
|
return {
|
||||||
parts.back.anchor.rotation.x = -angle
|
fold: (amount = 1) => { heldFold = amount; applyFold(runtime, amount) },
|
||||||
// ...and the pin rises as the panels straighten, because a folded
|
|
||||||
// A-board is taller than an open one and an origin left at the open
|
|
||||||
// height buries the feet.
|
|
||||||
const Lp = Math.min(1.4, Math.max(0.5, getConfig().panel))
|
|
||||||
const hingeY = Lp * Math.cos(angle)
|
|
||||||
for (const part of [parts.front, parts.back, parts.hinges]) {
|
|
||||||
part.anchor.position.setY(hingeY)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ...and then the stay follows, which is two numbers per link.
|
|
||||||
*
|
|
||||||
* The pin sits on the panel's inner face `STAY_AT` of the way down, so
|
|
||||||
* where it ENDS UP is the panel's own rotation applied to that point.
|
|
||||||
* The knuckle is on the centre plane at whatever height a link of
|
|
||||||
* fixed length can still reach from there -- which is what makes the
|
|
||||||
* pair go straight when open and hang when shut, with no case
|
|
||||||
* analysis and no clamp.
|
|
||||||
*/
|
|
||||||
const reach = reachOf(Lp)
|
|
||||||
for (const [part, facing] of [[parts.stayFront, -1], [parts.stayBack, 1]] as const) {
|
|
||||||
const rot = -facing * angle
|
|
||||||
const ly = -Lp * STAY_AT
|
|
||||||
const lz = (-facing * SECTION_T) / 2
|
|
||||||
const ay = hingeY + ly * Math.cos(rot) - lz * Math.sin(rot)
|
|
||||||
const az = ly * Math.sin(rot) + lz * Math.cos(rot)
|
|
||||||
part.anchor.position.set(0, ay, az)
|
|
||||||
// Built hanging along -Y, so the angle that points it at the knuckle
|
|
||||||
// is measured from straight down.
|
|
||||||
part.anchor.rotation.x = Math.atan2(az, Math.sqrt(Math.max(0, reach * reach - az * az)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
set(getConfig().fold)
|
},
|
||||||
return { fold: (amount = 1) => { set(amount) } }
|
|
||||||
|
// The config is adopted into the held pose whenever it changes, and the
|
||||||
|
// held pose is re-applied every frame. Between slider moves the action
|
||||||
|
// wins, which is what lets a consumer animate the sign.
|
||||||
|
update: (_dt, runtime) => {
|
||||||
|
const wanted = runtime.getConfig().fold
|
||||||
|
if (wanted !== seenFold) { seenFold = wanted; heldFold = wanted }
|
||||||
|
applyFold(runtime, heldFold)
|
||||||
},
|
},
|
||||||
}, overrides)
|
}, overrides)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -677,7 +677,7 @@
|
||||||
"address": "@contemporary-props/core",
|
"address": "@contemporary-props/core",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.045Z",
|
"installedAt": "2026-09-02T00:24:37.311Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\core\\geometry.ts",
|
"path": "src\\models\\contemporary-props\\core\\geometry.ts",
|
||||||
|
|
@ -724,7 +724,7 @@
|
||||||
"address": "@contemporary-props/ceramic-vase",
|
"address": "@contemporary-props/ceramic-vase",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.047Z",
|
"installedAt": "2026-09-02T00:24:37.314Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\ceramic-vase\\model.ts",
|
"path": "src\\models\\contemporary-props\\ceramic-vase\\model.ts",
|
||||||
|
|
@ -739,7 +739,7 @@
|
||||||
"address": "@contemporary-props/coffee-mug",
|
"address": "@contemporary-props/coffee-mug",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.048Z",
|
"installedAt": "2026-09-02T00:24:37.316Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\coffee-mug\\model.ts",
|
"path": "src\\models\\contemporary-props\\coffee-mug\\model.ts",
|
||||||
|
|
@ -754,7 +754,7 @@
|
||||||
"address": "@contemporary-props/pepper-mill",
|
"address": "@contemporary-props/pepper-mill",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.058Z",
|
"installedAt": "2026-09-02T00:24:37.330Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\pepper-mill\\model.ts",
|
"path": "src\\models\\contemporary-props\\pepper-mill\\model.ts",
|
||||||
|
|
@ -769,7 +769,7 @@
|
||||||
"address": "@contemporary-props/stockpot",
|
"address": "@contemporary-props/stockpot",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.061Z",
|
"installedAt": "2026-09-02T00:24:37.333Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\stockpot\\model.ts",
|
"path": "src\\models\\contemporary-props\\stockpot\\model.ts",
|
||||||
|
|
@ -784,7 +784,7 @@
|
||||||
"address": "@contemporary-props/traffic-cone",
|
"address": "@contemporary-props/traffic-cone",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.064Z",
|
"installedAt": "2026-09-02T00:24:37.336Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\traffic-cone\\model.ts",
|
"path": "src\\models\\contemporary-props\\traffic-cone\\model.ts",
|
||||||
|
|
@ -799,7 +799,7 @@
|
||||||
"address": "@contemporary-props/wine-glass",
|
"address": "@contemporary-props/wine-glass",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.065Z",
|
"installedAt": "2026-09-02T00:24:37.338Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\wine-glass\\model.ts",
|
"path": "src\\models\\contemporary-props\\wine-glass\\model.ts",
|
||||||
|
|
@ -814,7 +814,7 @@
|
||||||
"address": "@contemporary-props/kit",
|
"address": "@contemporary-props/kit",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.065Z",
|
"installedAt": "2026-09-02T00:24:37.338Z",
|
||||||
"files": [],
|
"files": [],
|
||||||
"dependencies": []
|
"dependencies": []
|
||||||
},
|
},
|
||||||
|
|
@ -822,7 +822,7 @@
|
||||||
"address": "@contemporary-props/street-bollard",
|
"address": "@contemporary-props/street-bollard",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.063Z",
|
"installedAt": "2026-09-02T00:24:37.335Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\street-bollard\\model.ts",
|
"path": "src\\models\\contemporary-props\\street-bollard\\model.ts",
|
||||||
|
|
@ -837,7 +837,7 @@
|
||||||
"address": "@contemporary-props/gas-cylinder",
|
"address": "@contemporary-props/gas-cylinder",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.051Z",
|
"installedAt": "2026-09-02T00:24:37.320Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\gas-cylinder\\model.ts",
|
"path": "src\\models\\contemporary-props\\gas-cylinder\\model.ts",
|
||||||
|
|
@ -852,11 +852,11 @@
|
||||||
"address": "@contemporary-props/fire-extinguisher",
|
"address": "@contemporary-props/fire-extinguisher",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.049Z",
|
"installedAt": "2026-09-02T00:24:37.318Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\fire-extinguisher\\model.ts",
|
"path": "src\\models\\contemporary-props\\fire-extinguisher\\model.ts",
|
||||||
"sourceHash": "34214096d2b5c4ccf53c3d6ea302d9f1168ea27e5207e67e0e5b46807621270f"
|
"sourceHash": "39e9a1f69730b8fcd9eaa0beefa36f25fbd79b591bc009c28adaca47d61cd16c"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
|
@ -867,7 +867,7 @@
|
||||||
"address": "@contemporary-props/pedestal-basin",
|
"address": "@contemporary-props/pedestal-basin",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.057Z",
|
"installedAt": "2026-09-02T00:24:37.328Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\pedestal-basin\\model.ts",
|
"path": "src\\models\\contemporary-props\\pedestal-basin\\model.ts",
|
||||||
|
|
@ -882,7 +882,7 @@
|
||||||
"address": "@contemporary-props/jersey-barrier",
|
"address": "@contemporary-props/jersey-barrier",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.052Z",
|
"installedAt": "2026-09-02T00:24:37.321Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\jersey-barrier\\model.ts",
|
"path": "src\\models\\contemporary-props\\jersey-barrier\\model.ts",
|
||||||
|
|
@ -897,7 +897,7 @@
|
||||||
"address": "@contemporary-props/picnic-table",
|
"address": "@contemporary-props/picnic-table",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.059Z",
|
"installedAt": "2026-09-02T00:24:37.331Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\picnic-table\\model.ts",
|
"path": "src\\models\\contemporary-props\\picnic-table\\model.ts",
|
||||||
|
|
@ -912,7 +912,7 @@
|
||||||
"address": "@contemporary-props/park-bench",
|
"address": "@contemporary-props/park-bench",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.055Z",
|
"installedAt": "2026-09-02T00:24:37.325Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\park-bench\\model.ts",
|
"path": "src\\models\\contemporary-props\\park-bench\\model.ts",
|
||||||
|
|
@ -927,11 +927,11 @@
|
||||||
"address": "@contemporary-props/pavement-sign-board",
|
"address": "@contemporary-props/pavement-sign-board",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.056Z",
|
"installedAt": "2026-09-02T00:24:37.326Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\pavement-sign-board\\model.ts",
|
"path": "src\\models\\contemporary-props\\pavement-sign-board\\model.ts",
|
||||||
"sourceHash": "4ff1598806e5a049dd1e6d7a286b39bd905992e4d20c11272e6f4c0d32002fa8"
|
"sourceHash": "8b86bd53e6fa83eb72f8551cb88d1689e807d9949f70b22fda6a4045bf857f8e"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
|
@ -942,7 +942,7 @@
|
||||||
"address": "@contemporary-props/lectern",
|
"address": "@contemporary-props/lectern",
|
||||||
"source": "file:contemporary-props/dist/registry.json",
|
"source": "file:contemporary-props/dist/registry.json",
|
||||||
"version": "workspace",
|
"version": "workspace",
|
||||||
"installedAt": "2026-09-02T00:10:18.053Z",
|
"installedAt": "2026-09-02T00:24:37.323Z",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "src\\models\\contemporary-props\\lectern\\model.ts",
|
"path": "src\\models\\contemporary-props\\lectern\\model.ts",
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,11 @@ export interface FireExtinguisherActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createModel(overrides: Partial<FireExtinguisherConfig> = {}) {
|
export function createModel(overrides: Partial<FireExtinguisherConfig> = {}) {
|
||||||
|
// Shared by the action and the frame hook; they are two properties of one
|
||||||
|
// options object and otherwise have no way to agree.
|
||||||
|
let heldSqueeze = 0
|
||||||
|
let seenSqueeze = Number.NaN
|
||||||
|
|
||||||
return createKitModel<
|
return createKitModel<
|
||||||
FireExtinguisherConfig,
|
FireExtinguisherConfig,
|
||||||
'retroreflective' | 'chrome' | 'steelPainted' | 'rubber' | 'brass',
|
'retroreflective' | 'chrome' | 'steelPainted' | 'rubber' | 'brass',
|
||||||
|
|
@ -603,8 +608,28 @@ export function createModel(overrides: Partial<FireExtinguisherConfig> = {}) {
|
||||||
*/
|
*/
|
||||||
parts.lever.anchor.rotation.z = -Math.min(1, Math.max(0, amount)) * 0.46
|
parts.lever.anchor.rotation.z = -Math.min(1, Math.max(0, amount)) * 0.46
|
||||||
}
|
}
|
||||||
set(getConfig().squeeze)
|
heldSqueeze = getConfig().squeeze
|
||||||
return { squeeze: (amount = 1) => { set(amount) } }
|
seenSqueeze = heldSqueeze
|
||||||
|
set(heldSqueeze)
|
||||||
|
return {
|
||||||
|
squeeze: (amount = 1) => { heldSqueeze = amount; set(amount) },
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ...and the slider has to reach it, which the action alone does not do.
|
||||||
|
*
|
||||||
|
* `squeeze` is both a control and a method. Moving the control calls
|
||||||
|
* `configure()`, which rebuilds the geometry -- and the lever's pose is a
|
||||||
|
* single anchor rotation that no rebuild re-applies, so in the viewer the
|
||||||
|
* slider was inert while the method worked. Adopting the config into the
|
||||||
|
* held value whenever it changes, and re-applying every frame, makes the
|
||||||
|
* two agree without letting either override the other.
|
||||||
|
*/
|
||||||
|
update: (_dt, { parts, getConfig }) => {
|
||||||
|
const wanted = getConfig().squeeze
|
||||||
|
if (wanted !== seenSqueeze) { seenSqueeze = wanted; heldSqueeze = wanted }
|
||||||
|
parts.lever.anchor.rotation.z = -Math.min(1, Math.max(0, heldSqueeze)) * 0.46
|
||||||
},
|
},
|
||||||
}, overrides)
|
}, overrides)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import {
|
||||||
latheGeometry,
|
latheGeometry,
|
||||||
mergeColoured,
|
mergeColoured,
|
||||||
smoothNormals,
|
smoothNormals,
|
||||||
|
type RuntimeContext,
|
||||||
} from '../core/index.ts'
|
} from '../core/index.ts'
|
||||||
|
|
||||||
export interface PavementSignConfig {
|
export interface PavementSignConfig {
|
||||||
|
|
@ -71,7 +72,66 @@ const STAY_AT = 0.62
|
||||||
const reachOf = (Lp: number): number =>
|
const reachOf = (Lp: number): number =>
|
||||||
Lp * STAY_AT * Math.sin(OPEN) - (SECTION_T / 2) * Math.cos(OPEN)
|
Lp * STAY_AT * Math.sin(OPEN) - (SECTION_T / 2) * Math.cos(OPEN)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pose, written once because TWO THINGS drive it.
|
||||||
|
*
|
||||||
|
* `fold` is a slider and a method. Moving the slider calls `configure()`,
|
||||||
|
* which rebuilds the geometry -- and the geometry does not depend on the fold
|
||||||
|
* at all, because the whole pose is anchor rotations. A rebuild does not
|
||||||
|
* re-run the action that set them, so in the viewer the slider was inert.
|
||||||
|
*
|
||||||
|
* Rebuilding also resets each anchor's POSITION to its origin while leaving
|
||||||
|
* its rotation alone. That is the kit's rule and it is the right one, but this
|
||||||
|
* model drives both, so after any rebuild the pin height and the panel angle
|
||||||
|
* disagreed. Hence one function, called from the action and again every frame.
|
||||||
|
*/
|
||||||
|
function applyFold(
|
||||||
|
runtime: RuntimeContext<PavementSignConfig, PavementSignParts>,
|
||||||
|
amount: number,
|
||||||
|
): void {
|
||||||
|
const { parts } = runtime
|
||||||
|
const t = Math.min(1, Math.max(0, amount))
|
||||||
|
const angle = OPEN * (1 - t)
|
||||||
|
parts.front.anchor.rotation.x = angle
|
||||||
|
parts.back.anchor.rotation.x = -angle
|
||||||
|
|
||||||
|
// The pin rises as the panels straighten, because a folded A-board is taller
|
||||||
|
// than an open one and an origin left at the open height buries the feet.
|
||||||
|
const Lp = Math.min(1.4, Math.max(0.5, runtime.getConfig().panel))
|
||||||
|
const hingeY = Lp * Math.cos(angle)
|
||||||
|
for (const part of [parts.front, parts.back, parts.hinges]) {
|
||||||
|
part.anchor.position.setY(hingeY)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ...and then the stay follows, which is two numbers per link.
|
||||||
|
*
|
||||||
|
* The pin sits on the panel's inner face `STAY_AT` of the way down, so where
|
||||||
|
* it ENDS UP is the panel's own rotation applied to that point. The knuckle
|
||||||
|
* is on the centre plane at whatever height a link of fixed length can still
|
||||||
|
* reach from there -- which is what makes the pair go straight when open and
|
||||||
|
* hang when shut, with no case analysis and no clamp.
|
||||||
|
*/
|
||||||
|
const reach = reachOf(Lp)
|
||||||
|
for (const [part, facing] of [[parts.stayFront, -1], [parts.stayBack, 1]] as const) {
|
||||||
|
const rot = -facing * angle
|
||||||
|
const ly = -Lp * STAY_AT
|
||||||
|
const lz = (-facing * SECTION_T) / 2
|
||||||
|
const ay = hingeY + ly * Math.cos(rot) - lz * Math.sin(rot)
|
||||||
|
const az = ly * Math.sin(rot) + lz * Math.cos(rot)
|
||||||
|
part.anchor.position.set(0, ay, az)
|
||||||
|
// Built hanging along -Y, so the angle that points it at the knuckle is
|
||||||
|
// measured from straight down.
|
||||||
|
part.anchor.rotation.x = Math.atan2(az, Math.sqrt(Math.max(0, reach * reach - az * az)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function createModel(overrides: Partial<PavementSignConfig> = {}) {
|
export function createModel(overrides: Partial<PavementSignConfig> = {}) {
|
||||||
|
// Shared by the action and the frame hook, which are two properties of the
|
||||||
|
// same options object and otherwise have no way to agree.
|
||||||
|
let heldFold = 0
|
||||||
|
let seenFold = Number.NaN
|
||||||
|
|
||||||
return createKitModel<
|
return createKitModel<
|
||||||
PavementSignConfig,
|
PavementSignConfig,
|
||||||
'steelPainted' | 'plastic' | 'rubber' | 'stainless',
|
'steelPainted' | 'plastic' | 'rubber' | 'stainless',
|
||||||
|
|
@ -305,46 +365,22 @@ export function createModel(overrides: Partial<PavementSignConfig> = {}) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: ({ parts, getConfig }) => {
|
actions: (runtime) => {
|
||||||
const set = (amount: number): void => {
|
heldFold = runtime.getConfig().fold
|
||||||
const t = Math.min(1, Math.max(0, amount))
|
seenFold = heldFold
|
||||||
const angle = OPEN * (1 - t)
|
applyFold(runtime, heldFold)
|
||||||
parts.front.anchor.rotation.x = angle
|
return {
|
||||||
parts.back.anchor.rotation.x = -angle
|
fold: (amount = 1) => { heldFold = amount; applyFold(runtime, amount) },
|
||||||
// ...and the pin rises as the panels straighten, because a folded
|
|
||||||
// A-board is taller than an open one and an origin left at the open
|
|
||||||
// height buries the feet.
|
|
||||||
const Lp = Math.min(1.4, Math.max(0.5, getConfig().panel))
|
|
||||||
const hingeY = Lp * Math.cos(angle)
|
|
||||||
for (const part of [parts.front, parts.back, parts.hinges]) {
|
|
||||||
part.anchor.position.setY(hingeY)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ...and then the stay follows, which is two numbers per link.
|
|
||||||
*
|
|
||||||
* The pin sits on the panel's inner face `STAY_AT` of the way down, so
|
|
||||||
* where it ENDS UP is the panel's own rotation applied to that point.
|
|
||||||
* The knuckle is on the centre plane at whatever height a link of
|
|
||||||
* fixed length can still reach from there -- which is what makes the
|
|
||||||
* pair go straight when open and hang when shut, with no case
|
|
||||||
* analysis and no clamp.
|
|
||||||
*/
|
|
||||||
const reach = reachOf(Lp)
|
|
||||||
for (const [part, facing] of [[parts.stayFront, -1], [parts.stayBack, 1]] as const) {
|
|
||||||
const rot = -facing * angle
|
|
||||||
const ly = -Lp * STAY_AT
|
|
||||||
const lz = (-facing * SECTION_T) / 2
|
|
||||||
const ay = hingeY + ly * Math.cos(rot) - lz * Math.sin(rot)
|
|
||||||
const az = ly * Math.sin(rot) + lz * Math.cos(rot)
|
|
||||||
part.anchor.position.set(0, ay, az)
|
|
||||||
// Built hanging along -Y, so the angle that points it at the knuckle
|
|
||||||
// is measured from straight down.
|
|
||||||
part.anchor.rotation.x = Math.atan2(az, Math.sqrt(Math.max(0, reach * reach - az * az)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
set(getConfig().fold)
|
},
|
||||||
return { fold: (amount = 1) => { set(amount) } }
|
|
||||||
|
// The config is adopted into the held pose whenever it changes, and the
|
||||||
|
// held pose is re-applied every frame. Between slider moves the action
|
||||||
|
// wins, which is what lets a consumer animate the sign.
|
||||||
|
update: (_dt, runtime) => {
|
||||||
|
const wanted = runtime.getConfig().fold
|
||||||
|
if (wanted !== seenFold) { seenFold = wanted; heldFold = wanted }
|
||||||
|
applyFold(runtime, heldFold)
|
||||||
},
|
},
|
||||||
}, overrides)
|
}, overrides)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue