🧡#Questions on Splines

0xfluffhead

First question: what is the convention of the ~ suffix for ts code? Is that a standard you are using?

marwi123

Ah sorry I misread. That is so that Unity doesnt import the folder an all the npm node modules

marwi123

So the modules repository contains a package which you can install so you get the npmdef and all that stuff (and the codegen) in your unity project. All npmdefs generate hidden npm packages - but we never want them to be imported by Unity. That's why they are all postfixed with ~

marwi123

The annotation is just for telling codegen (the one that produces the c# component from typescript) which field type to generate.

marwi123

The data is exported from the splines package (the SplineContainer component that comes with the Unity splines package - as you linked above)

marwi123

The spline walker is just an additional component we used/added for moving some stuff along the spline. You dont have to use that

0xfluffhead

Got it, but in this context for that you would just remove the don’t generate component part so that you could use it as is

0xfluffhead

And then it’s just serializing the data from the c# code on one of your gltf extensions to make that data available in ts?

marwi123

the dont-generate-component is also just for the Unity component generator - so in this case the Unity component already exists (from the Unity splines package) and we dont want to generate another C# component from the typescript file for it

0xfluffhead

So you’re essentially just pulling data from the C# class by marking the serializable fields and then it’s up to you to create the logic on ts side

marwi123

Sorry if it's confusing πŸ™‚ since we have some annotations that are for the runtime and some that are just for the editor.

Everything that is just a comment //@ .... is in general for the component generator. You can check the readme here for the available commands: https://www.npmjs.com/package/@needle-tools/needle-component-compiler

And the serializer that exports the data from Unity right now does not care about what fields or annotations you have in your Typescript file - later on we might just serialize the fileds that you have actually declared but right now it will all just be exported.

0xfluffhead

Essentially, think of components as just data transfer between both systems. Codegen exists for custom classes to expose to unity

marwi123

Yes, codegen exists so we dont have to write a C# component for every new Typescript component we want - we just write typescript, codegen comes in and builds the matching C# code for us and we can use it in Unity and assign the stuff

0xfluffhead

Ok great. This really helps me understand the architecture now. And I’m assuming from reading the docs that it does this from the custom needle component gltf extension?

marwi123

The data goes in the needle gltf component extension - but it doesnt care about what data your component contains. We just pack it in there and the runtime engine reads it and builds and attaches the typescript components and tries to deserialize the data to concrete javascript types (e.g. if you have a Vector3 it will be serialized as { x: ... y ... z.... } json and it will deserialize it as e.g. a threejs Vector3 if you add @serializable(Vector3) to it - that's what the typescript decorators are used for

0xfluffhead

Ok so it’s just looking at the shape of the json data coming in and seeing what ts object you’re serializing until and tries to make it work based on some simple data transformations checks?

marwi123

Yes basically πŸ™‚

if you look into @needle-tools/engine/engine/engine_serialization_builtin_serializer.ts you find some implementations of the TypeSerializer - those are responsible for resolving the serialized data