mirror of
https://github.com/yeicor-3d/yet-another-cad-viewer.git
synced 2025-12-19 22:24:17 +01:00
add support for rendering vertices
This commit is contained in:
@@ -40,7 +40,7 @@ function onEnabledFeaturesChange(newEnabledFeatures: Array<number>) {
|
||||
if (child.userData[extrasNameKey] === modelName) {
|
||||
let childIsFace = child.type == 'Mesh' || child.type == 'SkinnedMesh'
|
||||
let childIsEdge = child.type == 'Line'
|
||||
let childIsVertex = child.type == 'Point'
|
||||
let childIsVertex = child.type == 'Points'
|
||||
if (childIsFace || childIsEdge || childIsVertex) {
|
||||
let visible = newEnabledFeatures.includes(childIsFace ? 0 : childIsEdge ? 1 : childIsVertex ? 2 : -1);
|
||||
if (child.visible !== visible) {
|
||||
@@ -51,6 +51,7 @@ function onEnabledFeaturesChange(newEnabledFeatures: Array<number>) {
|
||||
});
|
||||
scene.queueRender()
|
||||
}
|
||||
|
||||
watch(enabledFeatures, onEnabledFeaturesChange);
|
||||
|
||||
function onOpacityChange(newOpacity: number) {
|
||||
@@ -63,8 +64,7 @@ function onOpacityChange(newOpacity: number) {
|
||||
console.log('Opacity may have changed', newOpacity)
|
||||
sceneModel.traverse((child) => {
|
||||
if (child.userData[extrasNameKey] === modelName) {
|
||||
if (child.material) {
|
||||
console.log('Setting opacity of', child)
|
||||
if (child.material && child.material.opacity !== newOpacity) {
|
||||
child.material.transparent = newOpacity < 1;
|
||||
child.material.opacity = newOpacity;
|
||||
child.material.needsUpdate = true;
|
||||
@@ -73,15 +73,42 @@ function onOpacityChange(newOpacity: number) {
|
||||
});
|
||||
scene.queueRender()
|
||||
}
|
||||
|
||||
watch(opacity, onOpacityChange);
|
||||
|
||||
// props.viewer.elem is already available as a model has been loaded...
|
||||
props.viewer.elem.addEventListener('load', () => {
|
||||
function onModelLoad() {
|
||||
let scene = props.viewer?.scene;
|
||||
let sceneModel = (scene as any)?._model;
|
||||
if (!scene || !sceneModel) return;
|
||||
// Iterate all primitives of the mesh and set their visibility based on the enabled features
|
||||
// Use the scene graph instead of the document to avoid reloading the same model, at the cost
|
||||
// of not actually removing the primitives from the scene graph
|
||||
sceneModel.traverse((child) => {
|
||||
if (child.userData[extrasNameKey] === modelName) {
|
||||
// if (child.type == 'Line') child.material.linewidth = 2; // Not supported in WebGL2
|
||||
if (child.type == 'Points') {
|
||||
child.material.size = 5;
|
||||
}
|
||||
}
|
||||
});
|
||||
scene.queueRender()
|
||||
|
||||
// Furthermore...
|
||||
|
||||
// Enabled features may have been reset after a reload
|
||||
onEnabledFeaturesChange(enabledFeatures.value)
|
||||
// Opacity may have been reset after a reload
|
||||
onOpacityChange(opacity.value)
|
||||
});
|
||||
}
|
||||
|
||||
// props.viewer.elem may not yet be available, so we need to wait for it
|
||||
if (props.viewer.elem) {
|
||||
props.viewer.elem.addEventListener('load', onModelLoad);
|
||||
} else {
|
||||
watch(() => props.viewer?.elem, (elem) => {
|
||||
if (elem) elem.addEventListener('load', onModelLoad);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -158,6 +185,7 @@ props.viewer.elem.addEventListener('load', () => {
|
||||
.v-expansion-panel-text__wrapper {
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.hide-this-icon {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class GLTFMgr:
|
||||
baseColorFactor=[0, 0, 0.5, 1]))
|
||||
elif kind == "vertex":
|
||||
new_material = Material(name="vertex", alphaCutoff=None, pbrMetallicRoughness=PbrMetallicRoughness(
|
||||
baseColorFactor=[0.5, 0.5, 0.5, 1]))
|
||||
baseColorFactor=[0, 0.2, 0, 1]))
|
||||
else:
|
||||
raise ValueError(f"Unknown material kind {kind}")
|
||||
self.gltf.materials.append(new_material)
|
||||
|
||||
Reference in New Issue
Block a user