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
marcel
(marwi)
December 14, 2022, 12:00am
2
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
marcel
(marwi)
December 14, 2022, 12:00am
4
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).
marcel
(marwi)
December 14, 2022, 12:00am
5
marcel
(marwi)
December 14, 2022, 12:00am
6
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
marcel
(marwi)
December 14, 2022, 12:00am
8
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
marcel
(marwi)
December 14, 2022, 12:00am
12
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.
marcel
(marwi)
December 14, 2022, 12:00am
13
Like explained here: Discord
marcel
(marwi)
December 14, 2022, 12:00am
15
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
marcel
(marwi)
December 14, 2022, 12:00am
18
that’s basically this problem there
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