SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

Add :textures array option to view.draw #393

Open AntonSynytsia opened 4 years ago

AntonSynytsia commented 4 years ago

It would be convenient to have a way to apply multiple textures to the triplets/polygons with a single call to view.draw. The { :textures => Array} option would suffice the request.

The textures array option is better than a single :texture option, which would limit to applying a single texture to the entire geometry of the mesh. With a single :texture option, in order to apply multiple textures, a user would have to break down the mesh into clusters and call view.draw for each cluster. So, a single :texture option would make it inconvenient and unnecessarily performance affecting.

A way to do this is to allow the user to pass an array of textures, through the :textures option, with each texture index mapping to the corresponding triplet/polygon passed. For example, if the user intends to call GL_TRIANGLES, they would pass the following:

view.draw(GL_TRIANGLES, [pt1, pt2, pt3, pt4, pt5, pt6], { :textures => [t1, t2] })

In the above snippet, t1 maps to the pt1, pt2, pt3 triplet; t2 maps to the pt4, pt5, pt6 triplet.

Now, if the user does not desire a texture for a triplet, they can simply pass -1, 0, or nil for the triplet index - up to the implementer.

The :textures option should be considered when openglenum argument for view.draw indicates triplets/polygons.

This feature would enhance the usability of view.draw.

thomthom commented 4 years ago

This is somewhat of a limitation of the graphic pipeline. Even internally we bulk up polygons of same material and draw them with separate calls.

Though, I guess it could be allowed as a utility abstraction...

Or maybe we provide a utility example that will perform the same thing. Might be more flexible to adapt for specific usage.