Skip to content

Commit afb40d6

Browse files
authored
Fix Trace Colors (#4)
* fix trace colors * make usb port a bit darker * fix material indexing
1 parent 549100a commit afb40d6

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

lib/converters/board-renderer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export async function renderBoardLayer(
2222
backgroundColor,
2323
drawPaddingOutsideBoard: false,
2424
colorOverrides: {
25+
soldermask: {
26+
top: "#4CAF50",
27+
bottom: "#4CAF50",
28+
},
2529
copper: {
2630
top: copperColor,
2731
bottom: copperColor,

lib/gltf/gltf-builder.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export class GLTFBuilder {
6868
const defaultMaterialIndex = this.addMaterial({
6969
name: "Default",
7070
pbrMetallicRoughness: {
71-
baseColorFactor: [0.5, 0.5, 0.5, 0.5],
72-
metallicFactor: 0.1,
73-
roughnessFactor: 0.8,
71+
baseColorFactor: [0.35, 0.35, 0.35, 0.5],
72+
metallicFactor: 0.05,
73+
roughnessFactor: 0.95,
7474
},
7575
alphaMode: "BLEND",
7676
})
@@ -140,27 +140,28 @@ export class GLTFBuilder {
140140
const dissolve = objMaterial.dissolve ?? 1.0
141141
const alpha = 1.0 - dissolve
142142

143-
let baseColor: [number, number, number, number] = [0.5, 0.5, 0.5, alpha]
143+
let baseColor: [number, number, number, number] = [0.3, 0.3, 0.3, alpha]
144144

145145
if (objMaterial.color) {
146146
const color = typeof objMaterial.color === "string"
147147
? this.parseColorString(objMaterial.color)
148148
: [objMaterial.color[0] / 255, objMaterial.color[1] / 255, objMaterial.color[2] / 255, alpha]
149-
baseColor = color
150-
baseColor[3] = alpha
149+
baseColor = [color[0]!, color[1]!, color[2]!, alpha]
151150
}
152151

153152
const gltfMaterialIndex = this.addMaterial({
154153
name: `OBJ_${name}`,
155154
pbrMetallicRoughness: {
156155
baseColorFactor: baseColor,
157-
metallicFactor: 0.1,
158-
roughnessFactor: 0.8,
156+
metallicFactor: 0.05,
157+
roughnessFactor: 0.95,
159158
},
160159
alphaMode: alpha < 1.0 ? "BLEND" : "OPAQUE",
161160
})
162161

163-
objMaterialIndices.set(parseInt(name), gltfMaterialIndex)
162+
// Get the correct material index from the OBJ parsing
163+
const materialIndex = objMesh.materialIndexMap?.get(name) ?? -1
164+
objMaterialIndices.set(materialIndex, gltfMaterialIndex)
164165
}
165166

166167
// Create primitives for each material group
@@ -517,8 +518,8 @@ export class GLTFBuilder {
517518
name: `Material_${this.materials.length}`,
518519
pbrMetallicRoughness: {
519520
baseColorFactor: baseColor,
520-
metallicFactor: 0.1,
521-
roughnessFactor: 0.8,
521+
metallicFactor: 0.05,
522+
roughnessFactor: 0.95,
522523
},
523524
alphaMode: makeTransparent ? "BLEND" : "OPAQUE",
524525
})

lib/loaders/obj.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ function parseOBJ(text: string, transform?: CoordinateTransformConfig): OBJMesh
190190
triangles: transformedTriangles,
191191
boundingBox: calculateBoundingBox(transformedTriangles),
192192
materials: materials.size > 0 ? materials : undefined,
193+
materialIndexMap: materials.size > 0 ? materialIndexMap : undefined,
193194
}
194195
}
195196

lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface STLMesh {
6161

6262
export interface OBJMesh extends STLMesh {
6363
materials?: Map<string, OBJMaterial>
64+
materialIndexMap?: Map<string, number>
6465
}
6566

6667
export interface OBJMaterial {

0 commit comments

Comments
 (0)