Fork the kit into contemporary-props with a nineteen slot palette, a per-model check that needs no registry round trip, and the first model.
This commit is contained in:
parent
96ac006e8a
commit
01e9605f1e
30 changed files with 5005 additions and 16 deletions
|
|
@ -519,23 +519,36 @@ export interface RenderOptions {
|
|||
readonly towards?: readonly [number, number, number]
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders anything with a transform tree, catalogued or not.
|
||||
*
|
||||
* Split out of `renderOne` so a model can be drawn straight from the folder it
|
||||
* is being written in, before it has a catalogue entry, a registry build or an
|
||||
* install. That is the whole difference between looking at your work now and
|
||||
* looking at it after a four step round trip.
|
||||
*/
|
||||
export function renderObject(root: Object3D, options: RenderOptions): Frame {
|
||||
const { size, tall = options.size, spin = 0, ground, towards = [0.78, 0.5, 1] } = options
|
||||
// We rotate the MODEL, not the camera: framing and the shadow computation
|
||||
// stay in a fixed direction, so turntable frames compare one to one.
|
||||
root.rotation.y = spin
|
||||
const triangles = collect(root)
|
||||
const frame = newFrame(size, tall, ground)
|
||||
const { camera, floor } = frameCamera(root, size, tall, towards)
|
||||
contactShadow(frame, camera, triangles, floor)
|
||||
raster(frame, camera, triangles)
|
||||
return frame
|
||||
}
|
||||
|
||||
export function renderOne(id: string, options: RenderOptions): Frame {
|
||||
const { size, tall = options.size, patch, spin = 0, ground, towards = [0.78, 0.5, 1] } = options
|
||||
const entry = CATALOG[id]
|
||||
if (!entry) throw new Error(`not in catalog: ${id}`)
|
||||
const built = entry.build()
|
||||
if (patch && built.params) built.params.apply(patch)
|
||||
if (options.patch && built.params) built.params.apply(options.patch)
|
||||
// Catch animated models mid-motion: a frozen flame does not show that the
|
||||
// flame flickers.
|
||||
built.update?.(0.42)
|
||||
// We rotate the MODEL, not the camera: framing and the shadow computation
|
||||
// stay in a fixed direction, so turntable frames compare one to one.
|
||||
built.root.rotation.y = spin
|
||||
const triangles = collect(built.root)
|
||||
const frame = newFrame(size, tall, ground)
|
||||
const { camera, floor } = frameCamera(built.root, size, tall, towards)
|
||||
contactShadow(frame, camera, triangles, floor)
|
||||
raster(frame, camera, triangles)
|
||||
const frame = renderObject(built.root, options)
|
||||
built.dispose()
|
||||
return frame
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,16 +103,23 @@ export function findFloating(root: Object3D, options: SupportOptions = {}): Supp
|
|||
const cells = new Map<string, Cell>()
|
||||
const vertex = new Vector3()
|
||||
root.traverse((object) => {
|
||||
if (!(object instanceof Mesh)) return
|
||||
const position = object.geometry.getAttribute('position')
|
||||
// `.isMesh`, not `instanceof Mesh`. Two copies of three can be loaded at
|
||||
// once (plain `three` and `three/webgpu` are separate builds, and a second
|
||||
// project brings its own install), and across copies instanceof matches
|
||||
// nothing at all. The failure is silent and total: the traversal samples
|
||||
// no geometry, finds no components, and reports every model clean. That is
|
||||
// exactly what it did the first time this ran against another repository.
|
||||
if (!(object as { isMesh?: boolean }).isMesh) return
|
||||
const mesh = object as unknown as Mesh
|
||||
const position = mesh.geometry.getAttribute('position')
|
||||
if (!position) return
|
||||
const index = object.geometry.getIndex()
|
||||
const index = mesh.geometry.getIndex()
|
||||
const count = index ? index.count : position.count
|
||||
const name = object.name || 'unnamed'
|
||||
const name = mesh.name || 'unnamed'
|
||||
|
||||
const at = (i: number): Vector3 => {
|
||||
const v = index ? index.getX(i) : i
|
||||
return vertex.fromBufferAttribute(position, v).applyMatrix4(object.matrixWorld).clone()
|
||||
return vertex.fromBufferAttribute(position, v).applyMatrix4(mesh.matrixWorld).clone()
|
||||
}
|
||||
|
||||
for (let i = 0; i < count; i += 3) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue