From c844684c95922799ddec00d8472865dcdf77de27 Mon Sep 17 00:00:00 2001 From: ochafik Date: Tue, 24 Dec 2024 04:47:52 +0000 Subject: [PATCH] Tweak lighting of glb outputs --- src/io/export_glb.ts | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/io/export_glb.ts b/src/io/export_glb.ts index 62f6d70..66a60f3 100644 --- a/src/io/export_glb.ts +++ b/src/io/export_glb.ts @@ -15,6 +15,8 @@ function createPrimitive(doc: Document, baseColorFactor: Color, {positions, indi doc.createMaterial() .setDoubleSided(true) .setAlphaMode(baseColorFactor[3] < 1 ? 'BLEND' : 'OPAQUE') + .setMetallicFactor(0.0) + .setRoughnessFactor(0.8) .setBaseColorFactor(baseColorFactor)) .setAttribute('POSITION', doc.createAccessor() @@ -71,23 +73,37 @@ function getGeom(data: IndexedPolyhedron): Geom { export async function exportGlb(data: IndexedPolyhedron, defaultColor: Color = DEFAULT_FACE_COLOR): Promise { const doc = new Document(); const lightExt = doc.createExtension(KHRLightsPunctual); - const buffer = doc.createBuffer(); + doc.createBuffer(); const scene = doc.createScene() .addChild(doc.createNode() - .setExtension('KHR_lights_punctual', lightExt - .createLight() - .setType(LightDef.Type.DIRECTIONAL) - .setIntensity(8.0) - .setColor([1.0, 1.0, 1.0])) + .setExtension('KHR_lights_punctual', + lightExt.createLight() + .setType(LightDef.Type.DIRECTIONAL) + .setIntensity(3.0) + .setColor([1.0, 1.0, 1.0])) .setRotation([-0.3250576, -0.3250576, 0, 0.8880739])) .addChild(doc.createNode() - .setExtension('KHR_lights_punctual', lightExt - .createLight() - .setType(LightDef.Type.DIRECTIONAL) - .setIntensity(8.0) - .setColor([1.0, 1.0, 1.0])) - .setRotation([0.6279631, 0.6279631, 0, 0.4597009])); + .setExtension('KHR_lights_punctual', + lightExt.createLight() + .setType(LightDef.Type.DIRECTIONAL) + .setIntensity(2.0) + .setColor([0.9, 0.9, 1.0])) + .setRotation([0.6279631, 0.6279631, 0, 0.4597009])) + .addChild(doc.createNode() + .setExtension('KHR_lights_punctual', + lightExt.createLight() + .setType(LightDef.Type.DIRECTIONAL) + .setIntensity(1.0) + .setColor([1.0, 1.0, 1.0])) + .setRotation([0.7071068, 0, 0, 0.7071068])) + .addChild(doc.createNode() + .setExtension('KHR_lights_punctual', + lightExt.createLight() + .setType(LightDef.Type.DIRECTIONAL) + .setIntensity(0.5) + .setColor([0.8, 0.8, 0.8])) + .setRotation([-0.7071068, 0, 0, 0.7071068])); const mesh = doc.createMesh();