question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello! This is a feature request. I want to be able to optionally feed my VBO to three.js BufferAttribute. I walked through some (three.js) code and couldn’t find any way to do so (from outside).

In previous versions of three.js I was able to hack into renderer.properties to replace VBO with my custom one. However, after an upgrade to r86 three’s VBO are stored in WebGLAttributes module which is not exposed. Since now the storage is hidden from the outside, I can no longer hack into it from my external codes. Therefore I want to legalize such behavior, to prevent further struggles and hacks.

An example of what I might do with it is following:

	const geo = new THREE.BufferGeometry();
	geo.setDrawRange( 0, REAL_SIZE );
	// ...
	const ba = new THREE.BufferAttribute(_dummyArray, 3);
	ba.count = REAL_SIZE * 3;
	geo.setDrawRange( 0, REAL_SIZE );

	// HERE! set buffer-creator callback
	ba.onCreateCallback = function () {
		// I create it just for example, actually it can come from other lib
		const vertices = [];
		for ( i = 0; i < REAL_SIZE; i ++ ) {
			vertices.push( Math.random() * 2000 - 1000 );
			vertices.push( Math.random() * 2000 - 1000 );
			vertices.push( Math.random() * 2000 - 1000 );
		}
		const vbo = gl.createBuffer();
		gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
		gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
		// Return back to three.js
		return vbo;
	};

	geo.addAttribute('position', ba);
	// ...
	particles = new THREE.Points( geo, materials[0] );
	scene.add( particles );

More of it you can see here.

To summarize: sometimes you end up with preallocated GL buffer and a lack of an ability to use it in three.js BufferGeometry, where it would fit perflectly.

If it sounds reasonable, then I can also show an example of a patch, that makes the above code work:

		var buffer;

		if (attribute.onCreateCallback) {

			buffer = attribute.onCreateCallback();

		} else {

			buffer = gl.createBuffer();

			gl.bindBuffer( bufferType, buffer );
			gl.bufferData( bufferType, array, usage );

		}

		attribute.onUploadCallback();

Just add the condition to see if there is user-defined buffer-creator callback. In WebGLAttributes.js, that’s all I need.

If you want me to give more specific reasons for what I do with my buffers, I’ll be glad to answer. I can then create a PR with the above changes, if it makes sense.

Three.js version
  • r86+
Browser
  • All of them
  • Even more than that
OS
  • All of them

Thanks for your time! 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mrdoobcommented, Feb 1, 2018

Instead of trying to hack BufferAttribute… What about an API like this?

var positions = new THREE.GLBufferAttribute( function ( gl ) {

	const vertices = [];

	for ( i = 0; i < REAL_SIZE; i ++ ) {
		vertices.push( Math.random() * 2000 - 1000 );
		vertices.push( Math.random() * 2000 - 1000 );
		vertices.push( Math.random() * 2000 - 1000 );
	}

	const vbo = gl.createBuffer();
	gl.bindBuffer( gl.ARRAY_BUFFER, vbo );
	gl.bufferData( gl.ARRAY_BUFFER, new Float32Array( vertices ), gl.STATIC_DRAW );
	return vbo;

} );
geometry.addAttribute( 'position', positions );
0reactions
Mugen87commented, Dec 17, 2020

Solved via #13196.

Read more comments on GitHub >

github_iconTop Results From Across the Web

External Events - VBO Tickets Support
The external event setting allows events not sold through VBO Tickets to be listed in your events plugin but re-directs users to the...
Read more >
Using JSON VBO | Blue Prism Product
I am using a REST Web service to use an api and I can't seem to use the JSON VBO ... -discussion/general-discussion/consuming-external-rest-web-services ...
Read more >
Using VBO with external database [#3130763] | Drupal.org
I managed to create a view with data coming from an external database. I wanted to add an VBO field but it seems...
Read more >
External video for Circuit Tools VBO files - Page 2 - RaceChrono
Automating the data/video sync should be a major help to anyone using Circuit Tools. CT is pretty resource-intensive while dealing with video, ...
Read more >
Manage Your Blue Prism Process by using Blue Prism Plugin ...
2. Object Studio - Almost all the enterprises need to have communication with external applications to automate tasks. Since it cannot happen in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found