Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/docs/dyno-stdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,7 @@ This way, you can pass around a `DynoVal<Gsplat>` 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 |
36 changes: 36 additions & 0 deletions src/dyno/splats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ export const combineGsplat = ({
};
export const gsplatNormal = (gsplat: DynoVal<typeof Gsplat>): DynoVal<"vec3"> =>
new GsplatNormal({ gsplat });
export const gsplatXAxis = (gsplat: DynoVal<typeof Gsplat>): DynoVal<"vec3"> =>
new GsplatXAxis({ gsplat });
export const gsplatYAxis = (gsplat: DynoVal<typeof Gsplat>): DynoVal<"vec3"> =>
new GsplatYAxis({ gsplat });
export const gsplatZAxis = (gsplat: DynoVal<typeof Gsplat>): DynoVal<"vec3"> =>
new GsplatZAxis({ gsplat });

export const transformGsplat = (
gsplat: DynoVal<typeof Gsplat>,
Expand Down Expand Up @@ -751,6 +757,36 @@ export class GsplatNormal extends UnaryOp<typeof Gsplat, "vec3", "normal"> {
}
}

export class GsplatXAxis extends UnaryOp<typeof Gsplat, "vec3", "xaxis"> {
constructor({ gsplat }: { gsplat: DynoVal<typeof Gsplat> }) {
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<typeof Gsplat, "vec3", "yaxis"> {
constructor({ gsplat }: { gsplat: DynoVal<typeof Gsplat> }) {
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<typeof Gsplat, "vec3", "zaxis"> {
constructor({ gsplat }: { gsplat: DynoVal<typeof Gsplat> }) {
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<
{
Expand Down
Loading