refactor: establish unified viewer workspaces
This commit is contained in:
@@ -62,6 +62,21 @@ async function getPLY(): Promise<PLYLoaderT> {
|
||||
return (_ply = new PLYLoader());
|
||||
}
|
||||
|
||||
function normalizePlyAttributes(geometry: THREE.BufferGeometry): void {
|
||||
for (const name of ['position', 'normal', 'uv', 'color']) {
|
||||
const attribute = geometry.getAttribute(name);
|
||||
if (!attribute || !(attribute.array instanceof Float64Array)) continue;
|
||||
geometry.setAttribute(
|
||||
name,
|
||||
new THREE.Float32BufferAttribute(
|
||||
new Float32Array(attribute.array),
|
||||
attribute.itemSize,
|
||||
attribute.normalized,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load any supported model URL and resolve to a scene-addable Object3D.
|
||||
* `nameHint` carries the real file name for ext detection when `url` is a
|
||||
@@ -165,7 +180,18 @@ export async function loadModel(
|
||||
case 'dae': {
|
||||
const loader = await getCollada();
|
||||
return new Promise<THREE.Object3D>((resolve, reject) => {
|
||||
loader.load(url, (result) => resolve(result.scene), onXhr, (err) => reject(err));
|
||||
loader.load(
|
||||
url,
|
||||
(result) => {
|
||||
if (!result) {
|
||||
reject(new Error('Collada loader returned no scene'));
|
||||
return;
|
||||
}
|
||||
resolve(result.scene);
|
||||
},
|
||||
onXhr,
|
||||
(err) => reject(err),
|
||||
);
|
||||
});
|
||||
}
|
||||
case 'ply': {
|
||||
@@ -174,6 +200,7 @@ export async function loadModel(
|
||||
loader.load(
|
||||
url,
|
||||
(geometry) => {
|
||||
normalizePlyAttributes(geometry);
|
||||
const hasColor = geometry.hasAttribute('color');
|
||||
if (geometry.index) {
|
||||
// Triangle mesh
|
||||
|
||||
Reference in New Issue
Block a user