Spaces:
Running
Running
Update viewer.js
Browse files
viewer.js
CHANGED
|
@@ -11,7 +11,7 @@ let viewerInitialized = false;
|
|
| 11 |
let resizeObserver = null;
|
| 12 |
|
| 13 |
// These will hold references to the material(s) you want to update.
|
| 14 |
-
let
|
| 15 |
let matTransparent = null;
|
| 16 |
let tubeEmit = null;
|
| 17 |
|
|
@@ -210,50 +210,36 @@ export async function initializeViewer(config, instanceId) {
|
|
| 210 |
|
| 211 |
|
| 212 |
//the 2 materials for the main model :
|
| 213 |
-
|
| 214 |
const ao = assets.ao_map.resource;
|
| 215 |
const op = assets.op_map.resource;
|
| 216 |
const thickness = assets.thickness_map.resource;
|
| 217 |
-
matOpaque.blendType = pc.BLEND_NORMAL;
|
| 218 |
-
matOpaque.diffuse = new pc.Color(0.7, 0.05, 0.05);
|
| 219 |
-
matOpaque.specular = new pc.Color(0.01, 0.01, 0.01);
|
| 220 |
-
matOpaque.shininess = 90;
|
| 221 |
-
matOpaque.gloss = 1;
|
| 222 |
-
matOpaque.metalness = 0.0;
|
| 223 |
-
matOpaque.useMetalness = true;
|
| 224 |
-
matOpaque.useDynamicRefraction = true;
|
| 225 |
-
matOpaque.refraction= 0.8;
|
| 226 |
-
matOpaque.refractionIndex = 1;
|
| 227 |
-
matOpaque.thickness = 30;
|
| 228 |
-
matOpaque.thicknessMap = thickness;
|
| 229 |
-
matOpaque.opacityMap = op;
|
| 230 |
-
matOpaque.opacityMapChannel = "r";
|
| 231 |
-
matOpaque.opacity = 0.9;
|
| 232 |
-
matOpaque.emissive = new pc.Color(0.372, 0.03, 0.003);
|
| 233 |
-
matOpaque.emissiveMap = ao;
|
| 234 |
-
matOpaque.emissiveIntensity = 0.1;
|
| 235 |
-
matOpaque.update();
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
/*matTransparent = new pc.StandardMaterial();
|
| 239 |
-
matTransparent.diffuse.set(1, 1, 1, 1);
|
| 240 |
matTransparent.blendType = pc.BLEND_NORMAL;
|
| 241 |
-
matTransparent.
|
| 242 |
-
matTransparent.
|
| 243 |
-
matTransparent.
|
| 244 |
-
matTransparent.
|
| 245 |
-
matTransparent.
|
| 246 |
-
matTransparent.
|
| 247 |
-
matTransparent.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
//material for the tube
|
| 250 |
tubeEmit = new pc.StandardMaterial();
|
| 251 |
tubeEmit.emissive = new pc.Color(1, 1, 1);
|
| 252 |
tubeEmit.emissiveIntensity = 2;
|
| 253 |
-
//tubeEmit.blendType = pc.BLEND_NORMAL;
|
| 254 |
-
//tubeEmit.useDynamicRefraction = false;
|
| 255 |
-
//tubeEmit.depthWrite = false;
|
| 256 |
-
//tubeEmit.thickness = 0.2;
|
| 257 |
tubeEmit.opacity = 0.8;
|
| 258 |
tubeEmit.update()
|
| 259 |
|
|
@@ -261,7 +247,7 @@ export async function initializeViewer(config, instanceId) {
|
|
| 261 |
traverse(modelEntity, node => {
|
| 262 |
if (node.render && node.render.meshInstances) {
|
| 263 |
for (let mi of node.render.meshInstances) {
|
| 264 |
-
mi.material =
|
| 265 |
}
|
| 266 |
}
|
| 267 |
});
|
|
@@ -417,11 +403,11 @@ export function resetViewerCamera() {
|
|
| 417 |
* r,g,b are floats [0,1]. This is a reusable function for new colors.
|
| 418 |
*/
|
| 419 |
export function changeColor(dr, dg, db, a, er, eg, eb) {
|
| 420 |
-
// Wait until
|
| 421 |
-
if (!
|
| 422 |
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
}
|
|
|
|
| 11 |
let resizeObserver = null;
|
| 12 |
|
| 13 |
// These will hold references to the material(s) you want to update.
|
| 14 |
+
let matTransparent = null;
|
| 15 |
let matTransparent = null;
|
| 16 |
let tubeEmit = null;
|
| 17 |
|
|
|
|
| 210 |
|
| 211 |
|
| 212 |
//the 2 materials for the main model :
|
| 213 |
+
matTransparent = new pc.StandardMaterial();
|
| 214 |
const ao = assets.ao_map.resource;
|
| 215 |
const op = assets.op_map.resource;
|
| 216 |
const thickness = assets.thickness_map.resource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
matTransparent.blendType = pc.BLEND_NORMAL;
|
| 218 |
+
matTransparent.diffuse = new pc.Color(0.7, 0.05, 0.05);
|
| 219 |
+
matTransparent.specular = new pc.Color(0.01, 0.01, 0.01);
|
| 220 |
+
matTransparent.shininess = 90;
|
| 221 |
+
matTransparent.gloss = 1;
|
| 222 |
+
matTransparent.metalness = 0.0;
|
| 223 |
+
matTransparent.useMetalness = true;
|
| 224 |
+
matTransparent.useDynamicRefraction = true;
|
| 225 |
+
matTransparent.refraction= 0.8;
|
| 226 |
+
matTransparent.refractionIndex = 1;
|
| 227 |
+
matTransparent.thickness = 30;
|
| 228 |
+
matTransparent.thicknessMap = thickness;
|
| 229 |
+
matTransparent.opacityMap = op;
|
| 230 |
+
matTransparent.opacityMapChannel = "r";
|
| 231 |
+
matTransparent.opacity = 0.9;
|
| 232 |
+
matTransparent.emissive = new pc.Color(0.372, 0.03, 0.003);
|
| 233 |
+
matTransparent.emissiveMap = ao;
|
| 234 |
+
matTransparent.emissiveIntensity = 0.1;
|
| 235 |
+
matTransparent.update();
|
| 236 |
+
|
| 237 |
+
|
| 238 |
|
| 239 |
//material for the tube
|
| 240 |
tubeEmit = new pc.StandardMaterial();
|
| 241 |
tubeEmit.emissive = new pc.Color(1, 1, 1);
|
| 242 |
tubeEmit.emissiveIntensity = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
tubeEmit.opacity = 0.8;
|
| 244 |
tubeEmit.update()
|
| 245 |
|
|
|
|
| 247 |
traverse(modelEntity, node => {
|
| 248 |
if (node.render && node.render.meshInstances) {
|
| 249 |
for (let mi of node.render.meshInstances) {
|
| 250 |
+
mi.material = matTransparent;
|
| 251 |
}
|
| 252 |
}
|
| 253 |
});
|
|
|
|
| 403 |
* r,g,b are floats [0,1]. This is a reusable function for new colors.
|
| 404 |
*/
|
| 405 |
export function changeColor(dr, dg, db, a, er, eg, eb) {
|
| 406 |
+
// Wait until matTransparent is loaded (null before model load).
|
| 407 |
+
if (!matTransparent) return;
|
| 408 |
|
| 409 |
+
matTransparent.diffuse.set(dr, dg, db);
|
| 410 |
+
matTransparent.emissive.set(er, eg, eb);
|
| 411 |
+
matTransparent.opacity = a;
|
| 412 |
+
matTransparent.update();
|
| 413 |
}
|