Skip to content

Commit

Permalink
Tweak lighting of glb outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Dec 24, 2024
1 parent 8f51167 commit c844684
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/io/export_glb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -71,23 +73,37 @@ function getGeom(data: IndexedPolyhedron): Geom {
export async function exportGlb(data: IndexedPolyhedron, defaultColor: Color = DEFAULT_FACE_COLOR): Promise<Blob> {
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();

Expand Down

0 comments on commit c844684

Please sign in to comment.