donmccurdy / three-gltf-viewer

Drag-and-drop preview for glTF 2.0 models in WebGL using three.js.
https://gltf-viewer.donmccurdy.com/
MIT License
2.15k stars 539 forks source link

CSS3DRenderer Adding tags, ineffective, I am very desperate #356

Closed jinmaotowne closed 11 months ago

jinmaotowne commented 11 months ago

Thank you for your reply! Viewer.js 300 3345

3444

                const scene = gltf.scene || gltf.scenes[0];
                const clips = gltf.animations || [];

                if (!scene) {
                    // Valid, but not supported by this viewer.
                    throw new Error(
                        'This model contains no scene, and cannot be viewed here. However,' +
                            ' it may contain individual 3D resources.',
                    );
                }           
            scene.traverse(child => {

                        if (child.type === 'Mesh' ) {

                            console.log("===================");
                            //添加标签文字
                              var element = document.createElement('div');
                                element.className = 'tag';
                                element.innerHTML = '============================';
                                var object = new CSS3DObject(element);
                                object.visible = true;
                                //缩放比例
                                object.scale.set(0.2, 0.2, 0.2);
                                //指定摆放位置
                                object.position.copy(child.position);
                                scene.add(object);//添加到指定的场景里
                        }

                    });

                      this.d3renderer.setSize(window.offsetWidth, window.offsetHeight);
                      this.d3renderer.domElement.style.position = 'absolute';
                      this.d3renderer.domElement.style.top = '10px';
                      this.d3renderer.domElement.style.left = '10px';
                      this.d3renderer.domElement.style.pointerEvents = 'none';
                      document.body.appendChild(this.d3renderer.domElement);

                this.setContent(scene, clips);
jinmaotowne commented 11 months ago

i used this model: https://github.com/jinmaotowne/test/blob/main/room.glb

jinmaotowne commented 11 months ago

the CSS3DRenderer version is r158

donmccurdy commented 11 months ago

Sorry @jinmaotowne — as mentioned in https://github.com/donmccurdy/three-gltf-viewer/issues/355#issuecomment-1845506678 I do not generally provide 1:1 support. Please use the three.js support channels (in link) rather than contacting me personally.