Skip to content

Commit 6d87ac2

Browse files
azaleacolburnBrandonPacewicHunterBarclay
authored
[AARD-1777] Mirabuf Friction Parsing (#1096)
Co-authored-by: Brandon Pacewic <[email protected]> Co-authored-by: KyroVibe <[email protected]>
1 parent 37d677c commit 6d87ac2

File tree

12 files changed

+481
-445
lines changed

12 files changed

+481
-445
lines changed

exporter/SynthesisFusionAddin/Synthesis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def register_ui() -> None:
121121
work_panel,
122122
lambda *_: True, # TODO: Should be redone with various refactors.
123123
ShowAPSAuthCommand.ShowAPSAuthCommandCreatedHandler,
124-
description=f"APS",
124+
description=f"Login to your Autodesk account",
125125
command=True,
126126
)
127127

@@ -132,7 +132,7 @@ def register_ui() -> None:
132132
work_panel,
133133
lambda *_: True,
134134
ShowWebsiteCommand.ShowWebsiteCommandCreatedHandler,
135-
description=f"Website Test",
135+
description=f"Open our tutorials page",
136136
command=True,
137137
)
138138
gm.elements.append(websiteButton)

exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def readFromDesign(self) -> "ExporterOptions":
7070
attrJsonData = makeObjectFromJson(type(field.type), json.loads(attribute.value))
7171
setattr(self, field.name, attrJsonData)
7272

73+
self.visualQuality = TriangleMeshQualityOptions.LowQualityTriangleMesh
7374
return self
7475

7576
@logFailure

exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Components.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ def _ParseBRep(
188188
) -> None:
189189
meshManager = body.meshManager
190190
calc = meshManager.createMeshCalculator()
191-
calc.setQuality(options.visualQuality)
191+
# Disabling for now. We need the user to be able to adjust this, otherwise it gets locked
192+
# into whatever the default was at the time it first creates the export options.
193+
# calc.setQuality(options.visualQuality)
194+
calc.setQuality(adsk.fusion.TriangleMeshQualityOptions.LowQualityTriangleMesh)
195+
# calc.maxNormalDeviation = 3.14159 * (1.0 / 6.0)
196+
# calc.surfaceTolerance = 0.5
192197
mesh = calc.calculate()
193198

194199
fill_info(trimesh, body)

exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Materials.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,26 @@ def getMaterialAppearance(
207207

208208
properties = fusionAppearance.appearanceProperties
209209

210+
roughnessProp = properties.itemById("surface_roughness")
211+
if roughnessProp:
212+
appearance.roughness = roughnessProp.value
213+
210214
# Thank Liam for this.
211215
modelItem = properties.itemById("interior_model")
212216
if modelItem:
213217
matModelType = modelItem.value
214218
baseColor = None
215219

216220
if matModelType == 0:
221+
reflectanceProp = properties.itemById("opaque_f0")
222+
if reflectanceProp:
223+
appearance.metallic = reflectanceProp.value
217224
baseColor = properties.itemById("opaque_albedo").value
218225
if baseColor:
219226
baseColor.opacity = 255
220227
elif matModelType == 1:
221228
baseColor = properties.itemById("metal_f0").value
229+
appearance.metallic = 0.8
222230
if baseColor:
223231
baseColor.opacity = 255
224232
elif matModelType == 2:

exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def notify(self, args: adsk.core.CommandEventArgs) -> None:
301301

302302
processedFileName = gm.app.activeDocument.name.replace(" ", "_")
303303
if generalConfigTab.exportLocation == ExportLocation.DOWNLOAD:
304-
savepath = FileDialogConfig.saveFileDialog(defaultPath=exporterOptions.fileLocation)
304+
savepath = FileDialogConfig.saveFileDialog(defaultPath="~/Documents/")
305305

306306
if not savepath:
307307
# save was canceled

fission/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"lint:fix": "eslint . --ext ts,tsx --report-unused-disable-directives --fix",
1717
"prettier": "bun x prettier src --check || npx prettier src --check",
1818
"prettier:fix": "bun x prettier src --write || npx prettier src --write",
19-
"format": "(bun run prettier:fix && bun run lint:fix) || (npm run prettier:fix && npm run lint:fix)",
19+
"format": "bun run prettier:fix && bun run lint:fix || npm run prettier:fix && npm run lint:fix",
2020
"assetpack": "curl -o public/assetpack.zip https://synthesis.autodesk.com/Downloadables/assetpack.zip && tar -xf public/assetpack.zip -C public/",
2121
"playwright:install": "bun x playwright install || npx playwright install"
2222
},

