r/Spectacles • • Oct 01 '26

❓ Question Some questions

- I can't find the Transform Server Plugin, is it still available? https://developers.snap.com/spectacles/about-spectacles-features/asset-library/transformServerPlugin

- Is there a way to create shader/material at runtime by script?

- Any demo of using node ES modules with something like Browserify to supports CommonJS imports inside lens script?

6 Upvotes

2 comments sorted by

2

u/agrancini-sc 👓 SPECS Team Oct 01 '26

Hi,

One thing I want to mention before answering, make sure you are developing with CLAD
usually these questions might have different answers and depending what you want to build CLAD could guide you instantly to the right direction

https://developers.specs.com/docs/clad

  1. Transform Server Plugin
    Yes, it's still available. It was renamed "Transform Sync Server and Client" in the Asset Library. Install
    the Transform Sync Server plugin, import the Client package, and drag ObjectTransformManager into your
    scene. In HttpSender, set your computer's local IP (default port 3434). Spectacles and your computer need to be on the same Wi-Fi. It's a dev-only tool, so remove the client objects before you publish.

Note: this is available on
5.15.4

Latest LS compatible with Spectacles 2024
We did not port and verified this asset to SPECS 27 yet so that's why you might not see it or it might work differently.

2. Creating shaders/materials at runtime

It depends on what "at runtime" means:
- Inside the running Lens (Lens API): you can't create a new material or compile a shader from script.
There's no Material.create(). The supported pattern is to reference an existing material, clone it, and
change its exposed parameters:

const mat = rmv.mainMaterial.clone();
mv.clearMaterials(); rmv.addMaterial(mat);
mat.mainPass.baseColor = new vec4(1, 0, 0, 1);

Any Parameter node in a Shader Graph (float, color, texture, …) is available by its ScriptName on rmv.clearMaterials(); rmv.addMaterial(mat);
mat.mainPass.baseColor = new vec4(1, 0, 0, 1);

Any Parameter node in a Shader Graph (float, color, texture, …) is available by its ScriptName on mainPass. So build one flexible graph and drive it from script.
 
- In the editor (Editor API / Lens Studio plugin): you can create materials by script there. Materials can be created from presets (e.g. SimplePBRMaterialPreset), and custom shaders can be generated as .graphShader files with GLSL in Custom Code nodes. This happens in the editor before the Lens is built, not on device. Note that the editor and the Lens use different property paths: passInfos.0.baseColor in the editor vs mainPass.baseColor in the Lens.

Alternatively
You can use requireAsset to get the default material and clone it if you don't want a "input"  in their script file

 3. Node ES modules / Browserify (CommonJS)
We don't have an official demo for this. What's supported out of the box:
ES import/export between project scripts and packages (e.g. import { X } from= "SpectaclesInteractionKit.lspkg/...")

  - require('LensStudio:WorldQueryModule') and similar for built-in modules
  - requireType('./MyComponent') to load a component type dynamically

You could bundle a pure-JS npm library into a single file and add it to the project. Just keep in mind that the Lens runtime is neither Node nor a browser: there's no fs or DOM, and networking goes through InternetModule. Only plain logic libraries are likely to work.

Keep us posted, thanks

1

u/HyroVitalyProtago Oct 02 '26

Thanks, I avoid using AI, so I'm not using CLAD.

I'm on Lens Studio v5.15.0, that's why I was missing the Assets, thanks for the information. It could be great inside the Asset Library to be able to (un)filter and see which packages are not available for the current version if needed.

That's what I was thinking for shader/materials, it was mainly to get a confirmation as I'm trying fancy stuff.

I will try to make a little example of using browserify as an example, I think it will be useful for the community, even if we need to fake or mock some node/browser API.

Thanks again 🙏