Skip to content
Snippets Groups Projects
Unverified Commit 1e7e32fb authored by Robert Long's avatar Robert Long Committed by GitHub
Browse files

New gltf-model component with caching WIP (#24)

parent 35df9bf0
No related branches found
No related tags found
No related merge requests found
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<script id="head-template" type="text/html"> <script id="head-template" type="text/html">
<a-entity <a-entity
class="head" class="head"
gltf-model="#bot-head-mesh" gltf-model2="#bot-head-mesh"
networked-audio-source networked-audio-source
networked-audio-analyser networked-audio-analyser
matcolor-audio-feedback="objectName: Head_Mesh" matcolor-audio-feedback="objectName: Head_Mesh"
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
<script id="body-template" type="text/html"> <script id="body-template" type="text/html">
<a-entity <a-entity
class="body" class="body"
gltf-model="#bot-body-mesh" gltf-model2="#bot-body-mesh"
personal-space-invader personal-space-invader
rotation="0 180 0" rotation="0 180 0"
position="0 -0.05 0" position="0 -0.05 0"
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
<script id="left-hand-template" type="text/html"> <script id="left-hand-template" type="text/html">
<a-entity <a-entity
class="hand" class="hand"
gltf-model="#bot-left-hand-mesh" gltf-model2="#bot-left-hand-mesh"
animation-mixer animation-mixer
personal-space-invader personal-space-invader
rotation="-90 90 0" rotation="-90 90 0"
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
<script id="right-hand-template" type="text/html"> <script id="right-hand-template" type="text/html">
<a-entity <a-entity
class="hand" class="hand"
gltf-model="#bot-right-hand-mesh" gltf-model2="#bot-right-hand-mesh"
personal-space-invader personal-space-invader
rotation="-90 -90 0" rotation="-90 -90 0"
position="0 0 0.075" position="0 0 0.075"
...@@ -144,7 +144,7 @@ ...@@ -144,7 +144,7 @@
> >
<a-entity <a-entity
id="watch" id="watch"
gltf-model="assets/hud/watch.gltf" gltf-model2="assets/hud/watch.gltf"
position="0 0.0015 0.147" position="0 0.0015 0.147"
rotation="3.5 0 0" rotation="3.5 0 0"
> >
...@@ -175,17 +175,17 @@ ...@@ -175,17 +175,17 @@
<!-- Environment --> <!-- Environment -->
<a-entity <a-entity
gltf-model="#meeting-space1-mesh" gltf-model2="#meeting-space1-mesh"
position="0 0 0" position="0 0 0"
></a-entity> ></a-entity>
<a-entity <a-entity
gltf-model="#outdoor-facade-mesh" gltf-model2="#outdoor-facade-mesh"
position="0 0 0" position="0 0 0"
></a-entity> ></a-entity>
<a-entity <a-entity
gltf-model="#floor-nav-mesh" gltf-model2="#floor-nav-mesh"
visible="false" visible="false"
position="0 0 0" position="0 0 0"
></a-entity> ></a-entity>
......
import "../vendor/GLTFLoader";
const GLTFCache = {};
/**
* glTF model loader.
*/
AFRAME.registerComponent("gltf-model2", {
schema: { type: "model" },
init: function() {
this.model = null;
this.loader = new THREE.GLTFLoader();
this.onLoad = this.onLoad.bind(this);
this.onError = this.onError.bind(this);
},
update: function() {
const self = this;
const el = this.el;
const src = this.data;
if (!src) {
return;
}
const cachedModel = GLTFCache[src];
if (cachedModel) {
this.model = cachedModel.clone(true);
this.model.visible = true;
this.model.animations = cachedModel.animations;
this.el.setObject3D("mesh", this.model);
this.el.emit("model-loaded", { format: "gltf", model: this.model });
}
this.remove();
this.loader.load(
src,
this.onLoad,
undefined /* onProgress */,
this.onError
);
},
onLoad(gltfModel) {
this.model = gltfModel.scene || gltfModel.scenes[0];
this.model.animations = gltfModel.animations;
GLTFCache[this.data] = this.model;
this.el.setObject3D("mesh", this.model);
this.el.emit("model-loaded", { format: "gltf", model: this.model });
},
onError(error) {
const message =
error && error.message ? error.message : "Failed to load glTF model";
console.warn(message);
this.el.emit("model-error", { format: "gltf", src: this.data });
},
remove: function() {
if (!this.model) {
return;
}
this.el.removeObject3D("mesh");
}
});
...@@ -22,6 +22,7 @@ import "./components/character-controller"; ...@@ -22,6 +22,7 @@ import "./components/character-controller";
import "./components/split-axis-events"; import "./components/split-axis-events";
import "./components/networked-video-player"; import "./components/networked-video-player";
import "./components/offset-relative-to"; import "./components/offset-relative-to";
import "./components/gltf-model2";
import "./systems/personal-space-bubble"; import "./systems/personal-space-bubble";
import registerNetworkScheams from "./network-schemas"; import registerNetworkScheams from "./network-schemas";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment