The Wayback Machine - https://web.archive.org/web/20200225151227/https://github.com/mrdoob/three.js/issues/16401
Skip to content
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

Expose 'attributes' and 'geometries' from WebGLRenderer #16401

Open
evodabas opened this issue May 8, 2019 · 12 comments
Open

Expose 'attributes' and 'geometries' from WebGLRenderer #16401

evodabas opened this issue May 8, 2019 · 12 comments

Comments

@evodabas
Copy link

@evodabas evodabas commented May 8, 2019

If I add these two lines to WebGLRenderer.initGLContext

	_this.attributes = attributes;
	_this.geometries = geometries;

Then I can do this to grab the underlying WebGL vertex and index buffers for my BufferGeometry and populate them from external WebGL code.

            var bufferGeometry = new THREE.BufferGeometry();
            bufferGeometry.setIndex([]);
            bufferGeometry.addAttribute( 'position', new THREE.Float32BufferAttribute([], 3));            
            bufferGeometry.addAttribute( 'normal', new THREE.Float32BufferAttribute([], 3));            
            bufferGeometry.addAttribute( 'uv', new THREE.Uint16BufferAttribute([], 2, true));

            renderer.geometries.update(bufferGeometry);
            var posBuf = renderer.attributes.get(bufferGeometry.attributes['position']).buffer;
            var norBuf = renderer.attributes.get(bufferGeometry.attributes['normal']).buffer;            
            var uvBuf = renderer.attributes.get(bufferGeometry.attributes['uv']).buffer;
            var indexBuf = renderer.attributes.get(bufferGeometry.index).buffer;

Is this a change you guys would consider taking? This is with the goal of getting volumetric video content playing inside of THREE.js scenes.

Thanks!
Evan

@Mugen87

This comment has been minimized.

Copy link
Collaborator

@Mugen87 Mugen87 commented May 8, 2019

Then I can do this to grab the underlying WebGL vertex and index buffers for my BufferGeometry and populate them from external WebGL code.

Would it be very inconvenient for you to populate data to the BufferGeometry instead? It might be easier to evaluate this issue if you can explain your workflow in more detail.

@evodabas

This comment has been minimized.

Copy link
Author

@evodabas evodabas commented May 8, 2019

The geometry is animated at 30 FPS, which is updated on the GPU with WebGL transform feedback. Directly populating the BufferGeometry object would mean round-tripping to CPU memory and back right?

Pretty much we have an existing WebGL component that can interface with a native WebGL application: the application gives us their buffer handles, we populate them on each tick with the animated geometry. We're hoping to build a THREE.js integration now to let users build more rich experiences with THREE.js and our volumetric video content.

@Mugen87

This comment has been minimized.

Copy link
Collaborator

@Mugen87 Mugen87 commented May 9, 2019

Wouldn't exposing attributes already be sufficient? What would you do with geometries?

@evodabas

This comment has been minimized.

Copy link
Author

@evodabas evodabas commented May 9, 2019

Well I found that I need to call:

renderer.geometries.update(bufferGeometry);

To get the attributes initialized, otherwise all the attributes.get calls in the code snippet above return null. If there's another way to get the attributes populated though I'd happily use that instead 😄

@Mugen87

This comment has been minimized.

Copy link
Collaborator

@Mugen87 Mugen87 commented May 10, 2019

Would something like #11883 solve your problem, too? Also check out the respective PR #13196

@evodabas

This comment has been minimized.

Copy link
Author

@evodabas evodabas commented May 10, 2019

That looks pretty good. Index buffers are just another BufferAttribute right so I'd be able to use a GLBufferAttribute for my indices too? I'll try to modify my project to work with that branch and see if I run into any issues.

@Mugen87

This comment has been minimized.

Copy link
Collaborator

@Mugen87 Mugen87 commented May 10, 2019

Index buffers are just another BufferAttribute right so I'd be able to use a GLBufferAttribute for my indices too?

I think so.

I'll try to modify my project to work with that branch and see if I run into any issues.

That would be good to know 👍 .

@evodabas

This comment has been minimized.

Copy link
Author

@evodabas evodabas commented May 10, 2019

OK I grabbed raub's fork and modified my code to use GLBufferAttribute instead of my hacked access to the attributes and geometries lookups, everything seems to work fine.

It would be nice if the GLBufferAttribute constructor could take a normalized parameter like BufferAttribute does, but setting it directly on the attribute after creation also seems to work:

            var uvAtt = new THREE.GLBufferAttribute(gl, uvBuf, gl.UNSIGNED_SHORT, 2, 0);
            uvAtt.normalized = true;
            bufferGeometry.addAttribute( 'uv', uvAtt);
@Mugen87

This comment has been minimized.

Copy link
Collaborator

@Mugen87 Mugen87 commented May 11, 2019

It would be nice if the GLBufferAttribute constructor could take a normalized parameter like BufferAttribute does

That's true.

@mrdoob Do you think it's worth to add GLBufferAttribute to the library? It seems there are some scenarios where a more flexibel version of BufferAttribute is helpful to users.

@pvaananen

This comment has been minimized.

Copy link

@pvaananen pvaananen commented May 30, 2019

I just wanted to chip in and say this feature is exactly what I need :) We stream geometry in chunks and doing the roundtrip through BufferGeometry really is a pain. The GLBufferAttribute of #13196 also looks pretty good, so that would be totally OK too.

@raub

This comment has been minimized.

Copy link

@raub raub commented Aug 9, 2019

@evodabas I've added the normalized param in 9ba4d01

@evodabas

This comment has been minimized.

Copy link
Author

@evodabas evodabas commented Aug 9, 2019

Nice 👍 What's the status of this feature overall, are there plans for #13196 to make it into a release anytime soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.