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

Attempted import error: 'CSS3DObject/CSS3DRenderer' is not exported from 'three' (imported as 'THREE'). #16095

Closed
5ervant opened this issue Mar 29, 2019 · 1 comment

Comments

@5ervant
Copy link

5ervant commented Mar 29, 2019

I'm coding with React and Three.js, trying to embed a URL but the following code gives me an Attempted import error: 'CSS3DObject/CSS3DRenderer' is not exported from 'three' (imported as 'THREE'):

import * as THREE from 'three';
import 'three/examples/js/renderers/CSS3DRenderer';
// ...

// create a CSS3DObject to display element
const cssObject = new THREE.CSS3DObject(element);
// synchronize cssObject position/rotation with object position/rotation
cssObject.position = object.position;
cssObject.rotation = object.rotation;
// resize cssObject to same size as object (plus a border)
const percentBorder = 0.05;
cssObject.scale.x /= (1 + percentBorder) * (elementWidth / planeWidth);
cssObject.scale.y /= (1 + percentBorder) * (elementWidth / planeWidth);
// ...

const rendererCSS = new THREE.CSS3DRenderer();

I even tried import 'three/examples/js/renderers/CSS3DRenderer'; and some other random stuffs. It seems that Three.js is not yet ready to be used as a 'node_module'?

'three/examples/jsm/renderers/CSS3DRenderer' and three/examples/jsm/objects/CSS3DObject doesn't even existing yet? And I'm glad that { OBJLoader } can be imported from 'three/examples/jsm/loaders/OBJLoader'.

How can I embed a URL using Three.js in React if the needed constructors couldn't be imported? Is there an official CSS3DObject and CSS3DRenderer modules for it, or any other alternative?

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 29, 2019

As mentioned at stackoverflow, CSS3DRenderer and CSS3DObject are no part of the core. Like most other code in the examples, they are also no modules so you can't just import them in your app. However, more and more classes are converted to modules (see jsm folder). So over the time, CSS3DRenderer and CSS3DObject will be available there.

For now, you have to convert them to modules by yourself or you use an npm package like three-css3drenderer. Be aware that these package are often not maintained so using them with the latest three.js version can lead to conflicts.

Related issue: #9562

@Mugen87 Mugen87 closed this as completed Mar 29, 2019
odys-z added a commit to odys-z/x-visual that referenced this issue Sep 28, 2020
It's seems the only way to use new function like EXR or HDR.
The problem is r110 is the latest npm version.
see:
https://stackoverflow.com/questions/55208134/why-am-i-getting-the-error-css3dobject-is-not-exported-from-three/55208449#55208449
mrdoob/three.js#16095

even Three.js Fundamental uses r119. There is no WebGLCubeRenderTarget
in r110.
odys-z added a commit to odys-z/x-visual that referenced this issue Sep 28, 2020
It's seems the only way to use new function like EXR or HDR.
The problem is r110 is the latest npm version.
see:
https://stackoverflow.com/questions/55208134/why-am-i-getting-the-error-css3dobject-is-not-exported-from-three/55208449#55208449

mrdoob/three.js#16095

even Three.js Fundamental uses r119. There is no WebGLCubeRenderTarget
in r110:

https://threejsfundamentals.org/threejs/lessons/threejs-backgrounds.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants