简体   繁体   English

Three.js:改变网格颜色导致只有一张脸受到改变的影响

[英]Three.js: changing mesh color results in only 1 face getting affected by the change

so i have a model (an assembly from CAD) in GLB format, with many parts, hierarchy and such.所以我有一个 GLB 格式的模型(来自 CAD 的组件),其中包含许多部件、层次结构等。 What i'm trying to accomplish is highlighting an object (specifically, a part of the assembly) on mouseover.我想要完成的是在鼠标悬停时突出显示一个对象(特别是程序集的一部分)。

so the main code that does this is:所以执行此操作的主要代码是:

raycaster.setFromCamera( pointer, camera );
            
                const intersects = raycaster.intersectObjects(scene.children, true);

                if ( intersects.length > 0 ) {

                    if ( INTERSECTED != intersects[ 0 ].object ) {

                        if ( INTERSECTED ) INTERSECTED.material.color.set( INTERSECTED.currentColor );

                        INTERSECTED = intersects[ 0 ].object;
                        
                        INTERSECTED.currentColor = INTERSECTED.material.color.getHex();

                        INTERSECTED.material = INTERSECTED.material.clone();
                        INTERSECTED.material.color.setHex( 0xffb300 );

                    }

                } else {

                    if ( INTERSECTED ) INTERSECTED.material.color.set( INTERSECTED.currentColor );
                    INTERSECTED = null;

                }

but unfortunately, the result i get is that only 1 face gets the colour change, the rest of the mesh does not.但不幸的是,我得到的结果是只有 1 个面发生了颜色变化,其余的网格没有。 I have tried many things but i'm kind of a novice on three.js so basically i don't have a clue我尝试了很多东西,但我是 Three.js 的新手,所以基本上我不知道

for anybody with the same problem in the future: for some kind of reason the step->glb conversion made a standalone mesh for every object face.对于将来遇到相同问题的任何人:出于某种原因,step->glb 转换为每个对象面制作了一个独立的网格。 So in order to highlight the whole part i had to change the material of every object in object.parent.children所以为了突出整个部分,我不得不改变 object.parent.children 中每个对象的材质

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM