MeshObjectRenderer.js 43 KB

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