Three.js: matrix4().applyToBufferAttribute() not working

Created on 31 Oct 2017  路  3Comments  路  Source: mrdoob/three.js

Description of the problem

I dont seem to detect a change in array when i apply a matrix to the array.

var test = new THREE.BoxBufferGeometry(2, 2, 2).attributes.position.array.slice(0);
console.log(test)
var test1 = new THREE.Matrix4().makeTranslation(3, 3, 3).applyToBufferAttribute(test);
console.log(test1, test);

http://jsfiddle.net/xgf1v2L5/

Three.js version
  • [ ] Dev
  • [x ] r84
  • [ ] ...
Browser
  • [ ] All of them
  • [x ] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [x] All of them
  • [ ] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS
Hardware Requirements (graphics card, VR Device, ...)

Most helpful comment

Data in a buffers are not always organized in a straightforward sequence. They can have different layouts like e.g. interleaved buffers. Working with buffer attributes provide a thin abstraction over these "low-level" implementation details.

All 3 comments

Pass attribute, not array, to .applyToBufferAttribute.

var test = new THREE.BoxBufferGeometry(2, 2, 2).attributes.position;
console.log(test.array)
var test1 = new THREE.Matrix4().makeTranslation(3, 3, 3).applyToBufferAttribute(test);
console.log(test1.array);

Float32Array(72) [1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, -1, -1]
Float32Array(72) [4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 2, 2, 2, 4, 2, 2, 4, 4, 2, 2, 2, 2, 2, 4, 2, 4, 2, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 4, 2, 2, 2, 4, 2, 2, 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 4, 4, 4, 2, 2, 4, 2, 4, 2, 2, 2, 2, 2]

@takahirox @Mugen87
That makes sense is there a reason why it doesn't take the array only? Seems like there is some overhead in the attribute object when all we really need is the array to be modified. Way better than geometry.applyMatrix, but still not as slim as possible? Thank you for the help.

Data in a buffers are not always organized in a straightforward sequence. They can have different layouts like e.g. interleaved buffers. Working with buffer attributes provide a thin abstraction over these "low-level" implementation details.

Was this page helpful?
0 / 5 - 0 ratings