MeshRenderer.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. THREE.WebGLRenderer.MeshRenderer = function ( lowlevelrenderer, info ) {
  2. THREE.WebGLRenderer.Object3DRenderer.call( this, lowlevelrenderer, info );
  3. };
  4. THREE.WebGLRenderer.MeshRenderer.prototype = Object.create( THREE.WebGLRenderer.Object3DRenderer.prototype );
  5. THREE.extend( THREE.WebGLRenderer.MeshRenderer.prototype, {
  6. createBuffers: function ( geometryGroup ) {
  7. var renderer = this.renderer;
  8. geometryGroup.__webglVertexBuffer = renderer.createBuffer();
  9. geometryGroup.__webglNormalBuffer = renderer.createBuffer();
  10. geometryGroup.__webglTangentBuffer = renderer.createBuffer();
  11. geometryGroup.__webglColorBuffer = renderer.createBuffer();
  12. geometryGroup.__webglUVBuffer = renderer.createBuffer();
  13. geometryGroup.__webglUV2Buffer = renderer.createBuffer();
  14. geometryGroup.__webglSkinIndicesBuffer = renderer.createBuffer();
  15. geometryGroup.__webglSkinWeightsBuffer = renderer.createBuffer();
  16. geometryGroup.__webglFaceBuffer = renderer.createBuffer();
  17. geometryGroup.__webglLineBuffer = renderer.createBuffer();
  18. var m, ml;
  19. if ( geometryGroup.numMorphTargets ) {
  20. geometryGroup.__webglMorphTargetsBuffers = [];
  21. for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
  22. geometryGroup.__webglMorphTargetsBuffers.push( renderer.createBuffer() );
  23. }
  24. }
  25. if ( geometryGroup.numMorphNormals ) {
  26. geometryGroup.__webglMorphNormalsBuffers = [];
  27. for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
  28. geometryGroup.__webglMorphNormalsBuffers.push( renderer.createBuffer() );
  29. }
  30. }
  31. this.info.memory.geometries ++;
  32. },
  33. initBuffers: function ( geometryGroup, object ) {
  34. var geometry = object.geometry,
  35. faces3 = geometryGroup.faces3,
  36. faces4 = geometryGroup.faces4,
  37. nvertices = faces3.length * 3 + faces4.length * 4,
  38. ntris = faces3.length * 1 + faces4.length * 2,
  39. nlines = faces3.length * 3 + faces4.length * 4,
  40. material = this.getBufferMaterial( object, geometryGroup ),
  41. uvType = this.bufferGuessUVType( material ),
  42. normalType = this.bufferGuessNormalType( material ),
  43. vertexColorType = this.bufferGuessVertexColorType( material );
  44. //console.log( "uvType", uvType, "normalType", normalType, "vertexColorType", vertexColorType, object, geometryGroup, material );
  45. geometryGroup.__vertexArray = new Float32Array( nvertices * 3 );
  46. if ( normalType ) {
  47. geometryGroup.__normalArray = new Float32Array( nvertices * 3 );
  48. }
  49. if ( geometry.hasTangents ) {
  50. geometryGroup.__tangentArray = new Float32Array( nvertices * 4 );
  51. }
  52. if ( vertexColorType ) {
  53. geometryGroup.__colorArray = new Float32Array( nvertices * 3 );
  54. }
  55. if ( uvType ) {
  56. if ( geometry.faceUvs.length > 0 || geometry.faceVertexUvs.length > 0 ) {
  57. geometryGroup.__uvArray = new Float32Array( nvertices * 2 );
  58. }
  59. if ( geometry.faceUvs.length > 1 || geometry.faceVertexUvs.length > 1 ) {
  60. geometryGroup.__uv2Array = new Float32Array( nvertices * 2 );
  61. }
  62. }
  63. if ( object.geometry.skinWeights.length && object.geometry.skinIndices.length ) {
  64. geometryGroup.__skinIndexArray = new Float32Array( nvertices * 4 );
  65. geometryGroup.__skinWeightArray = new Float32Array( nvertices * 4 );
  66. }
  67. geometryGroup.__faceArray = new Uint16Array( ntris * 3 );
  68. geometryGroup.__lineArray = new Uint16Array( nlines * 2 );
  69. var m, ml;
  70. if ( geometryGroup.numMorphTargets ) {
  71. geometryGroup.__morphTargetsArrays = [];
  72. for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
  73. geometryGroup.__morphTargetsArrays.push( new Float32Array( nvertices * 3 ) );
  74. }
  75. }
  76. if ( geometryGroup.numMorphNormals ) {
  77. geometryGroup.__morphNormalsArrays = [];
  78. for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
  79. geometryGroup.__morphNormalsArrays.push( new Float32Array( nvertices * 3 ) );
  80. }
  81. }
  82. geometryGroup.__webglFaceCount = ntris * 3;
  83. geometryGroup.__webglLineCount = nlines * 2;
  84. // custom attributes
  85. if ( material.attributes ) {
  86. if ( geometryGroup.__webglCustomAttributesList === undefined ) {
  87. geometryGroup.__webglCustomAttributesList = [];
  88. }
  89. for ( var a in material.attributes ) {
  90. // Do a shallow copy of the attribute object so different geometryGroup chunks use different
  91. // attribute buffers which are correctly indexed in the setMeshBuffers function
  92. var originalAttribute = material.attributes[ a ];
  93. var attribute = {};
  94. for ( var property in originalAttribute ) {
  95. attribute[ property ] = originalAttribute[ property ];
  96. }
  97. if ( !attribute.__webglInitialized || attribute.createUniqueBuffers ) {
  98. attribute.__webglInitialized = true;
  99. var size = 1; // "f" and "i"
  100. if( attribute.type === "v2" ) size = 2;
  101. else if( attribute.type === "v3" ) size = 3;
  102. else if( attribute.type === "v4" ) size = 4;
  103. else if( attribute.type === "c" ) size = 3;
  104. attribute.size = size;
  105. attribute.array = new Float32Array( nvertices * size );
  106. attribute.buffer = this.renderer.createBuffer();
  107. attribute.buffer.belongsToAttribute = a;
  108. originalAttribute.needsUpdate = true;
  109. attribute.__original = originalAttribute;
  110. }
  111. geometryGroup.__webglCustomAttributesList.push( attribute );
  112. }
  113. }
  114. geometryGroup.__inittedArrays = true;
  115. },
  116. setBuffers: function ( geometryGroup, object, dispose, material ) {
  117. if ( ! geometryGroup.__inittedArrays ) {
  118. return;
  119. }
  120. var renderer = this.renderer;
  121. var normalType = this.bufferGuessNormalType( material ),
  122. vertexColorType = this.bufferGuessVertexColorType( material ),
  123. uvType = this.bufferGuessUVType( material ),
  124. needsSmoothNormals = ( normalType === THREE.SmoothShading );
  125. var f, fl, fi, face,
  126. vertexNormals, faceNormal, normal,
  127. vertexColors, faceColor,
  128. vertexTangents,
  129. uv, uv2, v1, v2, v3, v4, t1, t2, t3, t4, n1, n2, n3, n4,
  130. c1, c2, c3, c4,
  131. sw1, sw2, sw3, sw4,
  132. si1, si2, si3, si4,
  133. sa1, sa2, sa3, sa4,
  134. sb1, sb2, sb3, sb4,
  135. m, ml, i, il,
  136. vn, uvi, uv2i,
  137. vk, vkl, vka,
  138. nka, chf, faceVertexNormals,
  139. a,
  140. vertexIndex = 0,
  141. offset = 0,
  142. offset_uv = 0,
  143. offset_uv2 = 0,
  144. offset_face = 0,
  145. offset_normal = 0,
  146. offset_tangent = 0,
  147. offset_line = 0,
  148. offset_color = 0,
  149. offset_skin = 0,
  150. offset_morphTarget = 0,
  151. offset_custom = 0,
  152. offset_customSrc = 0,
  153. value,
  154. vertexArray = geometryGroup.__vertexArray,
  155. uvArray = geometryGroup.__uvArray,
  156. uv2Array = geometryGroup.__uv2Array,
  157. normalArray = geometryGroup.__normalArray,
  158. tangentArray = geometryGroup.__tangentArray,
  159. colorArray = geometryGroup.__colorArray,
  160. skinIndexArray = geometryGroup.__skinIndexArray,
  161. skinWeightArray = geometryGroup.__skinWeightArray,
  162. morphTargetsArrays = geometryGroup.__morphTargetsArrays,
  163. morphNormalsArrays = geometryGroup.__morphNormalsArrays,
  164. customAttributes = geometryGroup.__webglCustomAttributesList,
  165. customAttribute,
  166. faceArray = geometryGroup.__faceArray,
  167. lineArray = geometryGroup.__lineArray,
  168. geometry = object.geometry, // this is shared for all chunks
  169. dirtyVertices = geometry.verticesNeedUpdate,
  170. dirtyElements = geometry.elementsNeedUpdate,
  171. dirtyUvs = geometry.uvsNeedUpdate,
  172. dirtyNormals = geometry.normalsNeedUpdate,
  173. dirtyTangents = geometry.tangentsNeedUpdate,
  174. dirtyColors = geometry.colorsNeedUpdate,
  175. dirtyMorphTargets = geometry.morphTargetsNeedUpdate,
  176. vertices = geometry.vertices,
  177. chunk_faces3 = geometryGroup.faces3,
  178. chunk_faces4 = geometryGroup.faces4,
  179. obj_faces = geometry.faces,
  180. obj_uvs = geometry.faceVertexUvs[ 0 ],
  181. obj_uvs2 = geometry.faceVertexUvs[ 1 ],
  182. obj_colors = geometry.colors,
  183. obj_skinIndices = geometry.skinIndices,
  184. obj_skinWeights = geometry.skinWeights,
  185. morphTargets = geometry.morphTargets,
  186. morphNormals = geometry.morphNormals;
  187. if ( dirtyVertices ) {
  188. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  189. face = obj_faces[ chunk_faces3[ f ] ];
  190. v1 = vertices[ face.a ];
  191. v2 = vertices[ face.b ];
  192. v3 = vertices[ face.c ];
  193. vertexArray[ offset ] = v1.x;
  194. vertexArray[ offset + 1 ] = v1.y;
  195. vertexArray[ offset + 2 ] = v1.z;
  196. vertexArray[ offset + 3 ] = v2.x;
  197. vertexArray[ offset + 4 ] = v2.y;
  198. vertexArray[ offset + 5 ] = v2.z;
  199. vertexArray[ offset + 6 ] = v3.x;
  200. vertexArray[ offset + 7 ] = v3.y;
  201. vertexArray[ offset + 8 ] = v3.z;
  202. offset += 9;
  203. }
  204. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  205. face = obj_faces[ chunk_faces4[ f ] ];
  206. v1 = vertices[ face.a ];
  207. v2 = vertices[ face.b ];
  208. v3 = vertices[ face.c ];
  209. v4 = vertices[ face.d ];
  210. vertexArray[ offset ] = v1.x;
  211. vertexArray[ offset + 1 ] = v1.y;
  212. vertexArray[ offset + 2 ] = v1.z;
  213. vertexArray[ offset + 3 ] = v2.x;
  214. vertexArray[ offset + 4 ] = v2.y;
  215. vertexArray[ offset + 5 ] = v2.z;
  216. vertexArray[ offset + 6 ] = v3.x;
  217. vertexArray[ offset + 7 ] = v3.y;
  218. vertexArray[ offset + 8 ] = v3.z;
  219. vertexArray[ offset + 9 ] = v4.x;
  220. vertexArray[ offset + 10 ] = v4.y;
  221. vertexArray[ offset + 11 ] = v4.z;
  222. offset += 12;
  223. }
  224. renderer.setDynamicArrayBuffer( geometryGroup.__webglVertexBuffer, vertexArray);
  225. }
  226. if ( dirtyMorphTargets ) {
  227. for ( vk = 0, vkl = morphTargets.length; vk < vkl; vk ++ ) {
  228. offset_morphTarget = 0;
  229. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  230. chf = chunk_faces3[ f ];
  231. face = obj_faces[ chf ];
  232. // morph positions
  233. v1 = morphTargets[ vk ].vertices[ face.a ];
  234. v2 = morphTargets[ vk ].vertices[ face.b ];
  235. v3 = morphTargets[ vk ].vertices[ face.c ];
  236. vka = morphTargetsArrays[ vk ];
  237. vka[ offset_morphTarget ] = v1.x;
  238. vka[ offset_morphTarget + 1 ] = v1.y;
  239. vka[ offset_morphTarget + 2 ] = v1.z;
  240. vka[ offset_morphTarget + 3 ] = v2.x;
  241. vka[ offset_morphTarget + 4 ] = v2.y;
  242. vka[ offset_morphTarget + 5 ] = v2.z;
  243. vka[ offset_morphTarget + 6 ] = v3.x;
  244. vka[ offset_morphTarget + 7 ] = v3.y;
  245. vka[ offset_morphTarget + 8 ] = v3.z;
  246. // morph normals
  247. if ( material.morphNormals ) {
  248. if ( needsSmoothNormals ) {
  249. faceVertexNormals = morphNormals[ vk ].vertexNormals[ chf ];
  250. n1 = faceVertexNormals.a;
  251. n2 = faceVertexNormals.b;
  252. n3 = faceVertexNormals.c;
  253. } else {
  254. n1 = morphNormals[ vk ].faceNormals[ chf ];
  255. n2 = n1;
  256. n3 = n1;
  257. }
  258. nka = morphNormalsArrays[ vk ];
  259. nka[ offset_morphTarget ] = n1.x;
  260. nka[ offset_morphTarget + 1 ] = n1.y;
  261. nka[ offset_morphTarget + 2 ] = n1.z;
  262. nka[ offset_morphTarget + 3 ] = n2.x;
  263. nka[ offset_morphTarget + 4 ] = n2.y;
  264. nka[ offset_morphTarget + 5 ] = n2.z;
  265. nka[ offset_morphTarget + 6 ] = n3.x;
  266. nka[ offset_morphTarget + 7 ] = n3.y;
  267. nka[ offset_morphTarget + 8 ] = n3.z;
  268. }
  269. //
  270. offset_morphTarget += 9;
  271. }
  272. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  273. chf = chunk_faces4[ f ];
  274. face = obj_faces[ chf ];
  275. // morph positions
  276. v1 = morphTargets[ vk ].vertices[ face.a ];
  277. v2 = morphTargets[ vk ].vertices[ face.b ];
  278. v3 = morphTargets[ vk ].vertices[ face.c ];
  279. v4 = morphTargets[ vk ].vertices[ face.d ];
  280. vka = morphTargetsArrays[ vk ];
  281. vka[ offset_morphTarget ] = v1.x;
  282. vka[ offset_morphTarget + 1 ] = v1.y;
  283. vka[ offset_morphTarget + 2 ] = v1.z;
  284. vka[ offset_morphTarget + 3 ] = v2.x;
  285. vka[ offset_morphTarget + 4 ] = v2.y;
  286. vka[ offset_morphTarget + 5 ] = v2.z;
  287. vka[ offset_morphTarget + 6 ] = v3.x;
  288. vka[ offset_morphTarget + 7 ] = v3.y;
  289. vka[ offset_morphTarget + 8 ] = v3.z;
  290. vka[ offset_morphTarget + 9 ] = v4.x;
  291. vka[ offset_morphTarget + 10 ] = v4.y;
  292. vka[ offset_morphTarget + 11 ] = v4.z;
  293. // morph normals
  294. if ( material.morphNormals ) {
  295. if ( needsSmoothNormals ) {
  296. faceVertexNormals = morphNormals[ vk ].vertexNormals[ chf ];
  297. n1 = faceVertexNormals.a;
  298. n2 = faceVertexNormals.b;
  299. n3 = faceVertexNormals.c;
  300. n4 = faceVertexNormals.d;
  301. } else {
  302. n1 = morphNormals[ vk ].faceNormals[ chf ];
  303. n2 = n1;
  304. n3 = n1;
  305. n4 = n1;
  306. }
  307. nka = morphNormalsArrays[ vk ];
  308. nka[ offset_morphTarget ] = n1.x;
  309. nka[ offset_morphTarget + 1 ] = n1.y;
  310. nka[ offset_morphTarget + 2 ] = n1.z;
  311. nka[ offset_morphTarget + 3 ] = n2.x;
  312. nka[ offset_morphTarget + 4 ] = n2.y;
  313. nka[ offset_morphTarget + 5 ] = n2.z;
  314. nka[ offset_morphTarget + 6 ] = n3.x;
  315. nka[ offset_morphTarget + 7 ] = n3.y;
  316. nka[ offset_morphTarget + 8 ] = n3.z;
  317. nka[ offset_morphTarget + 9 ] = n4.x;
  318. nka[ offset_morphTarget + 10 ] = n4.y;
  319. nka[ offset_morphTarget + 11 ] = n4.z;
  320. }
  321. //
  322. offset_morphTarget += 12;
  323. }
  324. this.renderer.setDynamicArrayBuffer( geometryGroup.__webglMorphTargetsBuffers[ vk ], morphTargetsArrays[ vk ]);
  325. if ( material.morphNormals ) {
  326. this.renderer.setDynamicArrayBuffer( geometryGroup.__webglMorphNormalsBuffers[ vk ], morphNormalsArrays[ vk ]);
  327. }
  328. }
  329. }
  330. if ( obj_skinWeights.length ) {
  331. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  332. face = obj_faces[ chunk_faces3[ f ] ];
  333. // weights
  334. sw1 = obj_skinWeights[ face.a ];
  335. sw2 = obj_skinWeights[ face.b ];
  336. sw3 = obj_skinWeights[ face.c ];
  337. skinWeightArray[ offset_skin ] = sw1.x;
  338. skinWeightArray[ offset_skin + 1 ] = sw1.y;
  339. skinWeightArray[ offset_skin + 2 ] = sw1.z;
  340. skinWeightArray[ offset_skin + 3 ] = sw1.w;
  341. skinWeightArray[ offset_skin + 4 ] = sw2.x;
  342. skinWeightArray[ offset_skin + 5 ] = sw2.y;
  343. skinWeightArray[ offset_skin + 6 ] = sw2.z;
  344. skinWeightArray[ offset_skin + 7 ] = sw2.w;
  345. skinWeightArray[ offset_skin + 8 ] = sw3.x;
  346. skinWeightArray[ offset_skin + 9 ] = sw3.y;
  347. skinWeightArray[ offset_skin + 10 ] = sw3.z;
  348. skinWeightArray[ offset_skin + 11 ] = sw3.w;
  349. // indices
  350. si1 = obj_skinIndices[ face.a ];
  351. si2 = obj_skinIndices[ face.b ];
  352. si3 = obj_skinIndices[ face.c ];
  353. skinIndexArray[ offset_skin ] = si1.x;
  354. skinIndexArray[ offset_skin + 1 ] = si1.y;
  355. skinIndexArray[ offset_skin + 2 ] = si1.z;
  356. skinIndexArray[ offset_skin + 3 ] = si1.w;
  357. skinIndexArray[ offset_skin + 4 ] = si2.x;
  358. skinIndexArray[ offset_skin + 5 ] = si2.y;
  359. skinIndexArray[ offset_skin + 6 ] = si2.z;
  360. skinIndexArray[ offset_skin + 7 ] = si2.w;
  361. skinIndexArray[ offset_skin + 8 ] = si3.x;
  362. skinIndexArray[ offset_skin + 9 ] = si3.y;
  363. skinIndexArray[ offset_skin + 10 ] = si3.z;
  364. skinIndexArray[ offset_skin + 11 ] = si3.w;
  365. offset_skin += 12;
  366. }
  367. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  368. face = obj_faces[ chunk_faces4[ f ] ];
  369. // weights
  370. sw1 = obj_skinWeights[ face.a ];
  371. sw2 = obj_skinWeights[ face.b ];
  372. sw3 = obj_skinWeights[ face.c ];
  373. sw4 = obj_skinWeights[ face.d ];
  374. skinWeightArray[ offset_skin ] = sw1.x;
  375. skinWeightArray[ offset_skin + 1 ] = sw1.y;
  376. skinWeightArray[ offset_skin + 2 ] = sw1.z;
  377. skinWeightArray[ offset_skin + 3 ] = sw1.w;
  378. skinWeightArray[ offset_skin + 4 ] = sw2.x;
  379. skinWeightArray[ offset_skin + 5 ] = sw2.y;
  380. skinWeightArray[ offset_skin + 6 ] = sw2.z;
  381. skinWeightArray[ offset_skin + 7 ] = sw2.w;
  382. skinWeightArray[ offset_skin + 8 ] = sw3.x;
  383. skinWeightArray[ offset_skin + 9 ] = sw3.y;
  384. skinWeightArray[ offset_skin + 10 ] = sw3.z;
  385. skinWeightArray[ offset_skin + 11 ] = sw3.w;
  386. skinWeightArray[ offset_skin + 12 ] = sw4.x;
  387. skinWeightArray[ offset_skin + 13 ] = sw4.y;
  388. skinWeightArray[ offset_skin + 14 ] = sw4.z;
  389. skinWeightArray[ offset_skin + 15 ] = sw4.w;
  390. // indices
  391. si1 = obj_skinIndices[ face.a ];
  392. si2 = obj_skinIndices[ face.b ];
  393. si3 = obj_skinIndices[ face.c ];
  394. si4 = obj_skinIndices[ face.d ];
  395. skinIndexArray[ offset_skin ] = si1.x;
  396. skinIndexArray[ offset_skin + 1 ] = si1.y;
  397. skinIndexArray[ offset_skin + 2 ] = si1.z;
  398. skinIndexArray[ offset_skin + 3 ] = si1.w;
  399. skinIndexArray[ offset_skin + 4 ] = si2.x;
  400. skinIndexArray[ offset_skin + 5 ] = si2.y;
  401. skinIndexArray[ offset_skin + 6 ] = si2.z;
  402. skinIndexArray[ offset_skin + 7 ] = si2.w;
  403. skinIndexArray[ offset_skin + 8 ] = si3.x;
  404. skinIndexArray[ offset_skin + 9 ] = si3.y;
  405. skinIndexArray[ offset_skin + 10 ] = si3.z;
  406. skinIndexArray[ offset_skin + 11 ] = si3.w;
  407. skinIndexArray[ offset_skin + 12 ] = si4.x;
  408. skinIndexArray[ offset_skin + 13 ] = si4.y;
  409. skinIndexArray[ offset_skin + 14 ] = si4.z;
  410. skinIndexArray[ offset_skin + 15 ] = si4.w;
  411. offset_skin += 16;
  412. }
  413. if ( offset_skin > 0 ) {
  414. renderer.setDynamicArrayBuffer( geometryGroup.__webglSkinIndicesBuffer, skinIndexArray);
  415. renderer.setDynamicArrayBuffer( geometryGroup.__webglSkinWeightsBuffer, skinWeightArray);
  416. }
  417. }
  418. if ( dirtyColors && vertexColorType ) {
  419. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  420. face = obj_faces[ chunk_faces3[ f ] ];
  421. vertexColors = face.vertexColors;
  422. faceColor = face.color;
  423. if ( vertexColors.length === 3 && vertexColorType === THREE.VertexColors ) {
  424. c1 = vertexColors[ 0 ];
  425. c2 = vertexColors[ 1 ];
  426. c3 = vertexColors[ 2 ];
  427. } else {
  428. c1 = faceColor;
  429. c2 = faceColor;
  430. c3 = faceColor;
  431. }
  432. colorArray[ offset_color ] = c1.r;
  433. colorArray[ offset_color + 1 ] = c1.g;
  434. colorArray[ offset_color + 2 ] = c1.b;
  435. colorArray[ offset_color + 3 ] = c2.r;
  436. colorArray[ offset_color + 4 ] = c2.g;
  437. colorArray[ offset_color + 5 ] = c2.b;
  438. colorArray[ offset_color + 6 ] = c3.r;
  439. colorArray[ offset_color + 7 ] = c3.g;
  440. colorArray[ offset_color + 8 ] = c3.b;
  441. offset_color += 9;
  442. }
  443. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  444. face = obj_faces[ chunk_faces4[ f ] ];
  445. vertexColors = face.vertexColors;
  446. faceColor = face.color;
  447. if ( vertexColors.length === 4 && vertexColorType === THREE.VertexColors ) {
  448. c1 = vertexColors[ 0 ];
  449. c2 = vertexColors[ 1 ];
  450. c3 = vertexColors[ 2 ];
  451. c4 = vertexColors[ 3 ];
  452. } else {
  453. c1 = faceColor;
  454. c2 = faceColor;
  455. c3 = faceColor;
  456. c4 = faceColor;
  457. }
  458. colorArray[ offset_color ] = c1.r;
  459. colorArray[ offset_color + 1 ] = c1.g;
  460. colorArray[ offset_color + 2 ] = c1.b;
  461. colorArray[ offset_color + 3 ] = c2.r;
  462. colorArray[ offset_color + 4 ] = c2.g;
  463. colorArray[ offset_color + 5 ] = c2.b;
  464. colorArray[ offset_color + 6 ] = c3.r;
  465. colorArray[ offset_color + 7 ] = c3.g;
  466. colorArray[ offset_color + 8 ] = c3.b;
  467. colorArray[ offset_color + 9 ] = c4.r;
  468. colorArray[ offset_color + 10 ] = c4.g;
  469. colorArray[ offset_color + 11 ] = c4.b;
  470. offset_color += 12;
  471. }
  472. if ( offset_color > 0 ) {
  473. renderer.setDynamicArrayBuffer( geometryGroup.__webglColorBuffer, colorArray);
  474. }
  475. }
  476. if ( dirtyTangents && geometry.hasTangents ) {
  477. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  478. face = obj_faces[ chunk_faces3[ f ] ];
  479. vertexTangents = face.vertexTangents;
  480. t1 = vertexTangents[ 0 ];
  481. t2 = vertexTangents[ 1 ];
  482. t3 = vertexTangents[ 2 ];
  483. tangentArray[ offset_tangent ] = t1.x;
  484. tangentArray[ offset_tangent + 1 ] = t1.y;
  485. tangentArray[ offset_tangent + 2 ] = t1.z;
  486. tangentArray[ offset_tangent + 3 ] = t1.w;
  487. tangentArray[ offset_tangent + 4 ] = t2.x;
  488. tangentArray[ offset_tangent + 5 ] = t2.y;
  489. tangentArray[ offset_tangent + 6 ] = t2.z;
  490. tangentArray[ offset_tangent + 7 ] = t2.w;
  491. tangentArray[ offset_tangent + 8 ] = t3.x;
  492. tangentArray[ offset_tangent + 9 ] = t3.y;
  493. tangentArray[ offset_tangent + 10 ] = t3.z;
  494. tangentArray[ offset_tangent + 11 ] = t3.w;
  495. offset_tangent += 12;
  496. }
  497. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  498. face = obj_faces[ chunk_faces4[ f ] ];
  499. vertexTangents = face.vertexTangents;
  500. t1 = vertexTangents[ 0 ];
  501. t2 = vertexTangents[ 1 ];
  502. t3 = vertexTangents[ 2 ];
  503. t4 = vertexTangents[ 3 ];
  504. tangentArray[ offset_tangent ] = t1.x;
  505. tangentArray[ offset_tangent + 1 ] = t1.y;
  506. tangentArray[ offset_tangent + 2 ] = t1.z;
  507. tangentArray[ offset_tangent + 3 ] = t1.w;
  508. tangentArray[ offset_tangent + 4 ] = t2.x;
  509. tangentArray[ offset_tangent + 5 ] = t2.y;
  510. tangentArray[ offset_tangent + 6 ] = t2.z;
  511. tangentArray[ offset_tangent + 7 ] = t2.w;
  512. tangentArray[ offset_tangent + 8 ] = t3.x;
  513. tangentArray[ offset_tangent + 9 ] = t3.y;
  514. tangentArray[ offset_tangent + 10 ] = t3.z;
  515. tangentArray[ offset_tangent + 11 ] = t3.w;
  516. tangentArray[ offset_tangent + 12 ] = t4.x;
  517. tangentArray[ offset_tangent + 13 ] = t4.y;
  518. tangentArray[ offset_tangent + 14 ] = t4.z;
  519. tangentArray[ offset_tangent + 15 ] = t4.w;
  520. offset_tangent += 16;
  521. }
  522. renderer.setDynamicArrayBuffer( geometryGroup.__webglTangentBuffer, tangentArray);
  523. }
  524. if ( dirtyNormals && normalType ) {
  525. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  526. face = obj_faces[ chunk_faces3[ f ] ];
  527. vertexNormals = face.vertexNormals;
  528. faceNormal = face.normal;
  529. if ( vertexNormals.length === 3 && needsSmoothNormals ) {
  530. for ( i = 0; i < 3; i ++ ) {
  531. vn = vertexNormals[ i ];
  532. normalArray[ offset_normal ] = vn.x;
  533. normalArray[ offset_normal + 1 ] = vn.y;
  534. normalArray[ offset_normal + 2 ] = vn.z;
  535. offset_normal += 3;
  536. }
  537. } else {
  538. for ( i = 0; i < 3; i ++ ) {
  539. normalArray[ offset_normal ] = faceNormal.x;
  540. normalArray[ offset_normal + 1 ] = faceNormal.y;
  541. normalArray[ offset_normal + 2 ] = faceNormal.z;
  542. offset_normal += 3;
  543. }
  544. }
  545. }
  546. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  547. face = obj_faces[ chunk_faces4[ f ] ];
  548. vertexNormals = face.vertexNormals;
  549. faceNormal = face.normal;
  550. if ( vertexNormals.length === 4 && needsSmoothNormals ) {
  551. for ( i = 0; i < 4; i ++ ) {
  552. vn = vertexNormals[ i ];
  553. normalArray[ offset_normal ] = vn.x;
  554. normalArray[ offset_normal + 1 ] = vn.y;
  555. normalArray[ offset_normal + 2 ] = vn.z;
  556. offset_normal += 3;
  557. }
  558. } else {
  559. for ( i = 0; i < 4; i ++ ) {
  560. normalArray[ offset_normal ] = faceNormal.x;
  561. normalArray[ offset_normal + 1 ] = faceNormal.y;
  562. normalArray[ offset_normal + 2 ] = faceNormal.z;
  563. offset_normal += 3;
  564. }
  565. }
  566. }
  567. renderer.setDynamicArrayBuffer( geometryGroup.__webglNormalBuffer, normalArray);
  568. }
  569. if ( dirtyUvs && obj_uvs && uvType ) {
  570. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  571. fi = chunk_faces3[ f ];
  572. uv = obj_uvs[ fi ];
  573. if ( uv === undefined ) continue;
  574. for ( i = 0; i < 3; i ++ ) {
  575. uvi = uv[ i ];
  576. uvArray[ offset_uv ] = uvi.x;
  577. uvArray[ offset_uv + 1 ] = uvi.y;
  578. offset_uv += 2;
  579. }
  580. }
  581. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  582. fi = chunk_faces4[ f ];
  583. uv = obj_uvs[ fi ];
  584. if ( uv === undefined ) continue;
  585. for ( i = 0; i < 4; i ++ ) {
  586. uvi = uv[ i ];
  587. uvArray[ offset_uv ] = uvi.x;
  588. uvArray[ offset_uv + 1 ] = uvi.y;
  589. offset_uv += 2;
  590. }
  591. }
  592. if ( offset_uv > 0 ) {
  593. renderer.setDynamicArrayBuffer( geometryGroup.__webglUVBuffer, uvArray);
  594. }
  595. }
  596. if ( dirtyUvs && obj_uvs2 && uvType ) {
  597. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  598. fi = chunk_faces3[ f ];
  599. uv2 = obj_uvs2[ fi ];
  600. if ( uv2 === undefined ) continue;
  601. for ( i = 0; i < 3; i ++ ) {
  602. uv2i = uv2[ i ];
  603. uv2Array[ offset_uv2 ] = uv2i.x;
  604. uv2Array[ offset_uv2 + 1 ] = uv2i.y;
  605. offset_uv2 += 2;
  606. }
  607. }
  608. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  609. fi = chunk_faces4[ f ];
  610. uv2 = obj_uvs2[ fi ];
  611. if ( uv2 === undefined ) continue;
  612. for ( i = 0; i < 4; i ++ ) {
  613. uv2i = uv2[ i ];
  614. uv2Array[ offset_uv2 ] = uv2i.x;
  615. uv2Array[ offset_uv2 + 1 ] = uv2i.y;
  616. offset_uv2 += 2;
  617. }
  618. }
  619. if ( offset_uv2 > 0 ) {
  620. renderer.setDynamicArrayBuffer( geometryGroup.__webglUV2Buffer, uv2Array);
  621. }
  622. }
  623. if ( dirtyElements ) {
  624. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  625. faceArray[ offset_face ] = vertexIndex;
  626. faceArray[ offset_face + 1 ] = vertexIndex + 1;
  627. faceArray[ offset_face + 2 ] = vertexIndex + 2;
  628. offset_face += 3;
  629. lineArray[ offset_line ] = vertexIndex;
  630. lineArray[ offset_line + 1 ] = vertexIndex + 1;
  631. lineArray[ offset_line + 2 ] = vertexIndex;
  632. lineArray[ offset_line + 3 ] = vertexIndex + 2;
  633. lineArray[ offset_line + 4 ] = vertexIndex + 1;
  634. lineArray[ offset_line + 5 ] = vertexIndex + 2;
  635. offset_line += 6;
  636. vertexIndex += 3;
  637. }
  638. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  639. faceArray[ offset_face ] = vertexIndex;
  640. faceArray[ offset_face + 1 ] = vertexIndex + 1;
  641. faceArray[ offset_face + 2 ] = vertexIndex + 3;
  642. faceArray[ offset_face + 3 ] = vertexIndex + 1;
  643. faceArray[ offset_face + 4 ] = vertexIndex + 2;
  644. faceArray[ offset_face + 5 ] = vertexIndex + 3;
  645. offset_face += 6;
  646. lineArray[ offset_line ] = vertexIndex;
  647. lineArray[ offset_line + 1 ] = vertexIndex + 1;
  648. lineArray[ offset_line + 2 ] = vertexIndex;
  649. lineArray[ offset_line + 3 ] = vertexIndex + 3;
  650. lineArray[ offset_line + 4 ] = vertexIndex + 1;
  651. lineArray[ offset_line + 5 ] = vertexIndex + 2;
  652. lineArray[ offset_line + 6 ] = vertexIndex + 2;
  653. lineArray[ offset_line + 7 ] = vertexIndex + 3;
  654. offset_line += 8;
  655. vertexIndex += 4;
  656. }
  657. renderer.setDynamicIndexBuffer( geometryGroup.__webglFaceBuffer, faceArray);
  658. renderer.setDynamicIndexBuffer( geometryGroup.__webglLineBuffer, lineArray);
  659. }
  660. if ( customAttributes ) {
  661. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  662. customAttribute = customAttributes[ i ];
  663. if ( ! customAttribute.__original.needsUpdate ) continue;
  664. offset_custom = 0;
  665. offset_customSrc = 0;
  666. if ( customAttribute.size === 1 ) {
  667. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  668. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  669. face = obj_faces[ chunk_faces3[ f ] ];
  670. customAttribute.array[ offset_custom ] = customAttribute.value[ face.a ];
  671. customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ face.b ];
  672. customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ face.c ];
  673. offset_custom += 3;
  674. }
  675. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  676. face = obj_faces[ chunk_faces4[ f ] ];
  677. customAttribute.array[ offset_custom ] = customAttribute.value[ face.a ];
  678. customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ face.b ];
  679. customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ face.c ];
  680. customAttribute.array[ offset_custom + 3 ] = customAttribute.value[ face.d ];
  681. offset_custom += 4;
  682. }
  683. } else if ( customAttribute.boundTo === "faces" ) {
  684. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  685. value = customAttribute.value[ chunk_faces3[ f ] ];
  686. customAttribute.array[ offset_custom ] = value;
  687. customAttribute.array[ offset_custom + 1 ] = value;
  688. customAttribute.array[ offset_custom + 2 ] = value;
  689. offset_custom += 3;
  690. }
  691. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  692. value = customAttribute.value[ chunk_faces4[ f ] ];
  693. customAttribute.array[ offset_custom ] = value;
  694. customAttribute.array[ offset_custom + 1 ] = value;
  695. customAttribute.array[ offset_custom + 2 ] = value;
  696. customAttribute.array[ offset_custom + 3 ] = value;
  697. offset_custom += 4;
  698. }
  699. }
  700. } else if ( customAttribute.size === 2 ) {
  701. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  702. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  703. face = obj_faces[ chunk_faces3[ f ] ];
  704. v1 = customAttribute.value[ face.a ];
  705. v2 = customAttribute.value[ face.b ];
  706. v3 = customAttribute.value[ face.c ];
  707. customAttribute.array[ offset_custom ] = v1.x;
  708. customAttribute.array[ offset_custom + 1 ] = v1.y;
  709. customAttribute.array[ offset_custom + 2 ] = v2.x;
  710. customAttribute.array[ offset_custom + 3 ] = v2.y;
  711. customAttribute.array[ offset_custom + 4 ] = v3.x;
  712. customAttribute.array[ offset_custom + 5 ] = v3.y;
  713. offset_custom += 6;
  714. }
  715. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  716. face = obj_faces[ chunk_faces4[ f ] ];
  717. v1 = customAttribute.value[ face.a ];
  718. v2 = customAttribute.value[ face.b ];
  719. v3 = customAttribute.value[ face.c ];
  720. v4 = customAttribute.value[ face.d ];
  721. customAttribute.array[ offset_custom ] = v1.x;
  722. customAttribute.array[ offset_custom + 1 ] = v1.y;
  723. customAttribute.array[ offset_custom + 2 ] = v2.x;
  724. customAttribute.array[ offset_custom + 3 ] = v2.y;
  725. customAttribute.array[ offset_custom + 4 ] = v3.x;
  726. customAttribute.array[ offset_custom + 5 ] = v3.y;
  727. customAttribute.array[ offset_custom + 6 ] = v4.x;
  728. customAttribute.array[ offset_custom + 7 ] = v4.y;
  729. offset_custom += 8;
  730. }
  731. } else if ( customAttribute.boundTo === "faces" ) {
  732. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  733. value = customAttribute.value[ chunk_faces3[ f ] ];
  734. v1 = value;
  735. v2 = value;
  736. v3 = value;
  737. customAttribute.array[ offset_custom ] = v1.x;
  738. customAttribute.array[ offset_custom + 1 ] = v1.y;
  739. customAttribute.array[ offset_custom + 2 ] = v2.x;
  740. customAttribute.array[ offset_custom + 3 ] = v2.y;
  741. customAttribute.array[ offset_custom + 4 ] = v3.x;
  742. customAttribute.array[ offset_custom + 5 ] = v3.y;
  743. offset_custom += 6;
  744. }
  745. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  746. value = customAttribute.value[ chunk_faces4[ f ] ];
  747. v1 = value;
  748. v2 = value;
  749. v3 = value;
  750. v4 = value;
  751. customAttribute.array[ offset_custom ] = v1.x;
  752. customAttribute.array[ offset_custom + 1 ] = v1.y;
  753. customAttribute.array[ offset_custom + 2 ] = v2.x;
  754. customAttribute.array[ offset_custom + 3 ] = v2.y;
  755. customAttribute.array[ offset_custom + 4 ] = v3.x;
  756. customAttribute.array[ offset_custom + 5 ] = v3.y;
  757. customAttribute.array[ offset_custom + 6 ] = v4.x;
  758. customAttribute.array[ offset_custom + 7 ] = v4.y;
  759. offset_custom += 8;
  760. }
  761. }
  762. } else if ( customAttribute.size === 3 ) {
  763. var pp;
  764. if ( customAttribute.type === "c" ) {
  765. pp = [ "r", "g", "b" ];
  766. } else {
  767. pp = [ "x", "y", "z" ];
  768. }
  769. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  770. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  771. face = obj_faces[ chunk_faces3[ f ] ];
  772. v1 = customAttribute.value[ face.a ];
  773. v2 = customAttribute.value[ face.b ];
  774. v3 = customAttribute.value[ face.c ];
  775. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  776. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  777. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  778. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  779. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  780. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  781. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  782. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  783. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  784. offset_custom += 9;
  785. }
  786. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  787. face = obj_faces[ chunk_faces4[ f ] ];
  788. v1 = customAttribute.value[ face.a ];
  789. v2 = customAttribute.value[ face.b ];
  790. v3 = customAttribute.value[ face.c ];
  791. v4 = customAttribute.value[ face.d ];
  792. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  793. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  794. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  795. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  796. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  797. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  798. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  799. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  800. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  801. customAttribute.array[ offset_custom + 9 ] = v4[ pp[ 0 ] ];
  802. customAttribute.array[ offset_custom + 10 ] = v4[ pp[ 1 ] ];
  803. customAttribute.array[ offset_custom + 11 ] = v4[ pp[ 2 ] ];
  804. offset_custom += 12;
  805. }
  806. } else if ( customAttribute.boundTo === "faces" ) {
  807. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  808. value = customAttribute.value[ chunk_faces3[ f ] ];
  809. v1 = value;
  810. v2 = value;
  811. v3 = value;
  812. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  813. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  814. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  815. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  816. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  817. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  818. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  819. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  820. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  821. offset_custom += 9;
  822. }
  823. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  824. value = customAttribute.value[ chunk_faces4[ f ] ];
  825. v1 = value;
  826. v2 = value;
  827. v3 = value;
  828. v4 = value;
  829. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  830. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  831. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  832. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  833. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  834. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  835. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  836. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  837. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  838. customAttribute.array[ offset_custom + 9 ] = v4[ pp[ 0 ] ];
  839. customAttribute.array[ offset_custom + 10 ] = v4[ pp[ 1 ] ];
  840. customAttribute.array[ offset_custom + 11 ] = v4[ pp[ 2 ] ];
  841. offset_custom += 12;
  842. }
  843. } else if ( customAttribute.boundTo === "faceVertices" ) {
  844. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  845. value = customAttribute.value[ chunk_faces3[ f ] ];
  846. v1 = value[ 0 ];
  847. v2 = value[ 1 ];
  848. v3 = value[ 2 ];
  849. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  850. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  851. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  852. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  853. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  854. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  855. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  856. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  857. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  858. offset_custom += 9;
  859. }
  860. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  861. value = customAttribute.value[ chunk_faces4[ f ] ];
  862. v1 = value[ 0 ];
  863. v2 = value[ 1 ];
  864. v3 = value[ 2 ];
  865. v4 = value[ 3 ];
  866. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  867. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  868. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  869. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  870. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  871. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  872. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  873. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  874. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  875. customAttribute.array[ offset_custom + 9 ] = v4[ pp[ 0 ] ];
  876. customAttribute.array[ offset_custom + 10 ] = v4[ pp[ 1 ] ];
  877. customAttribute.array[ offset_custom + 11 ] = v4[ pp[ 2 ] ];
  878. offset_custom += 12;
  879. }
  880. }
  881. } else if ( customAttribute.size === 4 ) {
  882. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  883. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  884. face = obj_faces[ chunk_faces3[ f ] ];
  885. v1 = customAttribute.value[ face.a ];
  886. v2 = customAttribute.value[ face.b ];
  887. v3 = customAttribute.value[ face.c ];
  888. customAttribute.array[ offset_custom ] = v1.x;
  889. customAttribute.array[ offset_custom + 1 ] = v1.y;
  890. customAttribute.array[ offset_custom + 2 ] = v1.z;
  891. customAttribute.array[ offset_custom + 3 ] = v1.w;
  892. customAttribute.array[ offset_custom + 4 ] = v2.x;
  893. customAttribute.array[ offset_custom + 5 ] = v2.y;
  894. customAttribute.array[ offset_custom + 6 ] = v2.z;
  895. customAttribute.array[ offset_custom + 7 ] = v2.w;
  896. customAttribute.array[ offset_custom + 8 ] = v3.x;
  897. customAttribute.array[ offset_custom + 9 ] = v3.y;
  898. customAttribute.array[ offset_custom + 10 ] = v3.z;
  899. customAttribute.array[ offset_custom + 11 ] = v3.w;
  900. offset_custom += 12;
  901. }
  902. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  903. face = obj_faces[ chunk_faces4[ f ] ];
  904. v1 = customAttribute.value[ face.a ];
  905. v2 = customAttribute.value[ face.b ];
  906. v3 = customAttribute.value[ face.c ];
  907. v4 = customAttribute.value[ face.d ];
  908. customAttribute.array[ offset_custom ] = v1.x;
  909. customAttribute.array[ offset_custom + 1 ] = v1.y;
  910. customAttribute.array[ offset_custom + 2 ] = v1.z;
  911. customAttribute.array[ offset_custom + 3 ] = v1.w;
  912. customAttribute.array[ offset_custom + 4 ] = v2.x;
  913. customAttribute.array[ offset_custom + 5 ] = v2.y;
  914. customAttribute.array[ offset_custom + 6 ] = v2.z;
  915. customAttribute.array[ offset_custom + 7 ] = v2.w;
  916. customAttribute.array[ offset_custom + 8 ] = v3.x;
  917. customAttribute.array[ offset_custom + 9 ] = v3.y;
  918. customAttribute.array[ offset_custom + 10 ] = v3.z;
  919. customAttribute.array[ offset_custom + 11 ] = v3.w;
  920. customAttribute.array[ offset_custom + 12 ] = v4.x;
  921. customAttribute.array[ offset_custom + 13 ] = v4.y;
  922. customAttribute.array[ offset_custom + 14 ] = v4.z;
  923. customAttribute.array[ offset_custom + 15 ] = v4.w;
  924. offset_custom += 16;
  925. }
  926. } else if ( customAttribute.boundTo === "faces" ) {
  927. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  928. value = customAttribute.value[ chunk_faces3[ f ] ];
  929. v1 = value;
  930. v2 = value;
  931. v3 = value;
  932. customAttribute.array[ offset_custom ] = v1.x;
  933. customAttribute.array[ offset_custom + 1 ] = v1.y;
  934. customAttribute.array[ offset_custom + 2 ] = v1.z;
  935. customAttribute.array[ offset_custom + 3 ] = v1.w;
  936. customAttribute.array[ offset_custom + 4 ] = v2.x;
  937. customAttribute.array[ offset_custom + 5 ] = v2.y;
  938. customAttribute.array[ offset_custom + 6 ] = v2.z;
  939. customAttribute.array[ offset_custom + 7 ] = v2.w;
  940. customAttribute.array[ offset_custom + 8 ] = v3.x;
  941. customAttribute.array[ offset_custom + 9 ] = v3.y;
  942. customAttribute.array[ offset_custom + 10 ] = v3.z;
  943. customAttribute.array[ offset_custom + 11 ] = v3.w;
  944. offset_custom += 12;
  945. }
  946. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  947. value = customAttribute.value[ chunk_faces4[ f ] ];
  948. v1 = value;
  949. v2 = value;
  950. v3 = value;
  951. v4 = value;
  952. customAttribute.array[ offset_custom ] = v1.x;
  953. customAttribute.array[ offset_custom + 1 ] = v1.y;
  954. customAttribute.array[ offset_custom + 2 ] = v1.z;
  955. customAttribute.array[ offset_custom + 3 ] = v1.w;
  956. customAttribute.array[ offset_custom + 4 ] = v2.x;
  957. customAttribute.array[ offset_custom + 5 ] = v2.y;
  958. customAttribute.array[ offset_custom + 6 ] = v2.z;
  959. customAttribute.array[ offset_custom + 7 ] = v2.w;
  960. customAttribute.array[ offset_custom + 8 ] = v3.x;
  961. customAttribute.array[ offset_custom + 9 ] = v3.y;
  962. customAttribute.array[ offset_custom + 10 ] = v3.z;
  963. customAttribute.array[ offset_custom + 11 ] = v3.w;
  964. customAttribute.array[ offset_custom + 12 ] = v4.x;
  965. customAttribute.array[ offset_custom + 13 ] = v4.y;
  966. customAttribute.array[ offset_custom + 14 ] = v4.z;
  967. customAttribute.array[ offset_custom + 15 ] = v4.w;
  968. offset_custom += 16;
  969. }
  970. } else if ( customAttribute.boundTo === "faceVertices" ) {
  971. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  972. value = customAttribute.value[ chunk_faces3[ f ] ];
  973. v1 = value[ 0 ];
  974. v2 = value[ 1 ];
  975. v3 = value[ 2 ];
  976. customAttribute.array[ offset_custom ] = v1.x;
  977. customAttribute.array[ offset_custom + 1 ] = v1.y;
  978. customAttribute.array[ offset_custom + 2 ] = v1.z;
  979. customAttribute.array[ offset_custom + 3 ] = v1.w;
  980. customAttribute.array[ offset_custom + 4 ] = v2.x;
  981. customAttribute.array[ offset_custom + 5 ] = v2.y;
  982. customAttribute.array[ offset_custom + 6 ] = v2.z;
  983. customAttribute.array[ offset_custom + 7 ] = v2.w;
  984. customAttribute.array[ offset_custom + 8 ] = v3.x;
  985. customAttribute.array[ offset_custom + 9 ] = v3.y;
  986. customAttribute.array[ offset_custom + 10 ] = v3.z;
  987. customAttribute.array[ offset_custom + 11 ] = v3.w;
  988. offset_custom += 12;
  989. }
  990. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  991. value = customAttribute.value[ chunk_faces4[ f ] ];
  992. v1 = value[ 0 ];
  993. v2 = value[ 1 ];
  994. v3 = value[ 2 ];
  995. v4 = value[ 3 ];
  996. customAttribute.array[ offset_custom ] = v1.x;
  997. customAttribute.array[ offset_custom + 1 ] = v1.y;
  998. customAttribute.array[ offset_custom + 2 ] = v1.z;
  999. customAttribute.array[ offset_custom + 3 ] = v1.w;
  1000. customAttribute.array[ offset_custom + 4 ] = v2.x;
  1001. customAttribute.array[ offset_custom + 5 ] = v2.y;
  1002. customAttribute.array[ offset_custom + 6 ] = v2.z;
  1003. customAttribute.array[ offset_custom + 7 ] = v2.w;
  1004. customAttribute.array[ offset_custom + 8 ] = v3.x;
  1005. customAttribute.array[ offset_custom + 9 ] = v3.y;
  1006. customAttribute.array[ offset_custom + 10 ] = v3.z;
  1007. customAttribute.array[ offset_custom + 11 ] = v3.w;
  1008. customAttribute.array[ offset_custom + 12 ] = v4.x;
  1009. customAttribute.array[ offset_custom + 13 ] = v4.y;
  1010. customAttribute.array[ offset_custom + 14 ] = v4.z;
  1011. customAttribute.array[ offset_custom + 15 ] = v4.w;
  1012. offset_custom += 16;
  1013. }
  1014. }
  1015. }
  1016. renderer.setDynamicArrayBuffer( customAttribute.buffer, customAttribute.array);
  1017. }
  1018. }
  1019. if ( dispose ) {
  1020. delete geometryGroup.__inittedArrays;
  1021. delete geometryGroup.__colorArray;
  1022. delete geometryGroup.__normalArray;
  1023. delete geometryGroup.__tangentArray;
  1024. delete geometryGroup.__uvArray;
  1025. delete geometryGroup.__uv2Array;
  1026. delete geometryGroup.__faceArray;
  1027. delete geometryGroup.__vertexArray;
  1028. delete geometryGroup.__lineArray;
  1029. delete geometryGroup.__skinIndexArray;
  1030. delete geometryGroup.__skinWeightArray;
  1031. }
  1032. }
  1033. } );