How do you use this.context.domElement?

I’m a bit confused by the documentation, and as someone relatively new to webdev I’m not sure if I’m misunderstanding something.

Does it go in tags within the component in index.html

I’m trying to communicate with the threejs scene.

I know there’s the Needle global namespace thing, which I have working - although i was confused why that doesn’t work at the toplevel within tags e.g

<script> 
  console.log(Needle);
</script>

Whilst it does work within a seprate .js file that I reference in . Is that to do with scoping? Anyway, that’s on the side.

Many thanks

Original Post on Discord

by user 285903863339548673

Hello, how are you developing? Are you using any of our Exporters for Unity or Blender or are you trying to work with Vanilla js only?

Hey. Yes, I used the Unity Exporter - which is working nicely

by user 285903863339548673

Then you can just create a component in typescript (in e.g. src/scripts) which should generate a new c# component and attach that in Unity to one of your gameobjects. you can then access e.g. the threejs scene from that component using this.context.scene or the object the component is attached to via this.gameObject from Typescript).

Have you tried reading through Needle Engine Scripting | Needle Engine Documentation ?

Here are also some examples: Script Examples | Needle Engine Documentation

As well as samples that you might want to download and have a look at: Needle Engine Samples

What I was basically trying to achieve is to get input from an external javascript file to change something about scene i.e. changing material

by user 285903863339548673

Have a look here: Needle Engine Scripting | Needle Engine Documentation

Or for example someone clicks a button elsewhere in the DOM and that changes the scene

by user 285903863339548673

Yes, have read through that but have gotten stuck!

by user 285903863339548673

Thanks for helping, by the way

by user 285903863339548673

you can query components in the scene once the scene has loaded. You can either use the loadfinished callback method for that and then Needle.findObjectOfType(<componentType>) OR query the <needle-engine> webcomponent via javascript and get the context.

Like explained here: Discord

sure!

Sorry if the docs are a bit confusing - we need to add more examples and step by step guides to make it simpler to follow

“query the webcomponent via javascript and get the context.” Yes! I was stuck trying to do that

by user 285903863339548673

What would that look like?

by user 285903863339548673

that’s basically this problem there :slightly_smiling_face:

Oh cool I’ll have a look

by user 285903863339548673

In the docs: Needle Engine Scripting | Needle Engine Documentation it uses await document.queryElement("needle-engine")?.getContext().

by user 285903863339548673