prolincur / three-dxf-loader

Cross platform DXF file loader for THREE.js and react-three-fiber
https://www.npmjs.com/package/three-dxf-loader
MIT License
46 stars 9 forks source link

MTEXT with directionVector can get wrong Z rotation #31

Open tampiland opened 4 weeks ago

tampiland commented 4 weeks ago

I noticed that some of my text elements appeared upside down in threejs compared to my CAD software. I've tried to review the code, and I believe that line 334 in index.js always produces positive angles, when half of them should be negative.

if (entity.directionVector) {
    var dv = entity.directionVector
    textEnt.rotation.z = new THREE.Vector3(1, 0, 0).angleTo(new THREE.Vector3(dv.x, dv.y, dv.z))
}

Line 334 in index.js

I believe a simple sign multiplication with the Y-component would do the trick.

if (entity.directionVector) {
    var dv = entity.directionVector
    textEnt.rotation.z = new THREE.Vector3(1, 0, 0).angleTo(new THREE.Vector3(dv.x, dv.y, dv.z)) * Math.sign(dv.y)
}