0

So I have a slider in my HTML with values ranging from 1 to 2. When I have the slider value set to 1, I want to set the coordinates of my wavefront to the one described by arrayMin and when the slider is set to 2, I want the coordinates of my wavefront to set to one described by arrayMin.

man is the name of the variable that I used to load the obj in threejs using OBJLoader.

function render(time)
    {

        let valueOfSlider = document.getElementById('mySlider').value
        scene.remove(man)
        if (valueOfSlider == 1){
                console.log("I want arrayMin to be set")
                man.children[0].geometry.attributes.position.array=Float32Array.from(arrayMin)
            }
        else
        {
                console.log("I want array Max to be set")
                man.children[0].geometry.attributes.position.array=Float32Array.from(arrayMax)

        }
        scene.add(man)
        controls.update()
        renderer.render(scene,camera)
        requestAnimationFrame(render)

    }

But it is not working. The image shows a screenshot of the log, which clearly shows there is no needsUpdate field

Community
  • 1
  • 1
aapap
  • 105
  • 14
  • Does it work if you use this code after updating the attribute data? `man.children[0].geometry.attributes.position.needsUpdate = true;`. Besides, it's better to reuse the existing typed array instead of overwriting it. – Mugen87 Jun 01 '20 at 18:19
  • @Mugen87 I checked, there is no "man.children[0].geometry.attributes.position.needsUpdate" that I can set to true; – aapap Jun 02 '20 at 02:06
  • Every instance of `BufferAttribute` has a property [needsUpdate](https://threejs.org/docs/index.html#api/en/core/BufferAttribute.needsUpdate). If you don't set it to true, the new buffer data won't be uploaded to the GPU. – Mugen87 Jun 02 '20 at 09:00
  • @Mugen87, the position is a Float32BufferAttribute and secondly even a BufferAttribute has no needsUpdate, as can be seen in the image in the edited picture. – aapap Jun 02 '20 at 09:40
  • `needsUpdate` is defined on `prototype` level: https://github.com/mrdoob/three.js/blob/d43cbd6cc464ca6ccc70fb6cf6392de9f6a5bfef/src/core/BufferAttribute.js#L35. – Mugen87 Jun 02 '20 at 11:08
  • Oh yes, I found it and it works! Heartfelt thank you to @Mugen87 . Cheers – aapap Jun 02 '20 at 11:23

1 Answers1

0

The first comment worked, i.e., setting needsUpdate as true;

aapap
  • 105
  • 14