What is the most efficient way in three.js to update a face color independently across many meshes that all share the same geometry? -
in three.js project (viewable here) have 500 cubes, of same size , statically positioned. on each of these cubes, 5 of faces remain same color; however, color of sixth face can dynamically updated, , modification occurs across many of cubes in single frame , occurs across frames.
i've been able implement scene several different ways, have not been satisfied performance of i've tried. know must not have hit upon right technique yet or maybe i'm not implementing 1 quite right. performance standpoint, best way change color of these cube faces while maintaining independence across each of cubes?
here have tried far:
create 500 individual cubegeometry , mesh instances. change color of geometry face described in answer here: change colors of cube's faces. far method has performed best me, 500 identical geometries seems less ideal, because i'm not able achieve regular 60fps gpu. rendering takes 11-20ms here.
create 1 cubegeometry , use across 500 mesh instances. create array of meshbasicmaterials create meshfacematerial each mesh. 5 of meshbasicmaterial instances same, representing 5 statically colored sides of each cube. create unique meshbasicmaterial add meshfacematerial each mesh. update color of unique material thismesh.material.materials[3].uniforms.diffuse.value.copy(newcolor). method renders quite slower first method, 90-110ms, seems surprising me. maybe it's because 500 cubes 6 materials each = 3000 materials process???
any advice can offer appreciated!
i discovered three.js performs webgl draw each mesh in scene, , hurting performance. looked yaku's suggestion of using buffergeometry, i'm sure great route, using buffergeometry appears relatively difficult unless have amount of experience webgl/opengl.
however, came across alternative solution incredibly effective. still created individual meshes each of 500 cubes, used geometryutils.merge() merge each of meshes generic geometry represent entire group of cubes. used group geometry create group mesh. explanation of geometryutils.merge() here.
what's nice tactic still have access faces part of underlying geometries/meshes merge. in project, allowed me still have full control on face colors wanted control over:
// 500 merged cubes, there 3000 faces in geometry. // code fourth face (index 3) of cube. _mergedcubesmesh.geometry.faces[(cubeidx * 6) + 3].color
Comments
Post a Comment