| title | position | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| description | Read the model origin in another model’s solved local frame. | ||||||||||||||||
| sourceReview |
|
||||||||||||||||
| sidebar |
|
||||||||||||||||
| head |
|
Read the model origin in another model’s solved local frame.
import {on, box, group, offset} from '@code3d/core';
const base = box(20, 4, 20);
const part = box(8, 12, 4).relate(() => [on(base.up), offset(20, 0, 0)]);
export const size = part.bounds().size; // [8, 12, 4]
export const origin = part.position(base); // [20, 8, 0]
export const minimum = part.bounds(base).minimum; // [16, 2, -2]
export default group([base, part]);model.position(relativeTo: Model): Vec3;
type Vec3 = readonly [number, number, number];Import the functions and named types from @code3d/core.
Every model kind, including groups, supports position. relativeTo is required
and must be a model; the result is an XYZ coordinate tuple in its local frame.
Existing relations are solved, and a unique member occurrence inside a nested
reference group is respected. It is neither camera coordinates nor an implicit
application-global position.
The example's part origin is [20, 8, 0] in the base frame: the contact puts
its half-height 6 above the base top at Y = 2, followed by an X offset of 20.
part.position(part) is always [0, 0, 0].
Position measures the model's coordinate origin, not its geometric center or
minimum bound. A point([10, 0, 0]) model still has origin zero in its own frame;
its actual vertex is at X = 10. Origin edits change the relationship between
geometry and the frame, so use bounds or distance
when the geometry itself is the measurement target.
Unrelated models use coincident origins and matching axes. A group keeps its
composition frame. A bare source with multiple occurrences in a reference group
is ambiguous and throws; select an unambiguous instance or create distinct part
values. position is a reserved model member name and cannot be exposed over.
The result is ordinary numeric data in model units. Reading it changes neither
model. It reflects relationships already attached at the call; constraints still
being constructed inside a relate callback are not yet attached. Creating
additional related model values later does not update a previously stored tuple.