我有一个数字范围,例如[-10, 10]。
我想按百分比获取数字。
例如,如果有50%我应该得到0。对于100%我应该得到10。
我正在考虑一个函数来获取percent,min和max数字并返回计算出的数字。
喜欢:
function getRangeNumber(percent, min, max){
// do some math here...
}
Run Code Online (Sandbox Code Playgroud)
我应该如何用 JavaScript 计算它?有人可以帮忙吗?
正如 Three.js 的文档所说,改变相机的位置后,我们必须调用该updateProjectionMatrix()方法。我也在做同样的事情。但它给了我这样的错误:
TypeError: object.updateWorldMatrix is not a function
at Box3.expandByObject (three.module.js:6329)
at Box3.setFromObject (three.module.js:6233)
at index.js:66
at GLTFLoader.js:147
at GLTFLoader.js:1639
Run Code Online (Sandbox Code Playgroud)
我的目标是将我加载的 GLTF 对象放在屏幕中央。这是我使用的代码:
this.gltfLoader.load("/corolla.gltf", (object) => {
const box = new THREE.Box3().setFromObject(object);
const size = box.getSize(new THREE.Vector3()).length();
const center = box.getCenter(new THREE.Vector3());
// reset OrbitControl
this.controls.reset();
object.position.x += (object.position.x - center.x);
object.position.y += (object.position.y - center.y);
object.position.z += (object.position.z - center.z);
this.controls.maxDistance = size * 10;
this.camera.near = size / 100;
this.camera.far = size * 100;
this.camera.updateProjectionMatrix(); …Run Code Online (Sandbox Code Playgroud)