Jump to content

[SOLVED] Cant update vertices, need help!


trsh
 Share

Recommended Posts

The below code just makes the triangle disapear:

const app = new PIXI.Application();
document.body.appendChild(app.view);

const geometry = new PIXI.Geometry()
    .addAttribute('aVertexPosition', [-100, -50, 100, -50, 0, 100]);

const shader = PIXI.Shader.from(`

    precision mediump float;
    attribute vec2 aVertexPosition;

    uniform mat3 translationMatrix;
    uniform mat3 projectionMatrix;

    void main() {
        gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
    }`,

`precision mediump float;

    void main() {
        gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
    }

`);

const triangle = new PIXI.Mesh(geometry, shader);

triangle.position.set(400, 300);

app.stage.addChild(triangle);

const buffer = geometry.getBuffer('aVertexPosition');

app.ticker.add((delta) => {
    //triangle.rotation += 0.01;
  	buffer.update([-100, -50, 100, -50, 0, 140]);
});

 

Edited by trsh
Solved
Link to comment
Share on other sites

41 minutes ago, ivan.popelyshev said:

i think you have to use Float32Array in that case. Add `new Float32Array([...])` there. Alternative: change elements in existing array in buffer (buffer.data or buffer._data i dont remember) and then call update()

Yeah it requires new Float32Array in any case. Thank you!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...