首页 > 解决方案 > Three.js 四元数不能分配给只读属性

问题描述

我正在尝试创建一个类(使用three.js),该类使用具有向量名称的数组与具有一组向量3 的数组进行比较,并生成平面的网格,但出现错误。


Uncaught TypeError: Cannot assign to read only property 'quaternion' of object '# <Tface>'
    at Tface.criaFace (Tface.js: 58)
    at eval (index.js: 54)
    at Module ../ src / index.js (bundle.js: 651)
    at __webpack_require__ (bundle.js: 674)
    at bundle.js: 738
    at bundle.js: 741

https://github.com/gisselecardozo/teste-classes/blob/master/src/classes/Tface.js

标签: javascriptthree.js

解决方案


该类Tponto派生自THREE.Object3D. 结果quaternion属性是只读的。criaFace()这意味着您的方法中的以下分配无效。

this.quaternion = new THREE.Quaternion().setFromUnitVectors(this.normal, this.baseNormal);

它应该是:

this.quaternion.setFromUnitVectors(this.normal, this.baseNormal);


推荐阅读