Using Threejs + OrbitContols in TypeScript
I'm not able to get this example of using the aforementioned combo going in TypeScript.
I have <script src="lib/three.min.js"></script>
and <script src="lib/OrbitControls.js"></script>
in my html <head>
and the typescript file in <body>
:
/// <reference path="libthree.d.ts" />
...
this.controls = new THREE.OrbitControls(this.camera); //there's the error
this.controls.addEventListener('change', this.render);
...
and
this.controls.update();
in periodically called render()
function. For all I know, the setup is identical to the expample, but gives me a huge error (abbreviated) on compilation of the OrbitControls constructor line:
The property 'OrbitControls' does not exist on value of type '{REVISION:string;
CullFace: {[x: number ...
I guess there's whole Threejs in that error, since Visual Studio crashes the moment I click on it :). Thanks for your help.
javascript html three.js typescript
add a comment |
I'm not able to get this example of using the aforementioned combo going in TypeScript.
I have <script src="lib/three.min.js"></script>
and <script src="lib/OrbitControls.js"></script>
in my html <head>
and the typescript file in <body>
:
/// <reference path="libthree.d.ts" />
...
this.controls = new THREE.OrbitControls(this.camera); //there's the error
this.controls.addEventListener('change', this.render);
...
and
this.controls.update();
in periodically called render()
function. For all I know, the setup is identical to the expample, but gives me a huge error (abbreviated) on compilation of the OrbitControls constructor line:
The property 'OrbitControls' does not exist on value of type '{REVISION:string;
CullFace: {[x: number ...
I guess there's whole Threejs in that error, since Visual Studio crashes the moment I click on it :). Thanks for your help.
javascript html three.js typescript
add a comment |
I'm not able to get this example of using the aforementioned combo going in TypeScript.
I have <script src="lib/three.min.js"></script>
and <script src="lib/OrbitControls.js"></script>
in my html <head>
and the typescript file in <body>
:
/// <reference path="libthree.d.ts" />
...
this.controls = new THREE.OrbitControls(this.camera); //there's the error
this.controls.addEventListener('change', this.render);
...
and
this.controls.update();
in periodically called render()
function. For all I know, the setup is identical to the expample, but gives me a huge error (abbreviated) on compilation of the OrbitControls constructor line:
The property 'OrbitControls' does not exist on value of type '{REVISION:string;
CullFace: {[x: number ...
I guess there's whole Threejs in that error, since Visual Studio crashes the moment I click on it :). Thanks for your help.
javascript html three.js typescript
I'm not able to get this example of using the aforementioned combo going in TypeScript.
I have <script src="lib/three.min.js"></script>
and <script src="lib/OrbitControls.js"></script>
in my html <head>
and the typescript file in <body>
:
/// <reference path="libthree.d.ts" />
...
this.controls = new THREE.OrbitControls(this.camera); //there's the error
this.controls.addEventListener('change', this.render);
...
and
this.controls.update();
in periodically called render()
function. For all I know, the setup is identical to the expample, but gives me a huge error (abbreviated) on compilation of the OrbitControls constructor line:
The property 'OrbitControls' does not exist on value of type '{REVISION:string;
CullFace: {[x: number ...
I guess there's whole Threejs in that error, since Visual Studio crashes the moment I click on it :). Thanks for your help.
javascript html three.js typescript
javascript html three.js typescript
edited Oct 19 '13 at 13:57
asdf
asked Oct 18 '13 at 8:05
asdfasdf
289312
289312
add a comment |
add a comment |
11 Answers
11
active
oldest
votes
After few hours spend on this problem, I ended up creating a new package: three-orbitcontrols-ts
import * as THREE from 'three';
import OrbitControls from 'three-orbitcontrols-ts';
const controls = new OrbitControls(camera, renderer.domElement);
1
you are a very good soul! thanks mate!
– messerbill
Feb 21 '17 at 18:40
Has anyone found something like this but for the trackball controls?
– Pablo Kvitca
Jul 23 '18 at 20:04
Great work, but now we have another package to get out of sync. For instance, this package is already missing thesaveState
routine which is used by some other components I am using.
– user9315861
Jul 31 '18 at 18:46
add a comment |
Importing the OrbitControls directly from the source file after importing THREE worked great for me (without using the three-orbitcontrols-ts
package):
import * as THREE from 'three';
import 'three/examples/js/controls/OrbitControls';
Using only the three
and @types/three
packages
looks like this post this should be marked as correct answer instead.
– daniel.bavrin
Sep 15 '17 at 19:10
The problem is that after the first importTHREE
is an imported object, not a property on the window object asthree/examples/js/controls/OrbitControls
expects in order to install itself.
– user9315861
Jul 22 '18 at 11:43
add a comment |
While previous answers may work out to some degree, you should go with the ready made definition files from DefinitelyTyped. They also define OrbitControl
's properties and methods.
1
the link is broken
– smartmeta
Mar 5 '17 at 11:21
Sorry, here is the updated link: github.com/DefinitelyTyped/DefinitelyTyped/blob/master/three/…
– BenR
Mar 6 '17 at 12:31
2
@BenR The updated link is broken again :(
– N15M0_jk
Sep 8 '17 at 8:42
This does not answer the question of how to bring in OrbitControls themselves.
– user9315861
Jul 31 '18 at 18:45
add a comment |
Feeling kind of silly since the solution (or workaround at least) turns out to be quite simple...
Just declare the OrbitControls
variable:
declare var THREE.OrbitControls: any; // even "declare var THREE.OrbitControls;" will do the trick
There are still some compilation errors but it works.
add a comment |
I tried some of the suggested solutions and could not get it to work right so after some experimentation, I ended up with:
import * as THREE from 'three';
import OrbitControlsLibrary = require('three-orbit-controls');
var OrbitControls = OrbitControlsLibrary(THREE);
...
this.controls = new OrbitControls(this.camera);
I am using webpack bundling and with this I did not have to add the script tag in the HTML template.
add a comment |
Unfortunately none of above answers solved problem for me. I have found solution without installing third party packages by creating three.js
file with below content:
import * as THREE from 'three';
window.THREE = THREE;
require('three/examples/js/controls/OrbitControls');
export default THREE;
and then import THREE from './three'
;
add a comment |
The answer didn't work for me in eclipse typescript, since it conflicted with the reference statement earlier. But the following works:
declare module THREE export var OrbitControls
add a comment |
After adding the three-orbitcontrols typings and three-orbit-controls npm package (why aren't these named the same?), I was still having issues getting it to work in Typescript. This ended up working for me in case it's helpful for anyone else who doesn't want to use the workaround:
import * as three from 'three';
three.OrbitControls = require('three-orbit-controls')(three);
let camera = new three.PerspectiveCamera(75, aspectRatio, 1, 1000);
let renderer = new three.WebGLRenderer();
let controls = new three.OrbitControls(camera, renderer.domElement);
As of today, it seems that the OrbitControls npm package is using an old style of exports that requires an old-style require statement that passes in the Three library.
add a comment |
outside ts:
var THREEa = THREE;
inside ts:
var controls = new THREEa.OrbitControls(pCamera, pContainer);
add a comment |
I was not able to get anything from here this post actually worked and seemed consistent or had enough detail to be actionable. Hopefully, this answer might provide some insight to others.
In my objects I already had three working by using typings to extract the THREE ts file. This was very reasonable and put the ts file in typings/globals/three.
Here are the steps assuming that you have downloaded and installed node.js. This also installs npm (Node Project Manager) which you can run from a command prompt to so all the steps below.
npm install typings --global
typings install dt~three --global --save
At this point all the basic THREE types are available once I "include" the ts file in my object:
/// <reference path="typings/globals/three/index.d.ts" />
At this point OrbitControls is not defined because the basic three package does not include it. However, there is ts data in the typings database. So I installed it as well:
typings install --globals three-orbitcontrols --save
It puts the ts file here:
node_modulesthree-orbitcontrols-tsdistindex.d.ts
I tried a number of things to get it to work but I am missing something. Generally the error was that THREE.OrbitControls was not defined. If I removed the THREE then it generated non-working JavaScript.
What I finally did which I consider a workaround is edit typings/globals/three/index.d.ts and cut and pasted the contents of typings/globals/three/OrbitControls/index.d.ts into the THREE namespace at the end.
At the top of the OrbitControls/index.d.ts it calls out <reference types="three" />
which doesn't work because in that context it cannot find "three". Once I worked around that it compiled but it generated non-working code.
add a comment |
I've also had some bad luck implementing the suggested solutions as none of them made the typescript compiler happy. Couldn't overwrite THREE.OrbitControls at compile time because it was set to read-only. My solution was as follows:
Install both 'three' and 'three-orbit-controls' with npm. (This is kinda dumb but necessary since 'three' already contains all the code for the orbit controls in the examples/js/controls/OrbitControl.js file but doesn't export it in a way that typescript understands. If you don't want to mess with your 3rd party libraries, just install 'three-orbit-controls' alongside 'three' which contains a duplicate of the code but exports it in a nice way.
Now use it like below:
import * as THREE from 'three';
import * as OrbitControlsFunction from 'three-orbit-controls';
const OrbitControls = OrbitControlsFunction(THREE); // OrbitControls is now your constructor
const controls: THREE.OrbitControls = new OrbitControls(camera, element); // Code as you would from here on out.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19444592%2fusing-threejs-orbitcontols-in-typescript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
11 Answers
11
active
oldest
votes
11 Answers
11
active
oldest
votes
active
oldest
votes
active
oldest
votes
After few hours spend on this problem, I ended up creating a new package: three-orbitcontrols-ts
import * as THREE from 'three';
import OrbitControls from 'three-orbitcontrols-ts';
const controls = new OrbitControls(camera, renderer.domElement);
1
you are a very good soul! thanks mate!
– messerbill
Feb 21 '17 at 18:40
Has anyone found something like this but for the trackball controls?
– Pablo Kvitca
Jul 23 '18 at 20:04
Great work, but now we have another package to get out of sync. For instance, this package is already missing thesaveState
routine which is used by some other components I am using.
– user9315861
Jul 31 '18 at 18:46
add a comment |
After few hours spend on this problem, I ended up creating a new package: three-orbitcontrols-ts
import * as THREE from 'three';
import OrbitControls from 'three-orbitcontrols-ts';
const controls = new OrbitControls(camera, renderer.domElement);
1
you are a very good soul! thanks mate!
– messerbill
Feb 21 '17 at 18:40
Has anyone found something like this but for the trackball controls?
– Pablo Kvitca
Jul 23 '18 at 20:04
Great work, but now we have another package to get out of sync. For instance, this package is already missing thesaveState
routine which is used by some other components I am using.
– user9315861
Jul 31 '18 at 18:46
add a comment |
After few hours spend on this problem, I ended up creating a new package: three-orbitcontrols-ts
import * as THREE from 'three';
import OrbitControls from 'three-orbitcontrols-ts';
const controls = new OrbitControls(camera, renderer.domElement);
After few hours spend on this problem, I ended up creating a new package: three-orbitcontrols-ts
import * as THREE from 'three';
import OrbitControls from 'three-orbitcontrols-ts';
const controls = new OrbitControls(camera, renderer.domElement);
answered Jan 7 '17 at 10:34
nicolaspanelnicolaspanel
492716
492716
1
you are a very good soul! thanks mate!
– messerbill
Feb 21 '17 at 18:40
Has anyone found something like this but for the trackball controls?
– Pablo Kvitca
Jul 23 '18 at 20:04
Great work, but now we have another package to get out of sync. For instance, this package is already missing thesaveState
routine which is used by some other components I am using.
– user9315861
Jul 31 '18 at 18:46
add a comment |
1
you are a very good soul! thanks mate!
– messerbill
Feb 21 '17 at 18:40
Has anyone found something like this but for the trackball controls?
– Pablo Kvitca
Jul 23 '18 at 20:04
Great work, but now we have another package to get out of sync. For instance, this package is already missing thesaveState
routine which is used by some other components I am using.
– user9315861
Jul 31 '18 at 18:46
1
1
you are a very good soul! thanks mate!
– messerbill
Feb 21 '17 at 18:40
you are a very good soul! thanks mate!
– messerbill
Feb 21 '17 at 18:40
Has anyone found something like this but for the trackball controls?
– Pablo Kvitca
Jul 23 '18 at 20:04
Has anyone found something like this but for the trackball controls?
– Pablo Kvitca
Jul 23 '18 at 20:04
Great work, but now we have another package to get out of sync. For instance, this package is already missing the
saveState
routine which is used by some other components I am using.– user9315861
Jul 31 '18 at 18:46
Great work, but now we have another package to get out of sync. For instance, this package is already missing the
saveState
routine which is used by some other components I am using.– user9315861
Jul 31 '18 at 18:46
add a comment |
Importing the OrbitControls directly from the source file after importing THREE worked great for me (without using the three-orbitcontrols-ts
package):
import * as THREE from 'three';
import 'three/examples/js/controls/OrbitControls';
Using only the three
and @types/three
packages
looks like this post this should be marked as correct answer instead.
– daniel.bavrin
Sep 15 '17 at 19:10
The problem is that after the first importTHREE
is an imported object, not a property on the window object asthree/examples/js/controls/OrbitControls
expects in order to install itself.
– user9315861
Jul 22 '18 at 11:43
add a comment |
Importing the OrbitControls directly from the source file after importing THREE worked great for me (without using the three-orbitcontrols-ts
package):
import * as THREE from 'three';
import 'three/examples/js/controls/OrbitControls';
Using only the three
and @types/three
packages
looks like this post this should be marked as correct answer instead.
– daniel.bavrin
Sep 15 '17 at 19:10
The problem is that after the first importTHREE
is an imported object, not a property on the window object asthree/examples/js/controls/OrbitControls
expects in order to install itself.
– user9315861
Jul 22 '18 at 11:43
add a comment |
Importing the OrbitControls directly from the source file after importing THREE worked great for me (without using the three-orbitcontrols-ts
package):
import * as THREE from 'three';
import 'three/examples/js/controls/OrbitControls';
Using only the three
and @types/three
packages
Importing the OrbitControls directly from the source file after importing THREE worked great for me (without using the three-orbitcontrols-ts
package):
import * as THREE from 'three';
import 'three/examples/js/controls/OrbitControls';
Using only the three
and @types/three
packages
answered Feb 23 '17 at 19:04
sporshsporsh
28933
28933
looks like this post this should be marked as correct answer instead.
– daniel.bavrin
Sep 15 '17 at 19:10
The problem is that after the first importTHREE
is an imported object, not a property on the window object asthree/examples/js/controls/OrbitControls
expects in order to install itself.
– user9315861
Jul 22 '18 at 11:43
add a comment |
looks like this post this should be marked as correct answer instead.
– daniel.bavrin
Sep 15 '17 at 19:10
The problem is that after the first importTHREE
is an imported object, not a property on the window object asthree/examples/js/controls/OrbitControls
expects in order to install itself.
– user9315861
Jul 22 '18 at 11:43
looks like this post this should be marked as correct answer instead.
– daniel.bavrin
Sep 15 '17 at 19:10
looks like this post this should be marked as correct answer instead.
– daniel.bavrin
Sep 15 '17 at 19:10
The problem is that after the first import
THREE
is an imported object, not a property on the window object as three/examples/js/controls/OrbitControls
expects in order to install itself.– user9315861
Jul 22 '18 at 11:43
The problem is that after the first import
THREE
is an imported object, not a property on the window object as three/examples/js/controls/OrbitControls
expects in order to install itself.– user9315861
Jul 22 '18 at 11:43
add a comment |
While previous answers may work out to some degree, you should go with the ready made definition files from DefinitelyTyped. They also define OrbitControl
's properties and methods.
1
the link is broken
– smartmeta
Mar 5 '17 at 11:21
Sorry, here is the updated link: github.com/DefinitelyTyped/DefinitelyTyped/blob/master/three/…
– BenR
Mar 6 '17 at 12:31
2
@BenR The updated link is broken again :(
– N15M0_jk
Sep 8 '17 at 8:42
This does not answer the question of how to bring in OrbitControls themselves.
– user9315861
Jul 31 '18 at 18:45
add a comment |
While previous answers may work out to some degree, you should go with the ready made definition files from DefinitelyTyped. They also define OrbitControl
's properties and methods.
1
the link is broken
– smartmeta
Mar 5 '17 at 11:21
Sorry, here is the updated link: github.com/DefinitelyTyped/DefinitelyTyped/blob/master/three/…
– BenR
Mar 6 '17 at 12:31
2
@BenR The updated link is broken again :(
– N15M0_jk
Sep 8 '17 at 8:42
This does not answer the question of how to bring in OrbitControls themselves.
– user9315861
Jul 31 '18 at 18:45
add a comment |
While previous answers may work out to some degree, you should go with the ready made definition files from DefinitelyTyped. They also define OrbitControl
's properties and methods.
While previous answers may work out to some degree, you should go with the ready made definition files from DefinitelyTyped. They also define OrbitControl
's properties and methods.
edited Mar 7 '17 at 9:08
answered Dec 2 '14 at 4:48
BenRBenR
275210
275210
1
the link is broken
– smartmeta
Mar 5 '17 at 11:21
Sorry, here is the updated link: github.com/DefinitelyTyped/DefinitelyTyped/blob/master/three/…
– BenR
Mar 6 '17 at 12:31
2
@BenR The updated link is broken again :(
– N15M0_jk
Sep 8 '17 at 8:42
This does not answer the question of how to bring in OrbitControls themselves.
– user9315861
Jul 31 '18 at 18:45
add a comment |
1
the link is broken
– smartmeta
Mar 5 '17 at 11:21
Sorry, here is the updated link: github.com/DefinitelyTyped/DefinitelyTyped/blob/master/three/…
– BenR
Mar 6 '17 at 12:31
2
@BenR The updated link is broken again :(
– N15M0_jk
Sep 8 '17 at 8:42
This does not answer the question of how to bring in OrbitControls themselves.
– user9315861
Jul 31 '18 at 18:45
1
1
the link is broken
– smartmeta
Mar 5 '17 at 11:21
the link is broken
– smartmeta
Mar 5 '17 at 11:21
Sorry, here is the updated link: github.com/DefinitelyTyped/DefinitelyTyped/blob/master/three/…
– BenR
Mar 6 '17 at 12:31
Sorry, here is the updated link: github.com/DefinitelyTyped/DefinitelyTyped/blob/master/three/…
– BenR
Mar 6 '17 at 12:31
2
2
@BenR The updated link is broken again :(
– N15M0_jk
Sep 8 '17 at 8:42
@BenR The updated link is broken again :(
– N15M0_jk
Sep 8 '17 at 8:42
This does not answer the question of how to bring in OrbitControls themselves.
– user9315861
Jul 31 '18 at 18:45
This does not answer the question of how to bring in OrbitControls themselves.
– user9315861
Jul 31 '18 at 18:45
add a comment |
Feeling kind of silly since the solution (or workaround at least) turns out to be quite simple...
Just declare the OrbitControls
variable:
declare var THREE.OrbitControls: any; // even "declare var THREE.OrbitControls;" will do the trick
There are still some compilation errors but it works.
add a comment |
Feeling kind of silly since the solution (or workaround at least) turns out to be quite simple...
Just declare the OrbitControls
variable:
declare var THREE.OrbitControls: any; // even "declare var THREE.OrbitControls;" will do the trick
There are still some compilation errors but it works.
add a comment |
Feeling kind of silly since the solution (or workaround at least) turns out to be quite simple...
Just declare the OrbitControls
variable:
declare var THREE.OrbitControls: any; // even "declare var THREE.OrbitControls;" will do the trick
There are still some compilation errors but it works.
Feeling kind of silly since the solution (or workaround at least) turns out to be quite simple...
Just declare the OrbitControls
variable:
declare var THREE.OrbitControls: any; // even "declare var THREE.OrbitControls;" will do the trick
There are still some compilation errors but it works.
edited Oct 21 '13 at 13:09
answered Oct 21 '13 at 9:22
asdfasdf
289312
289312
add a comment |
add a comment |
I tried some of the suggested solutions and could not get it to work right so after some experimentation, I ended up with:
import * as THREE from 'three';
import OrbitControlsLibrary = require('three-orbit-controls');
var OrbitControls = OrbitControlsLibrary(THREE);
...
this.controls = new OrbitControls(this.camera);
I am using webpack bundling and with this I did not have to add the script tag in the HTML template.
add a comment |
I tried some of the suggested solutions and could not get it to work right so after some experimentation, I ended up with:
import * as THREE from 'three';
import OrbitControlsLibrary = require('three-orbit-controls');
var OrbitControls = OrbitControlsLibrary(THREE);
...
this.controls = new OrbitControls(this.camera);
I am using webpack bundling and with this I did not have to add the script tag in the HTML template.
add a comment |
I tried some of the suggested solutions and could not get it to work right so after some experimentation, I ended up with:
import * as THREE from 'three';
import OrbitControlsLibrary = require('three-orbit-controls');
var OrbitControls = OrbitControlsLibrary(THREE);
...
this.controls = new OrbitControls(this.camera);
I am using webpack bundling and with this I did not have to add the script tag in the HTML template.
I tried some of the suggested solutions and could not get it to work right so after some experimentation, I ended up with:
import * as THREE from 'three';
import OrbitControlsLibrary = require('three-orbit-controls');
var OrbitControls = OrbitControlsLibrary(THREE);
...
this.controls = new OrbitControls(this.camera);
I am using webpack bundling and with this I did not have to add the script tag in the HTML template.
answered Dec 22 '16 at 21:29
Aaron BotelerAaron Boteler
7114
7114
add a comment |
add a comment |
Unfortunately none of above answers solved problem for me. I have found solution without installing third party packages by creating three.js
file with below content:
import * as THREE from 'three';
window.THREE = THREE;
require('three/examples/js/controls/OrbitControls');
export default THREE;
and then import THREE from './three'
;
add a comment |
Unfortunately none of above answers solved problem for me. I have found solution without installing third party packages by creating three.js
file with below content:
import * as THREE from 'three';
window.THREE = THREE;
require('three/examples/js/controls/OrbitControls');
export default THREE;
and then import THREE from './three'
;
add a comment |
Unfortunately none of above answers solved problem for me. I have found solution without installing third party packages by creating three.js
file with below content:
import * as THREE from 'three';
window.THREE = THREE;
require('three/examples/js/controls/OrbitControls');
export default THREE;
and then import THREE from './three'
;
Unfortunately none of above answers solved problem for me. I have found solution without installing third party packages by creating three.js
file with below content:
import * as THREE from 'three';
window.THREE = THREE;
require('three/examples/js/controls/OrbitControls');
export default THREE;
and then import THREE from './three'
;
answered Oct 6 '18 at 23:04
mtxmtx
304519
304519
add a comment |
add a comment |
The answer didn't work for me in eclipse typescript, since it conflicted with the reference statement earlier. But the following works:
declare module THREE export var OrbitControls
add a comment |
The answer didn't work for me in eclipse typescript, since it conflicted with the reference statement earlier. But the following works:
declare module THREE export var OrbitControls
add a comment |
The answer didn't work for me in eclipse typescript, since it conflicted with the reference statement earlier. But the following works:
declare module THREE export var OrbitControls
The answer didn't work for me in eclipse typescript, since it conflicted with the reference statement earlier. But the following works:
declare module THREE export var OrbitControls
answered Feb 11 '14 at 5:16
DejayDejay
31
31
add a comment |
add a comment |
After adding the three-orbitcontrols typings and three-orbit-controls npm package (why aren't these named the same?), I was still having issues getting it to work in Typescript. This ended up working for me in case it's helpful for anyone else who doesn't want to use the workaround:
import * as three from 'three';
three.OrbitControls = require('three-orbit-controls')(three);
let camera = new three.PerspectiveCamera(75, aspectRatio, 1, 1000);
let renderer = new three.WebGLRenderer();
let controls = new three.OrbitControls(camera, renderer.domElement);
As of today, it seems that the OrbitControls npm package is using an old style of exports that requires an old-style require statement that passes in the Three library.
add a comment |
After adding the three-orbitcontrols typings and three-orbit-controls npm package (why aren't these named the same?), I was still having issues getting it to work in Typescript. This ended up working for me in case it's helpful for anyone else who doesn't want to use the workaround:
import * as three from 'three';
three.OrbitControls = require('three-orbit-controls')(three);
let camera = new three.PerspectiveCamera(75, aspectRatio, 1, 1000);
let renderer = new three.WebGLRenderer();
let controls = new three.OrbitControls(camera, renderer.domElement);
As of today, it seems that the OrbitControls npm package is using an old style of exports that requires an old-style require statement that passes in the Three library.
add a comment |
After adding the three-orbitcontrols typings and three-orbit-controls npm package (why aren't these named the same?), I was still having issues getting it to work in Typescript. This ended up working for me in case it's helpful for anyone else who doesn't want to use the workaround:
import * as three from 'three';
three.OrbitControls = require('three-orbit-controls')(three);
let camera = new three.PerspectiveCamera(75, aspectRatio, 1, 1000);
let renderer = new three.WebGLRenderer();
let controls = new three.OrbitControls(camera, renderer.domElement);
As of today, it seems that the OrbitControls npm package is using an old style of exports that requires an old-style require statement that passes in the Three library.
After adding the three-orbitcontrols typings and three-orbit-controls npm package (why aren't these named the same?), I was still having issues getting it to work in Typescript. This ended up working for me in case it's helpful for anyone else who doesn't want to use the workaround:
import * as three from 'three';
three.OrbitControls = require('three-orbit-controls')(three);
let camera = new three.PerspectiveCamera(75, aspectRatio, 1, 1000);
let renderer = new three.WebGLRenderer();
let controls = new three.OrbitControls(camera, renderer.domElement);
As of today, it seems that the OrbitControls npm package is using an old style of exports that requires an old-style require statement that passes in the Three library.
answered Jul 13 '16 at 22:02
DaveDave
2,5461921
2,5461921
add a comment |
add a comment |
outside ts:
var THREEa = THREE;
inside ts:
var controls = new THREEa.OrbitControls(pCamera, pContainer);
add a comment |
outside ts:
var THREEa = THREE;
inside ts:
var controls = new THREEa.OrbitControls(pCamera, pContainer);
add a comment |
outside ts:
var THREEa = THREE;
inside ts:
var controls = new THREEa.OrbitControls(pCamera, pContainer);
outside ts:
var THREEa = THREE;
inside ts:
var controls = new THREEa.OrbitControls(pCamera, pContainer);
answered Jan 8 '17 at 14:00
Lior TrauLior Trau
381213
381213
add a comment |
add a comment |
I was not able to get anything from here this post actually worked and seemed consistent or had enough detail to be actionable. Hopefully, this answer might provide some insight to others.
In my objects I already had three working by using typings to extract the THREE ts file. This was very reasonable and put the ts file in typings/globals/three.
Here are the steps assuming that you have downloaded and installed node.js. This also installs npm (Node Project Manager) which you can run from a command prompt to so all the steps below.
npm install typings --global
typings install dt~three --global --save
At this point all the basic THREE types are available once I "include" the ts file in my object:
/// <reference path="typings/globals/three/index.d.ts" />
At this point OrbitControls is not defined because the basic three package does not include it. However, there is ts data in the typings database. So I installed it as well:
typings install --globals three-orbitcontrols --save
It puts the ts file here:
node_modulesthree-orbitcontrols-tsdistindex.d.ts
I tried a number of things to get it to work but I am missing something. Generally the error was that THREE.OrbitControls was not defined. If I removed the THREE then it generated non-working JavaScript.
What I finally did which I consider a workaround is edit typings/globals/three/index.d.ts and cut and pasted the contents of typings/globals/three/OrbitControls/index.d.ts into the THREE namespace at the end.
At the top of the OrbitControls/index.d.ts it calls out <reference types="three" />
which doesn't work because in that context it cannot find "three". Once I worked around that it compiled but it generated non-working code.
add a comment |
I was not able to get anything from here this post actually worked and seemed consistent or had enough detail to be actionable. Hopefully, this answer might provide some insight to others.
In my objects I already had three working by using typings to extract the THREE ts file. This was very reasonable and put the ts file in typings/globals/three.
Here are the steps assuming that you have downloaded and installed node.js. This also installs npm (Node Project Manager) which you can run from a command prompt to so all the steps below.
npm install typings --global
typings install dt~three --global --save
At this point all the basic THREE types are available once I "include" the ts file in my object:
/// <reference path="typings/globals/three/index.d.ts" />
At this point OrbitControls is not defined because the basic three package does not include it. However, there is ts data in the typings database. So I installed it as well:
typings install --globals three-orbitcontrols --save
It puts the ts file here:
node_modulesthree-orbitcontrols-tsdistindex.d.ts
I tried a number of things to get it to work but I am missing something. Generally the error was that THREE.OrbitControls was not defined. If I removed the THREE then it generated non-working JavaScript.
What I finally did which I consider a workaround is edit typings/globals/three/index.d.ts and cut and pasted the contents of typings/globals/three/OrbitControls/index.d.ts into the THREE namespace at the end.
At the top of the OrbitControls/index.d.ts it calls out <reference types="three" />
which doesn't work because in that context it cannot find "three". Once I worked around that it compiled but it generated non-working code.
add a comment |
I was not able to get anything from here this post actually worked and seemed consistent or had enough detail to be actionable. Hopefully, this answer might provide some insight to others.
In my objects I already had three working by using typings to extract the THREE ts file. This was very reasonable and put the ts file in typings/globals/three.
Here are the steps assuming that you have downloaded and installed node.js. This also installs npm (Node Project Manager) which you can run from a command prompt to so all the steps below.
npm install typings --global
typings install dt~three --global --save
At this point all the basic THREE types are available once I "include" the ts file in my object:
/// <reference path="typings/globals/three/index.d.ts" />
At this point OrbitControls is not defined because the basic three package does not include it. However, there is ts data in the typings database. So I installed it as well:
typings install --globals three-orbitcontrols --save
It puts the ts file here:
node_modulesthree-orbitcontrols-tsdistindex.d.ts
I tried a number of things to get it to work but I am missing something. Generally the error was that THREE.OrbitControls was not defined. If I removed the THREE then it generated non-working JavaScript.
What I finally did which I consider a workaround is edit typings/globals/three/index.d.ts and cut and pasted the contents of typings/globals/three/OrbitControls/index.d.ts into the THREE namespace at the end.
At the top of the OrbitControls/index.d.ts it calls out <reference types="three" />
which doesn't work because in that context it cannot find "three". Once I worked around that it compiled but it generated non-working code.
I was not able to get anything from here this post actually worked and seemed consistent or had enough detail to be actionable. Hopefully, this answer might provide some insight to others.
In my objects I already had three working by using typings to extract the THREE ts file. This was very reasonable and put the ts file in typings/globals/three.
Here are the steps assuming that you have downloaded and installed node.js. This also installs npm (Node Project Manager) which you can run from a command prompt to so all the steps below.
npm install typings --global
typings install dt~three --global --save
At this point all the basic THREE types are available once I "include" the ts file in my object:
/// <reference path="typings/globals/three/index.d.ts" />
At this point OrbitControls is not defined because the basic three package does not include it. However, there is ts data in the typings database. So I installed it as well:
typings install --globals three-orbitcontrols --save
It puts the ts file here:
node_modulesthree-orbitcontrols-tsdistindex.d.ts
I tried a number of things to get it to work but I am missing something. Generally the error was that THREE.OrbitControls was not defined. If I removed the THREE then it generated non-working JavaScript.
What I finally did which I consider a workaround is edit typings/globals/three/index.d.ts and cut and pasted the contents of typings/globals/three/OrbitControls/index.d.ts into the THREE namespace at the end.
At the top of the OrbitControls/index.d.ts it calls out <reference types="three" />
which doesn't work because in that context it cannot find "three". Once I worked around that it compiled but it generated non-working code.
answered May 17 '17 at 19:00
Ken CowsiwinKen Cowsiwin
84
84
add a comment |
add a comment |
I've also had some bad luck implementing the suggested solutions as none of them made the typescript compiler happy. Couldn't overwrite THREE.OrbitControls at compile time because it was set to read-only. My solution was as follows:
Install both 'three' and 'three-orbit-controls' with npm. (This is kinda dumb but necessary since 'three' already contains all the code for the orbit controls in the examples/js/controls/OrbitControl.js file but doesn't export it in a way that typescript understands. If you don't want to mess with your 3rd party libraries, just install 'three-orbit-controls' alongside 'three' which contains a duplicate of the code but exports it in a nice way.
Now use it like below:
import * as THREE from 'three';
import * as OrbitControlsFunction from 'three-orbit-controls';
const OrbitControls = OrbitControlsFunction(THREE); // OrbitControls is now your constructor
const controls: THREE.OrbitControls = new OrbitControls(camera, element); // Code as you would from here on out.
add a comment |
I've also had some bad luck implementing the suggested solutions as none of them made the typescript compiler happy. Couldn't overwrite THREE.OrbitControls at compile time because it was set to read-only. My solution was as follows:
Install both 'three' and 'three-orbit-controls' with npm. (This is kinda dumb but necessary since 'three' already contains all the code for the orbit controls in the examples/js/controls/OrbitControl.js file but doesn't export it in a way that typescript understands. If you don't want to mess with your 3rd party libraries, just install 'three-orbit-controls' alongside 'three' which contains a duplicate of the code but exports it in a nice way.
Now use it like below:
import * as THREE from 'three';
import * as OrbitControlsFunction from 'three-orbit-controls';
const OrbitControls = OrbitControlsFunction(THREE); // OrbitControls is now your constructor
const controls: THREE.OrbitControls = new OrbitControls(camera, element); // Code as you would from here on out.
add a comment |
I've also had some bad luck implementing the suggested solutions as none of them made the typescript compiler happy. Couldn't overwrite THREE.OrbitControls at compile time because it was set to read-only. My solution was as follows:
Install both 'three' and 'three-orbit-controls' with npm. (This is kinda dumb but necessary since 'three' already contains all the code for the orbit controls in the examples/js/controls/OrbitControl.js file but doesn't export it in a way that typescript understands. If you don't want to mess with your 3rd party libraries, just install 'three-orbit-controls' alongside 'three' which contains a duplicate of the code but exports it in a nice way.
Now use it like below:
import * as THREE from 'three';
import * as OrbitControlsFunction from 'three-orbit-controls';
const OrbitControls = OrbitControlsFunction(THREE); // OrbitControls is now your constructor
const controls: THREE.OrbitControls = new OrbitControls(camera, element); // Code as you would from here on out.
I've also had some bad luck implementing the suggested solutions as none of them made the typescript compiler happy. Couldn't overwrite THREE.OrbitControls at compile time because it was set to read-only. My solution was as follows:
Install both 'three' and 'three-orbit-controls' with npm. (This is kinda dumb but necessary since 'three' already contains all the code for the orbit controls in the examples/js/controls/OrbitControl.js file but doesn't export it in a way that typescript understands. If you don't want to mess with your 3rd party libraries, just install 'three-orbit-controls' alongside 'three' which contains a duplicate of the code but exports it in a nice way.
Now use it like below:
import * as THREE from 'three';
import * as OrbitControlsFunction from 'three-orbit-controls';
const OrbitControls = OrbitControlsFunction(THREE); // OrbitControls is now your constructor
const controls: THREE.OrbitControls = new OrbitControls(camera, element); // Code as you would from here on out.
answered Nov 12 '18 at 17:05
Stephen VerbistStephen Verbist
16016
16016
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19444592%2fusing-threejs-orbitcontols-in-typescript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown