Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrbitControls #155

Open
burl21 opened this issue May 14, 2019 · 6 comments
Open

OrbitControls #155

burl21 opened this issue May 14, 2019 · 6 comments

Comments

@burl21
Copy link

burl21 commented May 14, 2019

Hi,
I’m trying to use this library.
When I try to init OrbitControls orbitControls = new OrbitControls(camera, div);
I have the following error:
com.google.gwt.core.client.JavaScriptException: (TypeError) : $wnd.THREE.OrbitControls is not a constructor

GWT 2.8.1

Any ideas?

@treblereel
Copy link
Owner

@burl21 let me check ....

@treblereel
Copy link
Owner

@burl21 have you annotated your class with @InjectJavaScriptFor(elements = OrbitControls.class)
?
OrbitControls is a class from extensions so it needs to be injected explicitly.

here is example

https://github.com/treblereel/three4g-demo/blob/master/src/main/java/org/treblereel/gwt/three4g/demo/client/local/examples/misc/MiscControlsOrbit.java

@burl21
Copy link
Author

burl21 commented May 15, 2019

Thank you so much for your answer @treblereel

I solved it by adding:
ScriptInjector.fromString(JavascriptTextResource.IMPL.getOrbitControls().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();

Looks like the annotations does not work.
@InjectJavaScriptFor(elements = OrbitControls.class)

👍

@treblereel
Copy link
Owner

@burl21
pretty strange, may i ask you to share your app ?
do you use maven ?

Thanks for your feedback !

@tugalsan
Copy link

Hello,

I have studied three4g library examples...
As burl21 suggested i solved this problem by adding a class to reach js files.

package org.treblereel.gwt.three4g.extensions.resources;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.ScriptInjector;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.TextResource;

public interface TK_3JSResourceUtils extends ClientBundle {

    TK_3JSResourceUtils IMPL = GWT.create(TK_3JSResourceUtils.class);

    public static void addLib(TextResource libText) {//EXAMPLE TK_3JSLibResource.IMPL.getOrbitControls()
        ScriptInjector.fromString(libText.getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
    }

    @Source("js/loaders/DRACOLoader.js")
    TextResource getDRACOLoader();

    @Source("js/loaders/GLTFLoader.js")
    TextResource getGLTFLoader();

    @Source("js/controls/OrbitControls.js")
    TextResource getOrbitControls();

    @Source("js/controls/TrackballControls.js")
    TextResource getTrackballControls();
}

and using it as this,

TK_3JSResourceUtils.addLib(TK_3JSResourceUtils.IMPL.getOrbitControls());
TK_3JSResourceUtils.addLib(TK_3JSResourceUtils.IMPL.getTrackballControls());
TK_3JSResourceUtils.addLib(TK_3JSResourceUtils.IMPL.getGLTFLoader());
TK_3JSResourceUtils.addLib(TK_3JSResourceUtils.IMPL.getDRACOLoader());

@treblereel
Copy link
Owner

@tugalsan thanks for workaround, i ll take a look right after my PTO next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants