Skip to content

Commit

Permalink
extracted traverse tree
Browse files Browse the repository at this point in the history
  • Loading branch information
azaleacolburn committed Aug 21, 2024
1 parent 09aea2c commit 29000a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
3 changes: 2 additions & 1 deletion fission/src/mirabuf/MirabufInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ class MirabufInstance {
if (!mesh?.verts || !mesh.normals || !mesh.uv || !mesh.indices) return

const appearanceOverride = body.appearanceOverride
const material: THREE.Material = WIREFRAME

const material = WIREFRAME
? new THREE.MeshStandardMaterial({ wireframe: true, color: 0x000000 })
: appearanceOverride && this._materials.has(appearanceOverride)
? this._materials.get(appearanceOverride)!
Expand Down
44 changes: 19 additions & 25 deletions fission/src/mirabuf/MirabufParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,10 @@ class MirabufParser {
this.GenerateTreeValues()
this.LoadGlobalTransforms()

function traverseTree(nodes: mirabuf.INode[], op: (node: mirabuf.INode) => void) {
nodes.forEach(node => {
if (node.children) traverseTree(node.children, op)
op(node)
})
}

this.InitializeRigidGroups(assembly, traverseTree) // 1: from ancestral breaks in joints
this.InitializeRigidGroups() // 1: from ancestral breaks in joints

// Fields Only: Assign Game Piece rigid nodes
if (!assembly.dynamic) this.AssignGamePieceRigidNodes(assembly, traverseTree)
if (!assembly.dynamic) this.AssignGamePieceRigidNodes()

// 2: Grounded joint
const gInst = assembly.data!.joints!.jointInstances![GROUNDED_JOINT_ID]
Expand Down Expand Up @@ -136,41 +129,42 @@ class MirabufParser {
}
}

private InitializeRigidGroups(
assembly: mirabuf.Assembly,
traverseTree: (node: mirabuf.INode[], op: (node: mirabuf.INode) => void) => void
) {
const jointInstanceKeys = Object.keys(assembly.data!.joints!.jointInstances!) as string[]
private TraverseTree(nodes: mirabuf.INode[], op: (node: mirabuf.INode) => void) {
nodes.forEach(node => {
if (node.children) this.TraverseTree(node.children, op)
op(node)
})
}

private InitializeRigidGroups() {
const jointInstanceKeys = Object.keys(this._assembly.data!.joints!.jointInstances!) as string[]
jointInstanceKeys.forEach(key => {
if (key === GROUNDED_JOINT_ID) return

const jInst = assembly.data!.joints!.jointInstances![key]
const jInst = this._assembly.data!.joints!.jointInstances![key]
const [ancestorA, ancestorB] = this.FindAncestorialBreak(jInst.parentPart!, jInst.childPart!)
const parentRN = this.NewRigidNode()

this.MovePartToRigidNode(ancestorA, parentRN)
this.MovePartToRigidNode(ancestorB, this.NewRigidNode())

if (jInst.parts && jInst.parts.nodes)
traverseTree(jInst.parts.nodes, x => this.MovePartToRigidNode(x.value!, parentRN))
this.TraverseTree(jInst.parts.nodes, x => this.MovePartToRigidNode(x.value!, parentRN))
})
}

private AssignGamePieceRigidNodes(
assembly: mirabuf.Assembly,
traverseTree: (node: mirabuf.INode[], op: (node: mirabuf.INode) => void) => void
) {
private AssignGamePieceRigidNodes() {
// Collect all definitions labeled as gamepieces (dynamic = true)
const gamepieceDefinitions: Set<string> = new Set(
Object.values(assembly.data!.parts!.partDefinitions!)
Object.values(this._assembly.data!.parts!.partDefinitions!)
.filter(def => def.dynamic)
.map((def: mirabuf.IPartDefinition) => {
return def.info!.GUID!
})
)

// Create gamepiece rigid nodes from PartInstances with corresponding definitions
Object.values(assembly.data!.parts!.partInstances!).forEach((inst: mirabuf.IPartInstance) => {
Object.values(this._assembly.data!.parts!.partInstances!).forEach((inst: mirabuf.IPartInstance) => {
if (!gamepieceDefinitions.has(inst.partDefinitionReference!)) return

const instNode = this.BinarySearchDesignTree(inst.info!.GUID!)
Expand All @@ -182,7 +176,7 @@ class MirabufParser {
const gpRn = this.NewRigidNode(GAMEPIECE_SUFFIX)
gpRn.isGamePiece = true
this.MovePartToRigidNode(instNode!.value!, gpRn)
if (instNode.children) traverseTree(instNode.children, x => this.MovePartToRigidNode(x.value!, gpRn))
if (instNode.children) this.TraverseTree(instNode.children, x => this.MovePartToRigidNode(x.value!, gpRn))
})
}

Expand Down Expand Up @@ -219,7 +213,7 @@ class MirabufParser {
directedGraph.AddNode(node.id)
})

function directedRecursive(node: string) {
const directedRecursive = (node: string) => {
graph
.GetAdjacencyList(node)
.filter(x => whiteGreyBlackMap.has(x))
Expand Down Expand Up @@ -381,7 +375,7 @@ class MirabufParser {
let nextValue = 0
const partTreeValues = new Map<string, number>()

function recursive(partNode: mirabuf.INode) {
const recursive = (partNode: mirabuf.INode) => {
partNode.children = partNode.children?.filter(x => x.value != null)
partNode.children?.forEach(x => recursive(x))
partTreeValues.set(partNode.value!, nextValue++)
Expand Down

0 comments on commit 29000a2

Please sign in to comment.