fission/src/mirabuf/MirabufInstance.ts

Lines changed: 67 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ class MirabufInstance {
109109
}
110110

111111
public constructor(parser: MirabufParser, materialStyle?: MaterialStyle, progressHandle?: ProgressHandle) {
112-
if (parser.errors.some(x => x[0] >= ParseErrorSeverity.Unimportable)) {
112+
if (parser.errors.some(x => x[0] >= ParseErrorSeverity.Unimportable))
113113
throw new Error("Parser has significant errors...")
114-
}
115114

116115
this._mirabufParser = parser
117116
this._materials = new Map()
@@ -126,39 +125,32 @@ class MirabufInstance {
126125
}
127126

128127
/**
129-
* Parses all mirabuf appearances into ThreeJs materials.
128+
* Parses all mirabuf appearances into ThreeJS and Jolt materials.
130129
*/
131130
private LoadMaterials(materialStyle: MaterialStyle) {
132131
Object.entries(this._mirabufParser.assembly.data!.materials!.appearances!).forEach(
133132
([appearanceId, appearance]) => {
134-
let hex = 0xe32b50
135-
let opacity = 1.0
136-
if (appearance.albedo) {
137-
const { A, B, G, R } = appearance.albedo
138-
if (A && B && G && R) {
139-
hex = (A << 24) | (R << 16) | (G << 8) | B
140-
opacity = A / 255.0
141-
}
142-
}
143-
144-
let material: THREE.Material
145-
if (materialStyle == MaterialStyle.Regular) {
146-
material = new THREE.MeshPhongMaterial({
147-
color: hex,
148-
shininess: 0.0,
149-
shadowSide: THREE.DoubleSide,
150-
opacity: opacity,
151-
transparent: opacity < 1.0,
152-
})
153-
} else if (materialStyle == MaterialStyle.Normals) {
154-
material = new THREE.MeshNormalMaterial()
155-
} else if (materialStyle == MaterialStyle.Toon) {
156-
material = World.SceneRenderer.CreateToonMaterial(hex, 5)
157-
console.debug("Toon Material")
158-
}
159-
160-
World.SceneRenderer.SetupMaterial(material!)
161-
this._materials.set(appearanceId, material!)
133+
const { A, B, G, R } = appearance.albedo ?? {}
134+
const [hex, opacity] =
135+
A && B && G && R ? [(A << 24) | (R << 16) | (G << 8) | B, A / 255.0] : [0xe32b50, 1.0]
136+
137+
const material =
138+
materialStyle === MaterialStyle.Regular
139+
? new THREE.MeshStandardMaterial({
140+
// No specular?
141+
color: hex,
142+
roughness: appearance.roughness ?? 0.5,
143+
metalness: appearance.metallic ?? 0.0,
144+
shadowSide: THREE.DoubleSide,
145+
opacity: opacity,
146+
transparent: opacity < 1.0,
147+
})
148+
: materialStyle === MaterialStyle.Normals
149+
? new THREE.MeshNormalMaterial()
150+
: World.SceneRenderer.CreateToonMaterial(hex, 5)
151+
152+
World.SceneRenderer.SetupMaterial(material)
153+
this._materials.set(appearanceId, material)
162154
}
163155
)
164156
}
@@ -178,61 +170,52 @@ class MirabufInstance {
178170

179171
const batchMap = new Map<THREE.Material, Map<string, [mirabuf.IBody, Array<mirabuf.IPartInstance>]>>()
180172
const countMap = new Map<THREE.Material, BatchCounts>()
181-
182173
// Filter all instances by first material, then body
183-
for (const instance of Object.values(instances)) {
184-
const definition = assembly.data!.parts!.partDefinitions![instance.partDefinitionReference!]!
185-
const bodies = definition.bodies
186-
if (bodies) {
187-
for (const body of bodies) {
188-
if (!body) continue
189-
const mesh = body.triangleMesh
190-
if (
191-
mesh &&
192-
mesh.mesh &&
193-
mesh.mesh.verts &&
194-
mesh.mesh.normals &&
195-
mesh.mesh.uv &&
196-
mesh.mesh.indices
197-
) {
198-
const appearanceOverride = body.appearanceOverride
199-
const material: THREE.Material = WIREFRAME
200-
? new THREE.MeshStandardMaterial({ wireframe: true, color: 0x000000 })
201-
: appearanceOverride && this._materials.has(appearanceOverride)
202-
? this._materials.get(appearanceOverride)!
203-
: fillerMaterials[nextFillerMaterial++ % fillerMaterials.length]
204-
205-
let materialBodyMap = batchMap.get(material)
206-
if (!materialBodyMap) {
207-
materialBodyMap = new Map<string, [mirabuf.IBody, Array<mirabuf.IPartInstance>]>()
208-
batchMap.set(material, materialBodyMap)
209-
}
210-
211-
const partBodyGuid = this.GetPartBodyGuid(definition, body)
212-
let bodyInstances = materialBodyMap.get(partBodyGuid)
213-
if (!bodyInstances) {
214-
bodyInstances = [body, new Array<mirabuf.IPartInstance>()]
215-
materialBodyMap.set(partBodyGuid, bodyInstances)
216-
}
217-
bodyInstances[1].push(instance)
218-
219-
if (countMap.has(material)) {
220-
const count = countMap.get(material)!
221-
count.maxInstances += 1
222-
count.maxVertices += mesh.mesh.verts.length / 3
223-
count.maxIndices += mesh.mesh.indices.length
224-
} else {
225-
const count: BatchCounts = {
226-
maxInstances: 1,
227-
maxVertices: mesh.mesh.verts.length / 3,
228-
maxIndices: mesh.mesh.indices.length,
229-
}
230-
countMap.set(material, count)
231-
}
232-
}
174+
Object.values(instances).forEach(instance => {
175+
const definition = assembly.data!.parts!.partDefinitions![instance.partDefinitionReference!]
176+
const bodies = definition?.bodies ?? []
177+
bodies.forEach(body => {
178+
const mesh = body?.triangleMesh?.mesh
179+
if (!mesh?.verts || !mesh.normals || !mesh.uv || !mesh.indices) return
180+
181+
const appearanceOverride = body.appearanceOverride
182+
183+
const material = WIREFRAME
184+
? new THREE.MeshStandardMaterial({ wireframe: true, color: 0x000000 })
185+
: appearanceOverride && this._materials.has(appearanceOverride)
186+
? this._materials.get(appearanceOverride)!
187+
: fillerMaterials[nextFillerMaterial++ % fillerMaterials.length]
188+
189+
let materialBodyMap = batchMap.get(material)
190+
if (!materialBodyMap) {
191+
materialBodyMap = new Map<string, [mirabuf.IBody, Array<mirabuf.IPartInstance>]>()
192+
batchMap.set(material, materialBodyMap)
233193
}
234-
}
235-
}
194+
195+
const partBodyGuid = this.GetPartBodyGuid(definition, body)
196+
let bodyInstances = materialBodyMap.get(partBodyGuid)
197+
if (!bodyInstances) {
198+
bodyInstances = [body, new Array<mirabuf.IPartInstance>()]
199+
materialBodyMap.set(partBodyGuid, bodyInstances)
200+
}
201+
bodyInstances[1].push(instance)
202+
203+
if (countMap.has(material)) {
204+
const count = countMap.get(material)!
205+
count.maxInstances += 1
206+
count.maxVertices += mesh.verts.length / 3
207+
count.maxIndices += mesh.indices.length
208+
return
209+
}
210+
211+
const count: BatchCounts = {
212+
maxInstances: 1,
213+
maxVertices: mesh.verts.length / 3,
214+
maxIndices: mesh.indices.length,
215+
}
216+
countMap.set(material, count)
217+
})
218+
})
236219

237220
// Construct batched meshes
238221
batchMap.forEach((materialBodyMap, material) => {

0 commit comments

Comments
 (0)