-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add Teapot example that uses the new ES module bundle with importmap #5645
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
Changes from 5 commits
af8a6ac
f115d02
3da06dd
b8c90f2
6b02a87
570f93e
92617bc
6ec33cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>Teapot • A-Frame</title> | ||
| <meta name="description" content="Teapot • A-Frame" /> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "aframe": "../../../dist/aframe-master.module.min.js", | ||
| "three": "https://cdn.jsdelivr.net/npm/super-three@0.172.0/build/three.module.js", | ||
| "three/addons/": "https://cdn.jsdelivr.net/npm/super-three@0.172.0/examples/jsm/", | ||
| "aframe-extras/controls": "https://cdn.jsdelivr.net/gh/c-frame/aframe-extras@7.5.x/dist/aframe-extras.controls.min.js" | ||
| } | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| // We use an importmap to load three as a module to avoid the warning "Multiple instances of Three.js being imported." | ||
| import AFRAME from "aframe"; | ||
| // AFRAME and THREE variables are available globally, the imported aframe-master.module.min.js bundle basically does: | ||
| // import * as THREE from "three" | ||
| // window.THREE = THREE | ||
| import "aframe-extras/controls"; // This uses the THREE global variable in the bundle. | ||
| import { Mesh, MeshStandardMaterial } from "three"; // This uses the same three instance. | ||
| import { TeapotGeometry } from "three/addons/geometries/TeapotGeometry.js"; // This uses the same three instance. | ||
|
|
||
| AFRAME.registerComponent("teapot", { | ||
| init() { | ||
| this.geometry = new TeapotGeometry(); | ||
| const mesh = new Mesh(); | ||
| mesh.geometry = this.geometry; | ||
| // Default material if not defined on the entity. | ||
| if (!this.el.getAttribute("material")) { | ||
| mesh.material = new MeshStandardMaterial({ | ||
| color: Math.random() * 0xffffff, | ||
| metalness: 0, | ||
| roughness: 0.5, | ||
| side: THREE.DoubleSide, | ||
| }); | ||
| } | ||
| this.el.setObject3D("mesh", mesh); | ||
| }, | ||
| remove() { | ||
| this.geometry.dispose(); | ||
| }, | ||
| }); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <a-scene background="color: #ECECEC"> | ||
| <a-cylinder | ||
| position="0 0.25 -2" | ||
| radius="0.5" | ||
| height="0.5" | ||
| color="#FFC65D" | ||
| > | ||
| <a-entity | ||
| teapot | ||
| position="0 0.48 0" | ||
| scale="0.005 0.005 0.005" | ||
| material="color: #713f12; roughness: 0.5; side: double" | ||
| ></a-entity> | ||
| </a-cylinder> | ||
|
|
||
| <a-plane | ||
| position="0 0 -2" | ||
| rotation="-90 0 0" | ||
| width="4" | ||
| height="4" | ||
| color="#7BC8A4" | ||
| ></a-plane> | ||
|
|
||
| <a-entity | ||
| position="0 0 1" | ||
| id="rig" | ||
| movement-controls="controls: gamepad,keyboard,nipple" | ||
| nipple-controls="mode: static" | ||
| > | ||
| <a-entity camera position="0 1.6 0" look-controls></a-entity> | ||
| </a-entity> | ||
| </a-scene> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,6 +157,7 @@ <h2>Examples</h2> | |
| <li><a href="boilerplate/3d-model/">3D Model (glTF)</a></li> | ||
| <li><a href="mixed-reality/anchor/">Anchor (Mixed Reality)</a></li> | ||
| <li><a href="mixed-reality/real-world-meshing/">Real World Meshing (Mixed Reality)</a></li> | ||
| <li><a href="boilerplate/teapot/">Teapot (use importmap and import from three/addons)</a></li> | ||
|
||
| </ul> | ||
|
|
||
| <h2>Examples from Documentation</h2> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem is that will have to update this in the future since it’s locked to r172. Is it possible to have an example without a hardcoded version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be an option to tag the super-three versions with the A-Frame version they are used in, so you'd be able to use
super-three@aframe-1.7.0. For master we could consider pointing it tonode_modulesinstead of using a CDN? That way when checking out older revisions, runningnpm installensures that the right super-three version is referenced.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. pointing to node_modules sounds fine to me. trying to avoid small things that will eventually break and hard to keep track of over time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you see my changes to the release script? There is no need to update manually, the script will update the super-three version in examples and docs similar to the aframe version.
But indeed for master that should reference the current version in node_modules. I just added an additional directory path to the webpack dev server config, and the preghpages script rewrite the url with the cdn.