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.

Add `DrawGeometry` function to WebGLRenderer

See original GitHub issue

Hello! THREE provides a really nice, quick approach for setting up a scene but there are times when the default render path isn’t ideal. I want to propose adding a function like DrawGeometry to the WebGLRenderer API.

WebGLRenderer.DrawGeometry(<Geometry|BufferGeometry>, <Material>, <Matrix4>, <Camera>, <Scene>, <RenderTarget>, <Options>)

Draws the geometry to the render target immediately.

Geometry|BufferGeometry

The geometry to render.

Material

The material to render with.

Matrix4

The world matrix to transform the geometry.

Camera

The camera to render with.

Scene

The scene to render in the context of (for lighting, fog, etc).

RenderTarget

The target to render to.

Options

A set of draw options including things like frustumCulled.

Use Cases

At a high level this would afford more flexibility to create custom render paths to suit different types of optimizations and scene complexity.

  • In cases where you’re dealing with tens or hundreds of thousands of meshes in a scene it can be beneficial to save transform information in a minimal representation to save memory (an array of matrices, for example). This can’t be done all the easily at the moment because THREE requires Object3Ds and Meshes to render.
  • If a set of visible geometry is already known (through a custom octree frustum culling implementation or precomputed visible sets) there’s no reason to have THREE iterate over all geometry in the scene and it can be much slower to do so. This lets you control what gets drawn and iterated over.
  • Some effects are just convenient to implement with a custom draw and don’t need an object in the scene hierarchy.
  • You may want to draw for only X milliseconds during a frame – this would let you measure how long you’ve spent drawing so far.

In a couple of these cases the solution at the moment is to remove everything (or almost everything) from the scene and rebuild it specifically so THREE doesn’t doesn’t spend time iterating over everything, which can take time in itself.

Thoughts?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
gkjohnsoncommented, Mar 26, 2021

Some other PRs I’ve submitted that I think are more in line with three.js patterns will address the issues I originally created this for which I’m hoping can be revisited once JSM and ES6 conversion have been addressed. I will open a new issue if this becomes a need again.

Thanks!

2reactions
gkjohnsoncommented, Jul 17, 2018

Yeah I think that’s some of the same problem I’m having, as well. But I don’t think you should have to manually call objects.update( object ) to perform a draw. This is what I noticed when looking over the renderer code, some of which you mentioned:

I’d be interested in updating the renderer to allow for the types of operations I’m talking about. I understand that some or a lot of what I mentioned is there for the sake of optimization. Does this belong in a new function? Would any of this be affected by the new WebGL2Renderer?

Thoughts @mugen87? @mrdoob?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebGLRenderer – three.js docs
A canvas where the renderer draws its output. This is automatically created by the renderer in the constructor (if not provided already); you...
Read more >
WebGLRenderer() and Canvas - three.js - Stack Overflow
Here is my code : At this point, in the code the renderer is appended inside Canvas (search for : canvasObj.appendChild(renderer.domElement)) ...
Read more >
externalRenderers | ArcGIS Maps SDK for JavaScript 4.25
Transforms positions from the given spatial reference to the internal rendering coordinate system. more details, externalRenderers. Method Details. add(view, ...
Read more >
Getting started with the WebGL renderer | Three.js Cookbook
For your skeleton to work, you need to add the init function, which looks as follows: function init() { // create a scene,...
Read more >
three.WebGLRenderer JavaScript and Node.js code examples
How to use. WebGLRenderer. function ... domElement); // Add a light source!!! ... HemisphereLight(0xffffbb, 0x080820, 1); this.scene.add(light); ...
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