-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct work with edm4eic files from remote API
- Loading branch information
Showing
15 changed files
with
224 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
firebird-ng/src/app/painters/box-tracker-hit-simple.painter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { | ||
Object3D, | ||
Mesh, | ||
BoxGeometry, | ||
MeshBasicMaterial, | ||
Color, | ||
} from 'three'; | ||
import { ComponentPainter } from './component-painter'; | ||
import { BoxTrackerHitComponent } from '../model/box-tracker-hit.component'; | ||
import { EntryComponent } from '../model/entry-component'; | ||
|
||
/** | ||
* Alternative Painter class for rendering BoxTrackerHitComponent using individual Meshes. | ||
*/ | ||
export class BoxTrackerHitSimplePainter extends ComponentPainter { | ||
/** Array of Mesh objects representing hits */ | ||
private hitMeshes: Mesh[] = []; | ||
|
||
private boxComponent: BoxTrackerHitComponent; | ||
|
||
/** | ||
* Constructs a new BoxTrackerHitAlternativePainter. | ||
* | ||
* @param parentNode - The Object3D node where the hit meshes will be added. | ||
* @param component - The BoxTrackerHitComponent containing the hit data. | ||
*/ | ||
constructor(parentNode: Object3D, component: EntryComponent) { | ||
super(parentNode, component); | ||
|
||
// Runtime type check | ||
if (component.type !== BoxTrackerHitComponent.type) { | ||
throw new Error('Invalid component type for BoxTrackerHitAlternativePainter'); | ||
} | ||
|
||
this.boxComponent = component as BoxTrackerHitComponent; | ||
|
||
// Create a bright random color for this component collection | ||
const hue = Math.random(); | ||
const randomColor = new Color().setHSL(hue, 1, 0.5); // Bright color | ||
|
||
// Create a material with the random color | ||
const material = new MeshBasicMaterial({ color: randomColor }); | ||
|
||
// Create a mesh for each hit using the same material | ||
this.createHitMeshes(material); | ||
} | ||
|
||
/** | ||
* Creates Mesh instances for each hit and adds them to the parent node. | ||
* | ||
* @param material - The material to use for the hit meshes. | ||
*/ | ||
private createHitMeshes(material: MeshBasicMaterial): void { | ||
for (const hit of this.boxComponent.hits) { | ||
// Create geometry for the box | ||
const geometry = new BoxGeometry(10,10,10 | ||
// hit.dimensions[0], | ||
// hit.dimensions[1], | ||
// hit.dimensions[2] | ||
); | ||
|
||
// Create the mesh | ||
const mesh = new Mesh(geometry, material); | ||
|
||
// Set position | ||
mesh.position.set(hit.position[0], hit.position[1], hit.position[2]); | ||
|
||
// Store the hit time | ||
mesh.userData['appearanceTime'] = hit.time[0]; | ||
|
||
// Initially make the mesh invisible | ||
mesh.visible = false; | ||
|
||
// Add the mesh to the parent node and to the array | ||
this.parentNode.add(mesh); | ||
this.hitMeshes.push(mesh); | ||
} | ||
} | ||
|
||
/** | ||
* Paint method to update the visibility of the hits based on time. | ||
* | ||
* @param time - The current time in nanoseconds or null for static rendering. | ||
*/ | ||
public paint(time: number | null): void { | ||
for (const mesh of this.hitMeshes) { | ||
if (time !== null) { | ||
// Show the mesh if its appearance time is less than or equal to the current time | ||
mesh.visible = mesh.userData['appearanceTime'] <= time; | ||
} else { | ||
// In static mode, make all meshes visible | ||
mesh.visible = true; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Dispose of resources used by the painter. | ||
*/ | ||
override dispose(): void { | ||
for (const mesh of this.hitMeshes) { | ||
// Dispose of geometry and material | ||
mesh.geometry.dispose(); | ||
|
||
// Dispose of the material only if it's not shared with other meshes | ||
if (mesh.material instanceof MeshBasicMaterial) { | ||
mesh.material.dispose(); | ||
} | ||
|
||
// Remove the mesh from the parent node | ||
this.parentNode.remove(mesh); | ||
} | ||
|
||
// Clear the array | ||
this.hitMeshes = []; | ||
|
||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.