Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirabuf Friction Parsing #1096

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a09bfc8
some minor parser refactors
azaleacolburn Aug 15, 2024
1b1ad67
some declarative-style refactors of instance and parsing
azaleacolburn Aug 16, 2024
1594ef3
minor changes
azaleacolburn Aug 17, 2024
a370ff2
set friction when creating bodies from parser
azaleacolburn Aug 19, 2024
c9c0e56
small refactors to parsing
azaleacolburn Aug 19, 2024
2a3fa72
make eslint not complain
azaleacolburn Aug 19, 2024
11fadb2
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Aug 19, 2024
a150a1c
fix build and lint
azaleacolburn Aug 19, 2024
dc6bf6a
more extraction refactoring in MirabufParser constructor
azaleacolburn Aug 20, 2024
102f164
more refactors :)
azaleacolburn Aug 20, 2024
7f934b3
format
azaleacolburn Aug 20, 2024
e8d823b
fix parsing for non-dynamic assemblies
azaleacolburn Aug 21, 2024
66b9f87
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Aug 21, 2024
5b9e451
fix raycasting
azaleacolburn Aug 21, 2024
09aea2c
fix intense robot shaking
azaleacolburn Aug 21, 2024
6af504d
Update fission/src/mirabuf/MirabufInstance.ts
azaleacolburn Aug 21, 2024
c485d5b
Update fission/src/systems/physics/PhysicsSystem.ts
azaleacolburn Aug 21, 2024
29000a2
extracted traverse tree
azaleacolburn Aug 21, 2024
86a8e51
Merge branch 'colbura/1777/friction-parsing' of https://github.com/Au…
azaleacolburn Aug 21, 2024
4f6f742
Update fission/src/mirabuf/MirabufParser.ts
azaleacolburn Aug 21, 2024
4bffc6a
cleanup appearance parsing
azaleacolburn Aug 21, 2024
691c7d0
formatted
azaleacolburn Aug 21, 2024
e328c03
revert colors
azaleacolburn Aug 22, 2024
2acdfa2
change map to foreach
azaleacolburn Aug 22, 2024
32fc40e
format
azaleacolburn Aug 22, 2024
98f049e
one more formatting change apartently
azaleacolburn Aug 22, 2024
3c358e4
what is going on with formatting
azaleacolburn Aug 22, 2024
5f1b4ed
i think maybe eslint and prettier disagree :(
azaleacolburn Aug 22, 2024
32dbec7
format again
azaleacolburn Aug 22, 2024
bbc7cda
Merge branch 'dev' into colbura/1777/friction-parsing
HunterBarclay Sep 2, 2024
0c39d2e
WIP: Accumulating friction pairings and fixed gamepiece issue in the
HunterBarclay Sep 5, 2024
978d9d4
Merge branch 'dev' into colbura/1777/friction-parsing
HunterBarclay Sep 5, 2024
78f7f3b
fix: Add fallbacks for zero friction, experimenting with materials in
HunterBarclay Sep 16, 2024
c875a15
chores: Clean up left over test code, remove debug statements.
HunterBarclay Sep 16, 2024
8b5fdea
Merge branch 'dev' into colbura/1777/friction-parsing
HunterBarclay Nov 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fission/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint:fix": "eslint . --ext ts,tsx --report-unused-disable-directives --fix",
"prettier": "bun x prettier src --check || npx prettier src --check",
"prettier:fix": "bun x prettier src --write || npx prettier src --write",
"format": "(bun run prettier:fix && bun run lint:fix) || (npm run prettier:fix && npm run lint:fix)",
"format": "bun run prettier:fix && bun run lint:fix || npm run prettier:fix && npm run lint:fix",
"assetpack": "curl -o public/assetpack.zip https://synthesis.autodesk.com/Downloadables/assetpack.zip && tar -xf public/assetpack.zip -C public/",
"playwright:install": "bun x playwright install || npx playwright install"
},
Expand Down
149 changes: 65 additions & 84 deletions fission/src/mirabuf/MirabufInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ class MirabufInstance {
}

