Skip to content

Commit

Permalink
Added geometry outline and merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed May 18, 2024
1 parent 96c9fc0 commit 98a11ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
13 changes: 9 additions & 4 deletions firebird-ng/src/app/main-display/main-display.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function getColorOrDefault(material:any, defaultColor: Color): Color {
* @param parentNode The parent node of the branch to merge.
* @returns void
*/
function mergeBranchGeometries(parentNode: THREE.Object3D): void {
function mergeBranchGeometries(parentNode: THREE.Object3D, name: string): void {
const geometries: THREE.BufferGeometry[] = [];
let material: THREE.Material | undefined;
const childrenToRemove: THREE.Object3D[] = [];
Expand Down Expand Up @@ -94,9 +94,13 @@ function mergeBranchGeometries(parentNode: THREE.Object3D): void {
childrenToRemove.forEach((child: any) => {
child.geometry.dispose();
child?.parent?.remove(child);
// Remove empty parents
if( (child?.parent?.children?.length ?? 1) === 0 ) {
child?.parent?.parent?.remove(child.parent);
}
});


mergedMesh.name = name;

parentNode.add(mergedMesh);
}
Expand Down Expand Up @@ -160,7 +164,7 @@ export class MainDisplayComponent implements OnInit {
// Add geometry
uiManager.addGeometry(obj3dNode, obj3dNode.name);

mergeBranchGeometries(obj3dNode);
mergeBranchGeometries(obj3dNode, obj3dNode.name + "_merged");

}

Expand Down Expand Up @@ -241,7 +245,8 @@ export class MainDisplayComponent implements OnInit {
// Set render priority
let scene = threeManager.getSceneManager().getScene();
let camera = openThreeManager.controlsManager.getMainCamera();
// produceRenderOrder(scene, camera.position, 'dflt');
camera.far = 5000;
//produceRenderOrder(scene, camera.position, 'dflt');


}
Expand Down
35 changes: 19 additions & 16 deletions firebird-ng/src/app/three-geometry.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ export class ThreeGeometryProcessor {
`;
fragmentShader = `
//#extension GL_OES_standard_derivatives : enable
varying vec2 vUv;
uniform float thickness;
float edgeFactor(vec2 p){
vec2 grid = abs(fract(p - 0.5) - 0.5) / fwidth(p) / thickness;
return min(grid.x, grid.y);
}
void main() {
float a = edgeFactor(vUv);
vec3 c = mix(vec3(1), vec3(0), a);
gl_FragColor = vec4(c, 1.0);
}
`;
Expand All @@ -96,7 +96,7 @@ export class ThreeGeometryProcessor {
} );



// new MeshPhysicalMaterial({
// color: 0xffff00, // Yellow color
// metalness: 0,
Expand Down Expand Up @@ -138,21 +138,24 @@ export class ThreeGeometryProcessor {
// Material
let name:string = child.name;

if(name.startsWith("bar_") || name.startsWith("prism_")) {
child.material = this.alphaMaterial;
//if(name.startsWith("bar_") || name.startsWith("prism_")) {
//child.material = this.alphaMaterial;
const edges = new EdgesGeometry(child.geometry);
const lineMaterial = new LineBasicMaterial({
color: 0xffffff,
color: 0x555555,
fog: false,
// Copy clipping planes from parent, using type assertion for TypeScript
clippingPlanes: child.material.clippingPlanes ? child.material.clippingPlanes : undefined,
clipIntersection: (child.material as Material).clipIntersection,
clipShadows: (child.material as Material).clipShadows
clippingPlanes: child.material.clippingPlanes ? child.material.clippingPlanes : [],
clipIntersection: true,
clipShadows: true

});
// lineMaterial.clipping = true;
const edgesLine = new LineSegments(edges, lineMaterial);

child.add(edgesLine);

}
child.parent.add(edgesLine);

//}
});
}
}

0 comments on commit 98a11ac

Please sign in to comment.