How do I modify the Orbit Controls scripts?

Hi! I’m trying to modify some of the values in the .ts and .js scripts, so that the Orbit Controls work like the Map Controls example (three.js examples), which is basically just that, a modified Orbit Controls script (three.js/examples/misc_controls_map.html at master · mrdoob/three.js · GitHub). However, the values are not applying when I test the scene, since the CS component keeps its original default values instead of the new ones and there are some variables that I need to modify that are not available in the component, but I’m not allowed to modify the component’s script itself to add them. Any tips?

Original Post on Discord

by user 239022618240483330

Hello, there are a few ways to do that with different pros and cons.

one way to go about it would be to just copy the script/component and create your own version based on that.

Another one would be by adding a new c# script and implement AdditionalComonentData - with that you can inject new settings in OrbitControls on Export. In the typescript side you can replace or wrap the methods you want to change (or use the @prefix decorator attribute but thats a bit experimental at this point and undocumented)

Quick example, this is my own copy of the orbit script modified, not the best way to do things I’m sure but you can do what you want with it from here
OrbitControlsEpm.ts

by user 103054507105067008

For those who want the finished script, here it is:

by user 224464722878005248

MapControl.ts

by user 224464722878005248

And thanks to @ROBYER1 for your Script because the original OrbitControl on Needle can’t disable Rotation.
But I need the OrbitControl to use the LookAtConstraint so it better like it

But what is the “Look at constraint 01” with the float number ?

by user 224464722878005248

Hi all… sorry to bother you with such a basic query but I’m very inexperienced with Unity and I’m hoping you can steer me in the right direction.

The above solutions seem to be exactly what I’m looking for (at least I’m pretty certain they are) but despite spending a couple of days trying to ascertain what I might need to do with them I’ve still no idea how to implement either of the brilliant scripts that you ( @ROBYER1 and @AeistDesmos ) have so kindly provided.

I’m very happy to learn, so any kind of pointers (a screenshot… or anything like that… indicating where I might need to put stuff) would be very gratefully received… and feverishly studied :sweat_smile: … at this end.

I hope you or someone can help… but I’ll totally understand if there isn’t time to do so if this is too much of a newbie question :slightly_smiling_face:

by user 908977119781060648

Hey @frannie :beer: sorry for the late reply. You should be able to just copy paste the scripts from above in a new typescript file in src/scripts for example, a unity component should automatically generate which you can then add to your camera in unity (you might to need restart the server if its running)

I hope i understand your question right. Here is a very short video about scripting https://youtu.be/uf5UK0bLHlY

Awesome… huge thanks for this @marcel :cactus:. I’ll have a good try at it :slightly_smiling_face: :+1:

by user 908977119781060648

Okay so that all works… kinda…

The good news: the ObitControlsEpm.ts is absolutely perfect for what I was hoping to achieve and I can run things exactly as expected locally.
The bad news: I don’t seem to be able to compile the script when it comes to building a production version of the project.

What I see is this…

by user 908977119781060648

That means that typescript is not installed. Can you try running npm install typescript -g (it will install typescript globally for npm)

Will do… two minutes…

by user 908977119781060648

Sorry for the delay… I can’t get it to work, so I tried lots of refreshes/reboots etc. No joy :anguished:

by user 908977119781060648

I now see this…

by user 908977119781060648

Ah I think threejs changed their orbit controls and enableKeys doesnt exist anymore. You need to remove this line (98 i think)

this._controls.enableKeys = this.enableKeys; < this is wrong

Oooooo, right… I’ll give that a go…

by user 908977119781060648

Sadly no luck. Now when I run ‘Needle Engine > Export and Build Dist (Production)’ I no longer get the ‘failed to compile script’ notification, but the resultant build just displays the loading bar followed by an empty black screen.

The console shows this…

by user 908977119781060648

Can you send me the project? I’ll take a look
image.png