diff --git a/docs/docs/dyno-stdlib.md b/docs/docs/dyno-stdlib.md index 65c2723e..f0afb26b 100644 --- a/docs/docs/dyno-stdlib.md +++ b/docs/docs/dyno-stdlib.md @@ -232,4 +232,7 @@ This way, you can pass around a `DynoVal` that contains the all the prop | `splitGsplat(gsplat)` | Split a `Gsplat` into its components | | `combineGsplat(gsplat)` | Create a `Gsplat` from components (or inject components into an existing `Gsplat`) | | `gsplatNormal(gsplat)` | Get the `Gsplat` normal, defined as whichever X/Y/Z axis has the smallest scale | +| `gsplatXAxis(gsplat)` | Return the unit vector along the splat's X-axis | +| `gsplatYAxis(gsplat)` | Return the unit vector along the splat's Y-axis | +| `gsplatZAxis(gsplat)` | Return the unit Vector along the splat's Z-axis | | `transformGsplat(gsplat, { scale?, rotate?, translate?, recolor? })` | Transform a `Gsplat` and all its components by the given transform | diff --git a/src/dyno/splats.ts b/src/dyno/splats.ts index 31ff33b6..099374b0 100644 --- a/src/dyno/splats.ts +++ b/src/dyno/splats.ts @@ -108,6 +108,12 @@ export const combineGsplat = ({ }; export const gsplatNormal = (gsplat: DynoVal): DynoVal<"vec3"> => new GsplatNormal({ gsplat }); +export const gsplatXAxis = (gsplat: DynoVal): DynoVal<"vec3"> => + new GsplatXAxis({ gsplat }); +export const gsplatYAxis = (gsplat: DynoVal): DynoVal<"vec3"> => + new GsplatYAxis({ gsplat }); +export const gsplatZAxis = (gsplat: DynoVal): DynoVal<"vec3"> => + new GsplatZAxis({ gsplat }); export const transformGsplat = ( gsplat: DynoVal, @@ -751,6 +757,36 @@ export class GsplatNormal extends UnaryOp { } } +export class GsplatXAxis extends UnaryOp { + constructor({ gsplat }: { gsplat: DynoVal }) { + super({ a: gsplat, outKey: "xaxis", outTypeFunc: () => "vec3" }); + this.globals = () => [defineGsplat]; + this.statements = ({ inputs, outputs }) => [ + `${outputs.xaxis} = quatVec(${inputs.a}.quaternion, vec3(1.0, 0.0, 0.0));`, + ]; + } +} + +export class GsplatYAxis extends UnaryOp { + constructor({ gsplat }: { gsplat: DynoVal }) { + super({ a: gsplat, outKey: "yaxis", outTypeFunc: () => "vec3" }); + this.globals = () => [defineGsplat]; + this.statements = ({ inputs, outputs }) => [ + `${outputs.yaxis} = quatVec(${inputs.a}.quaternion, vec3(0.0, 1.0, 0.0));`, + ]; + } +} + +export class GsplatZAxis extends UnaryOp { + constructor({ gsplat }: { gsplat: DynoVal }) { + super({ a: gsplat, outKey: "zaxis", outTypeFunc: () => "vec3" }); + this.globals = () => [defineGsplat]; + this.statements = ({ inputs, outputs }) => [ + `${outputs.zaxis} = quatVec(${inputs.a}.quaternion, vec3(0.0, 0.0, 1.0));`, + ]; + } +} + export class TransformGsplat extends Dyno< {