Spaces:
Running
Running
Update viewer.js
Browse files
viewer.js
CHANGED
|
@@ -80,58 +80,27 @@ export async function initializeViewer(config, instanceId) {
|
|
| 80 |
window.pc = pc;
|
| 81 |
}
|
| 82 |
|
| 83 |
-
|
| 84 |
-
deviceTypes: ["webgl2"],
|
| 85 |
-
glslangUrl: "https://playcanvas.vercel.app/static/lib/glslang/glslang.js",
|
| 86 |
-
twgslUrl: "https://playcanvas.vercel.app/static/lib/twgsl/twgsl.js",
|
| 87 |
-
antialias: false
|
| 88 |
-
});
|
| 89 |
-
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2);
|
| 90 |
-
|
| 91 |
-
const opts = new pc.AppOptions();
|
| 92 |
-
opts.graphicsDevice = device;
|
| 93 |
-
opts.mouse = new pc.Mouse(document.body);
|
| 94 |
-
opts.touch = new pc.TouchDevice(document.body);
|
| 95 |
-
opts.componentSystems = [
|
| 96 |
-
pc.RenderComponentSystem,
|
| 97 |
-
pc.CameraComponentSystem,
|
| 98 |
-
pc.LightComponentSystem,
|
| 99 |
-
pc.ScriptComponentSystem,
|
| 100 |
-
pc.GSplatComponentSystem,
|
| 101 |
-
pc.CollisionComponentSystem,
|
| 102 |
-
pc.RigidbodyComponentSystem
|
| 103 |
-
];
|
| 104 |
-
opts.resourceHandlers = [
|
| 105 |
-
pc.TextureHandler,
|
| 106 |
-
pc.ContainerHandler,
|
| 107 |
-
pc.ScriptHandler,
|
| 108 |
-
pc.GSplatHandler
|
| 109 |
-
];
|
| 110 |
-
|
| 111 |
-
app = new pc.Application(canvas, opts);
|
| 112 |
-
app.setCanvasFillMode(pc.FILLMODE_NONE);
|
| 113 |
-
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
| 114 |
-
|
| 115 |
-
resizeObserver = new ResizeObserver(entries => {
|
| 116 |
-
entries.forEach(entry => {
|
| 117 |
-
app.resizeCanvas(entry.contentRect.width, entry.contentRect.height);
|
| 118 |
-
});
|
| 119 |
-
});
|
| 120 |
-
resizeObserver.observe(viewerContainer);
|
| 121 |
-
|
| 122 |
-
window.addEventListener('resize', () => app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight));
|
| 123 |
-
app.on('destroy', () => resizeObserver.disconnect());
|
| 124 |
-
|
| 125 |
const assets = {
|
| 126 |
model: new pc.Asset('gsplat', 'gsplat', { url: plyUrl }),
|
| 127 |
orbit: new pc.Asset('script', 'script', { url: "https://mikafil-viewer-gs.static.hf.space/orbit-camera.js" }),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
};
|
| 129 |
|
| 130 |
-
const loader = new pc.AssetListLoader(Object.values(assets), app.assets);
|
| 131 |
loader.load(() => {
|
| 132 |
app.start();
|
| 133 |
progressDialog.style.display = 'none';
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
modelEntity = new pc.Entity('model');
|
| 136 |
modelEntity.addComponent('gsplat', { asset: assets.model });
|
| 137 |
modelEntity.setLocalPosition(modelX, modelY, modelZ);
|
|
|
|
| 80 |
window.pc = pc;
|
| 81 |
}
|
| 82 |
|
| 83 |
+
// --- HDR asset is now included ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
const assets = {
|
| 85 |
model: new pc.Asset('gsplat', 'gsplat', { url: plyUrl }),
|
| 86 |
orbit: new pc.Asset('script', 'script', { url: "https://mikafil-viewer-gs.static.hf.space/orbit-camera.js" }),
|
| 87 |
+
hdr: new pc.Asset(
|
| 88 |
+
'hdr', 'texture',
|
| 89 |
+
{ url: "https://huggingface.co/datasets/bilca/ply_files/resolve/main/galeries/blanc.png" },
|
| 90 |
+
{ type: pc.TEXTURETYPE_RGBP, mipmaps: false }
|
| 91 |
+
),
|
| 92 |
};
|
| 93 |
|
| 94 |
+
const loader = new pc.AssetListLoader(Object.values(assets), app ? app.assets : []);
|
| 95 |
loader.load(() => {
|
| 96 |
app.start();
|
| 97 |
progressDialog.style.display = 'none';
|
| 98 |
|
| 99 |
+
// --- Apply HDR environment if available ---
|
| 100 |
+
if (assets.hdr && assets.hdr.resource) {
|
| 101 |
+
app.scene.envAtlas = assets.hdr.resource;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
modelEntity = new pc.Entity('model');
|
| 105 |
modelEntity.addComponent('gsplat', { asset: assets.model });
|
| 106 |
modelEntity.setLocalPosition(modelX, modelY, modelZ);
|