Skip to content

Conversation

@Ne0nWinds
Copy link
Contributor

Related issue: #30885

Description

This PR adds support for struct definitions/declarations to the TSL transpiler.

Examples

Struct definitions:

struct Ray {
  vec3 origin;
  vec3 direction;
};
const Ray = struct({

	origin: 'vec3',
	direction: 'vec3'

}, 'Ray' );

Struct Declarations:

Ray r = Ray(vec3(0.0), vec3(0.0, 0.0, 1.0));
const r = Ray( vec3( 0.0 ), vec3( 0.0, 0.0, 1.0 ) );

Return Values / Input parameters:

// struct RaymarchResult { ... }

RaymarchResult raymarch(Ray r) {
	return RaymarchResult(vec3(0.0), 1.0);
}
export const raymarch = /*@__PURE__*/ Fn( ( [ r ] ) => {

	return RaymarchResult( vec3( 0.0 ), 1.0 );

}, { r: 'Ray', return: 'RaymarchResult' } );

Limitations

  1. Struct members can't be properly accessed. Currently, if a struct member is accessed, the transpiler will generate .member instead of .get("member"). In order to do this properly, the transpiler would need proper type resolution. Some type information is available in the linker, but this won't work in the general case.

  2. As far as I can tell (and I'm okay being corrected on this), TSL doesn't support structs with array/struct members, so this PR doesn't add support for them.

Despite these limitations, this feature still helps with the discoverability of struct syntax in TSL

@Ne0nWinds Ne0nWinds marked this pull request as ready for review November 17, 2025 19:57
@sunag sunag added this to the r182 milestone Nov 20, 2025
@sunag sunag merged commit bd03102 into mrdoob:dev Nov 21, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants