#Can we add objects by script?

1 messages · Page 1 of 1 (latest)

tranquil beacon
#

Hi everyone! I'm completely new to needle engine and this forum. I am using Needle in a personal project and want to borrow the idea with sockets and understand the basics of needle for creating a floorplan by serializables. I am currently struggling how to add a simple Cube in a grid with Typescript. I want to prevent use another toolkit in combination of - like BabylonJS.

Hope someone can help me and please feel free to inform me if I am hasty to asking questions here.

Thanks!

tags: scripting

tranquil beacon
dark sonnet
#

Here :
https://engine.needle.tools/docs/scripting.html#version-control

You can instantiate prefab and add it to your gameObject or your scene

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development, and can be deployed anywhere. It is flexible, extensible, and collaboration and XR come naturally. Needle Exporter for Unity bridges the Unity Editor and the web runtime. It helps you to export your assets, animations, lightmaps and so on to the web. It is...

tranquil beacon
#

Thanks @dark sonnet ! I got it. Is it possible to set position of my cube in a grid by something like a coordinate "2x3"?
( {x: number}x{y: number} )

dark sonnet
#

Yes by using of the tools of Needle or three
Like

cube.position.set(x, y, z)
Or cube.translateX(x) (same with y and z
Etc

tranquil beacon
#

Great! So I could calculate by this format {x}x{y},
how it should translate my object, right? And translate will always start from 0?

dark sonnet
#

Translate start from the actual position of your object (if x is 10 and you translateX(5) then x is 15)
Set use the local position of your object

If you want to use a string to place your object, then yes you need to calculate it like with split('x') in js and convert your string to number
Or with {x}x{y} as you said etc

  • the position depend of the scale of your objects, you need to think to it too
tranquil beacon
#

Amazing! How could I add DragControls as component to this object

zealous quest
#

e.g. GameObject.addNewComponent(cube, DragControls)

tranquil beacon
#

Hi @zealous quest,
thank you always for quick response 🙂
I tried that, no error occurs but the cube does not recognize a drag event.

#

It continues just with rotating and moving the camera

zealous quest
#

You need to add an ObjectRaycaster somewhere in the hierarchy too (either the object itself or some parent)

tranquil beacon
#

Ok, what is an object raycaster for? There is somewhere a raycaster component in the scene (right panel). But maybe this is not enough?

#

Wait, fancyyy - it works :)) But how? Why is the object raycaster so important?

zealous quest
#

Ah yeah the script above looks like GridHelper is added to the scene instead of this.gameObject. The Scene is really the root of everything and the componets/hierarchy you load is put inside that

#

Sorry if the naming is confusing (SceneRoot being inside the scene not the scene itself)

#

You can name it however you want 🙂