public constructor(parser: MirabufParser, materialStyle?: MaterialStyle, progressHandle?: ProgressHandle) {
if (parser.errors.some(x => x[0] >= ParseErrorSeverity.Unimportable)) {
if (parser.errors.some(x => x[0] >= ParseErrorSeverity.Unimportable))
azaleacolburn marked this conversation as resolved.
Show resolved Hide resolved
throw new Error("Parser has significant errors...")
}

this._mirabufParser = parser
this._materials = new Map()
Expand All @@ -126,39 +125,30 @@ class MirabufInstance {
}

/**
* Parses all mirabuf appearances into ThreeJs materials.
* Parses all mirabuf appearances into ThreeJS and Jolt materials.
*/
private LoadMaterials(materialStyle: MaterialStyle) {
Object.entries(this._mirabufParser.assembly.data!.materials!.appearances!).forEach(
([appearanceId, appearance]) => {
let hex = 0xe32b50
let opacity = 1.0
if (appearance.albedo) {
const { A, B, G, R } = appearance.albedo
if (A && B && G && R) {
hex = (A << 24) | (R << 16) | (G << 8) | B
opacity = A / 255.0
}
}

let material: THREE.Material
if (materialStyle == MaterialStyle.Regular) {
material = new THREE.MeshPhongMaterial({
color: hex,
shininess: 0.0,
shadowSide: THREE.DoubleSide,
opacity: opacity,
transparent: opacity < 1.0,
})
} else if (materialStyle == MaterialStyle.Normals) {
material = new THREE.MeshNormalMaterial()
} else if (materialStyle == MaterialStyle.Toon) {
material = World.SceneRenderer.CreateToonMaterial(hex, 5)
console.debug("Toon Material")
}

World.SceneRenderer.SetupMaterial(material!)
this._materials.set(appearanceId, material!)
const { A, B, G, R } = appearance.albedo ?? {}
const [hex, opacity] =
A && B && G && R ? [(A << 24) | (R << 16) | (G << 8) | B, A / 255.0] : [0xe32b50, 1.0]
azaleacolburn marked this conversation as resolved.
Show resolved Hide resolved

const material =
materialStyle === MaterialStyle.Regular
? new THREE.MeshPhongMaterial({
color: hex,
shininess: 0.0,
shadowSide: THREE.DoubleSide,
opacity: opacity,
transparent: opacity < 1.0,
})
: materialStyle === MaterialStyle.Normals
? new THREE.MeshNormalMaterial()
: World.SceneRenderer.CreateToonMaterial(hex, 5)
azaleacolburn marked this conversation as resolved.
Show resolved Hide resolved

World.SceneRenderer.SetupMaterial(material)
this._materials.set(appearanceId, material)
}
)
}
Expand All @@ -178,61 +168,52 @@ class MirabufInstance {

const batchMap = new Map<THREE.Material, Map<string, [mirabuf.IBody, Array<mirabuf.IPartInstance>]>>()
const countMap = new Map<THREE.Material, BatchCounts>()

// Filter all instances by first material, then body
for (const instance of Object.values(instances)) {
const definition = assembly.data!.parts!.partDefinitions![instance.partDefinitionReference!]!
const bodies = definition.bodies
if (bodies) {
for (const body of bodies) {
if (!body) continue
const mesh = body.triangleMesh
if (
mesh &&
mesh.mesh &&
mesh.mesh.verts &&
mesh.mesh.normals &&
mesh.mesh.uv &&
mesh.mesh.indices
) {
const appearanceOverride = body.appearanceOverride
const material: THREE.Material = WIREFRAME
? new THREE.MeshStandardMaterial({ wireframe: true, color: 0x000000 })
: appearanceOverride && this._materials.has(appearanceOverride)
? this._materials.get(appearanceOverride)!
: fillerMaterials[nextFillerMaterial++ % fillerMaterials.length]

let materialBodyMap = batchMap.get(material)
if (!materialBodyMap) {
materialBodyMap = new Map<string, [mirabuf.IBody, Array<mirabuf.IPartInstance>]>()
batchMap.set(material, materialBodyMap)
}

const partBodyGuid = this.GetPartBodyGuid(definition, body)
let bodyInstances = materialBodyMap.get(partBodyGuid)
if (!bodyInstances) {
bodyInstances = [body, new Array<mirabuf.IPartInstance>()]
materialBodyMap.set(partBodyGuid, bodyInstances)
}
bodyInstances[1].push(instance)

if (countMap.has(material)) {
const count = countMap.get(material)!
count.maxInstances += 1
count.maxVertices += mesh.mesh.verts.length / 3
count.maxIndices += mesh.mesh.indices.length
} else {
const count: BatchCounts = {
maxInstances: 1,
maxVertices: mesh.mesh.verts.length / 3,
maxIndices: mesh.mesh.indices.length,
}
countMap.set(material, count)
}
}
Object.values(instances).forEach(instance => {
const definition = assembly.data!.parts!.partDefinitions![instance.partDefinitionReference!]
const bodies = definition?.bodies ?? []
bodies.forEach(body => {
const mesh = body?.triangleMesh?.mesh
if (!mesh?.verts || !mesh.normals || !mesh.uv || !mesh.indices) return

const appearanceOverride = body.appearanceOverride

const material = WIREFRAME
? new THREE.MeshStandardMaterial({ wireframe: true, color: 0x000000 })
: appearanceOverride && this._materials.has(appearanceOverride)
? this._materials.get(appearanceOverride)!
: fillerMaterials[nextFillerMaterial++ % fillerMaterials.length]
azaleacolburn marked this conversation as resolved.
Show resolved Hide resolved

let materialBodyMap = batchMap.get(material)
if (!materialBodyMap) {
materialBodyMap = new Map<string, [mirabuf.IBody, Array<mirabuf.IPartInstance>]>()
batchMap.set(material, materialBodyMap)
}
}
}

const partBodyGuid = this.GetPartBodyGuid(definition, body)
let bodyInstances = materialBodyMap.get(partBodyGuid)
if (!bodyInstances) {
bodyInstances = [body, new Array<mirabuf.IPartInstance>()]
materialBodyMap.set(partBodyGuid, bodyInstances)
}
bodyInstances[1].push(instance)

if (countMap.has(material)) {
const count = countMap.get(material)!
count.maxInstances += 1
count.maxVertices += mesh.verts.length / 3
count.maxIndices += mesh.indices.length
return
}

const count: BatchCounts = {
maxInstances: 1,
maxVertices: mesh.verts.length / 3,
maxIndices: mesh.indices.length,
}
countMap.set(material, count)
})
})

console.debug(batchMap)

Expand Down
Loading
Loading