mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-08-11 19:59:01 +08:00
Update to our THREE.js example: DracoModule is now instantiated in
DRACOLoader class using closure to prevent multiple instantiations.
This commit is contained in:
parent
127484be47
commit
0a9c9c7b8b
@ -39,32 +39,45 @@ THREE.DRACOLoader.prototype = {
|
||||
this.path = value;
|
||||
},
|
||||
|
||||
decodeDracoFile: function(rawBuffer) {
|
||||
const scope = this;
|
||||
/*
|
||||
* Here is how to use Draco Javascript decoder and get the geometry.
|
||||
*/
|
||||
const buffer = new dracoDecoder.DecoderBuffer();
|
||||
buffer.Init(new Int8Array(rawBuffer), rawBuffer.byteLength);
|
||||
const wrapper = new dracoDecoder.WebIDLWrapper();
|
||||
decodeDracoFile: ( function() {
|
||||
let dracoDecoder;
|
||||
|
||||
/*
|
||||
* Determine what type is this file: mesh or point cloud.
|
||||
*/
|
||||
const geometryType = wrapper.GetEncodedGeometryType(buffer);
|
||||
if (geometryType == dracoDecoder.TRIANGULAR_MESH) {
|
||||
fileDisplayArea.innerText = "Loaded a mesh.\n";
|
||||
} else if (geometryType == dracoDecoder.POINT_CLOUD) {
|
||||
fileDisplayArea.innerText = "Loaded a point cloud.\n";
|
||||
if (typeof DracoModule === 'function') {
|
||||
dracoDecoder = DracoModule();
|
||||
} else {
|
||||
const errorMsg = "Error: Unknown geometry type.";
|
||||
fileDisplayArea.innerText = errorMsg;
|
||||
throw new Error(errorMsg);
|
||||
console.error('THREE.DRACOLoader: DracoModule not found.');
|
||||
return;
|
||||
}
|
||||
return scope.convertDracoGeometryTo3JS(wrapper, geometryType, buffer);
|
||||
},
|
||||
|
||||
convertDracoGeometryTo3JS: function(wrapper, geometryType, buffer) {
|
||||
return function(rawBuffer) {
|
||||
const scope = this;
|
||||
/*
|
||||
* Here is how to use Draco Javascript decoder and get the geometry.
|
||||
*/
|
||||
const buffer = new dracoDecoder.DecoderBuffer();
|
||||
buffer.Init(new Int8Array(rawBuffer), rawBuffer.byteLength);
|
||||
const wrapper = new dracoDecoder.WebIDLWrapper();
|
||||
|
||||
/*
|
||||
* Determine what type is this file: mesh or point cloud.
|
||||
*/
|
||||
const geometryType = wrapper.GetEncodedGeometryType(buffer);
|
||||
if (geometryType == dracoDecoder.TRIANGULAR_MESH) {
|
||||
fileDisplayArea.innerText = "Loaded a mesh.\n";
|
||||
} else if (geometryType == dracoDecoder.POINT_CLOUD) {
|
||||
fileDisplayArea.innerText = "Loaded a point cloud.\n";
|
||||
} else {
|
||||
const errorMsg = "Error: Unknown geometry type.";
|
||||
fileDisplayArea.innerText = errorMsg;
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
return scope.convertDracoGeometryTo3JS(wrapper, geometryType, buffer,
|
||||
dracoDecoder);
|
||||
}
|
||||
} )(),
|
||||
|
||||
convertDracoGeometryTo3JS: function(wrapper, geometryType, buffer,
|
||||
dracoDecoder) {
|
||||
let dracoGeometry;
|
||||
const start_time = performance.now();
|
||||
if (geometryType == dracoDecoder.TRIANGULAR_MESH) {
|
||||
|
@ -47,8 +47,6 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const dracoDecoder = DracoModule();
|
||||
|
||||
let container;
|
||||
let camera, cameraTarget, scene, renderer;
|
||||
let mouseX = 0, mouseY = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user