-
-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All components that use three.js Geometry such as <a-ocean> are broken in A-Frame 1.2.0 #348
Comments
Geometry
such as <a-ocean> are broken in A-Frame 1.2.0
Geometry
such as <a-ocean> are broken in A-Frame 1.2.0
here is a quickly hacked together update for AFRAME.registerPrimitive('a-ocean', {
defaultComponents: {
ocean: {},
rotation: { x: -90, y: 0, z: 0 }
},
mappings: {
width: 'ocean.width',
depth: 'ocean.depth',
density: 'ocean.density',
amplitude: 'ocean.amplitude',
amplitudeVariance: 'ocean.amplitudeVariance',
speed: 'ocean.speed',
speedVariance: 'ocean.speedVariance',
color: 'ocean.color',
opacity: 'ocean.opacity'
}
});
AFRAME.registerComponent('ocean', {
schema: {
// Dimensions of the ocean area.
width: { default: 10, min: 0 },
depth: { default: 10, min: 0 },
// Density of waves.
density: { default: 10 },
// Wave amplitude and variance.
amplitude: { default: 0.1 },
amplitudeVariance: { default: 0.3 },
// Wave speed and variance.
speed: { default: 1 },
speedVariance: { default: 2 },
// Material.
color: { default: '#7AD2F7', type: 'color' },
opacity: { default: 0.8 }
},
/**
* Use play() instead of init(), because component mappings – unavailable as dependencies – are
* not guaranteed to have parsed when this component is initialized.
*/
play: function () {
const el = this.el;
const data = this.data;
let material = el.components.material;
let geometry = new THREE.PlaneGeometry(data.width, data.depth, data.density, data.density);
// geometry.mergeVertices(); #OLD
geometry = THREE.BufferGeometryUtils.mergeVertices(geometry);
this.waves = [];
// for (let v, i = 0, l = geometry.vertices.length; i < l; i++) { #OLD
for (let v, i = 0, l = geometry.attributes.position.count; i < l; i++) {
// v = geometry.vertices[i]; #OLD
v = geometry.attributes.position;
this.waves.push({
// z: v.z, #OLD
z: v.getZ(i),
ang: Math.random() * Math.PI * 2,
amp: data.amplitude + Math.random() * data.amplitudeVariance,
speed: (data.speed + Math.random() * data.speedVariance) / 1000 // radians / frame
});
}
if (!material) {
material = {};
material.material = new THREE.MeshPhongMaterial({
color: data.color,
transparent: data.opacity < 1,
opacity: data.opacity,
flatShading: true
});
}
this.mesh = new THREE.Mesh(geometry, material.material);
el.setObject3D('mesh', this.mesh);
},
remove: function () {
this.el.removeObject3D('mesh');
},
tick: function (t, dt) {
if (!dt) return;
// const verts = this.mesh.geometry.vertices; #OLD
const verts = this.mesh.geometry.attributes.position.array;
// for (let v, vprops, i = 0; (v = verts[i]); i++) { #OLD
for (let i = 0, j = 2; i < this.waves.length; i++, j = j + 3) {
const vprops = this.waves[i];
// v.z = vprops.z + Math.sin(vprops.ang) * vprops.amp; #OLD
verts[j] = vprops.z + Math.sin(vprops.ang) * vprops.amp;
vprops.ang += vprops.speed * dt;
}
// this.mesh.geometry.verticesNeedUpdate = true; #OLD
this.mesh.geometry.attributes.position.needsUpdate = true;
}
}); |
Does this pull request look right? #352 |
I opened a PR to revert the code changes that I made to Ocean, so that you can at least see what changes I made, and test them. In hindsight I ought to have followed a more correct process of letting others preview and test the PR further before approving it. Please review the open PR to revert the changes I made to Ocean to see what was done last time, so you can advise on how to make further improvements. In addition I am also trying to fix navmesh so that it works in Aframe 1.2.0 Help with navmesh testing, and writing Feel free to read the commented code in each index file for details. I am trying to replace Three.Geometry which has been deleted from threejs with BufferGeometry. I could use some help testing this and writing this code, please remix the links and try to get it working also. In the meantime use Aframe 1.1.0 with A-Frame Extras until we get this fixed. |
Hi thanks. Please have a look at my post above - #348 (comment) from Feb 6 - I had already hacked together a version that works for me with A-FRAME 1.20. I commented the edits I made. However this is not production quality code and unfortunately I prefer to write my own components without the A-FRAME tooling, which prevents me to contribute more to "official" builds. Happy to help / test though - ideally from a compiled version in /dist. |
Your comment #348 is what I used to create the changes that you can see highlighted in the a-ocean "revert" PR I created to highlight my implementation of your suggestions. If the code is working there is no need to merge the revert PR. |
There is a newly discovered issue with the Aframe Physics System Cannon program, use the Ammo version instead for now. If you want to help fix it, please read and comment on the issue here n5ro/aframe-physics-system#189 |
i3 I want to ask you for help with your expertise on the differences between three.geometry and three.buffergeometry because obviously there is a lot more to change than just the word Buffer. As you demonstrated with your suggestions above. Quote: " // const verts = this.mesh.geometry.vertices; #OLD |
So actually I moved by trial and error, starting with a minimal scene only containing a <a-ocean> element, going back and forth between error messages, the three.js examples / documentation and stackoverflow until the ocean reappeared. I still don't know if the code is the correct way to do it therefore labelled "hacked together". I hope the three.js folks find a better way to introduce breaking changes like that. |
Wow there were lots of discussion here :) I fixed the ocean component in #387 |
I'll close this issue. If there are other components that needs fixing, this will be part of #395 |
Geometry
has been removed in three.js 125https://github.com/mrdoob/three.js/wiki/Migration-Guide
All components that rely on it have to be re-written using BufferGeometry instead.
The text was updated successfully, but these errors were encountered: