n5ro / aframe-physics-system

Physics system for A-Frame VR, built on CANNON.js.
https://n5ro.github.io/aframe-physics-system/
MIT License
505 stars 136 forks source link

THREE.Geometry is not a constructor Error Aframe 1.3.0 (>1.0.4) #205

Open smeybi opened 1 year ago

smeybi commented 1 year ago

With the newer Aframe versions above>1.0.4 it has an error THREE.Geometry is not a constructor for certain functions such as spring. I'm not sure is the solution, I didn't test properly. But i have replaced: THREE.Geometry() with THREE.BufferGeometry() and tmp.fromBufferGeometry(meshes[0].geometry) with tmp = meshes[0].geometry.clone() It seems to work.

function getGeometry (object) { var matrix, mesh, meshes = getMeshes(object), tmp = new THREE.BufferGeometry(), // new THREE.Geometry(), combined = new THREE.BufferGeometry(); // new THREE.Geometry(),

if (meshes.length === 0) return null;

// Apply scale – it can't easily be applied to a CANNON.Shape later. if (meshes.length === 1) { var position = new THREE.Vector3(), quaternion = new THREE.Quaternion(), scale = new THREE.Vector3(); if (meshes[0].geometry.isBufferGeometry) { if (meshes[0].geometry.attributes.position && meshes[0].geometry.attributes.position.itemSize > 2) { // tmp.fromBufferGeometry(meshes[0].geometry); tmp = meshes[0].geometry.clone(); } } else { tmp = meshes[0].geometry.clone(); } tmp.metadata = meshes[0].geometry.metadata; meshes[0].updateMatrixWorld(); meshes[0].matrixWorld.decompose(position, quaternion, scale); return tmp.scale(scale.x, scale.y, scale.z); }

// Recursively merge geometry, preserving local transforms. while ((mesh = meshes.pop())) { mesh.updateMatrixWorld(); if (mesh.geometry.isBufferGeometry) { if (mesh.geometry.attributes.position && mesh.geometry.attributes.position.itemSize > 2) { var tmpGeom = new THREE.Geometry(); // tmpGeom.fromBufferGeometry(mesh.geometry); tmpGeom = meshes.geometry.clone(); combined.merge(tmpGeom, mesh.matrixWorld); tmpGeom.dispose(); } } else { combined.merge(mesh.geometry, mesh.matrixWorld); } }

vincentfretin commented 1 year ago

This is fixed in the community fork https://www.npmjs.com/package/@c-frame/aframe-physics-system