MMDLoader.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  1. import {
  2. AddOperation,
  3. AnimationClip,
  4. Bone,
  5. BufferGeometry,
  6. Color,
  7. ColorManagement,
  8. CustomBlending,
  9. TangentSpaceNormalMap,
  10. DoubleSide,
  11. DstAlphaFactor,
  12. Euler,
  13. FileLoader,
  14. Float32BufferAttribute,
  15. FrontSide,
  16. Interpolant,
  17. Loader,
  18. LoaderUtils,
  19. UniformsUtils,
  20. ShaderMaterial,
  21. MultiplyOperation,
  22. NearestFilter,
  23. NumberKeyframeTrack,
  24. OneMinusSrcAlphaFactor,
  25. Quaternion,
  26. QuaternionKeyframeTrack,
  27. RepeatWrapping,
  28. Skeleton,
  29. SkinnedMesh,
  30. SrcAlphaFactor,
  31. TextureLoader,
  32. Uint16BufferAttribute,
  33. Vector3,
  34. VectorKeyframeTrack,
  35. RGB_S3TC_DXT1_Format,
  36. RGB_PVRTC_4BPPV1_Format,
  37. RGB_PVRTC_2BPPV1_Format,
  38. RGB_ETC1_Format,
  39. RGB_ETC2_Format
  40. } from 'three';
  41. import { MMDToonShader } from '../shaders/MMDToonShader.js';
  42. import { TGALoader } from '../loaders/TGALoader.js';
  43. import { MMDParser } from '../libs/mmdparser.module.js';
  44. /**
  45. * Dependencies
  46. * - mmd-parser https://github.com/takahirox/mmd-parser
  47. * - TGALoader
  48. * - OutlineEffect
  49. *
  50. * MMDLoader creates Three.js Objects from MMD resources as
  51. * PMD, PMX, VMD, and VPD files.
  52. *
  53. * PMD/PMX is a model data format, VMD is a motion data format
  54. * VPD is a posing data format used in MMD(Miku Miku Dance).
  55. *
  56. * MMD official site
  57. * - https://sites.google.com/view/evpvp/
  58. *
  59. * PMD, VMD format (in Japanese)
  60. * - http://blog.goo.ne.jp/torisu_tetosuki/e/209ad341d3ece2b1b4df24abf619d6e4
  61. *
  62. * PMX format
  63. * - https://gist.github.com/felixjones/f8a06bd48f9da9a4539f
  64. *
  65. * TODO
  66. * - light motion in vmd support.
  67. * - SDEF support.
  68. * - uv/material/bone morphing support.
  69. * - more precise grant skinning support.
  70. * - shadow support.
  71. */
  72. /**
  73. * @param {THREE.LoadingManager} manager
  74. */
  75. class MMDLoader extends Loader {
  76. constructor( manager ) {
  77. super( manager );
  78. this.loader = new FileLoader( this.manager );
  79. this.parser = null; // lazy generation
  80. this.meshBuilder = new MeshBuilder( this.manager );
  81. this.animationBuilder = new AnimationBuilder();
  82. }
  83. /**
  84. * @param {string} animationPath
  85. * @return {MMDLoader}
  86. */
  87. setAnimationPath( animationPath ) {
  88. this.animationPath = animationPath;
  89. return this;
  90. }
  91. // Load MMD assets as Three.js Object
  92. /**
  93. * Loads Model file (.pmd or .pmx) as a SkinnedMesh.
  94. *
  95. * @param {string} url - url to Model(.pmd or .pmx) file
  96. * @param {function} onLoad
  97. * @param {function} onProgress
  98. * @param {function} onError
  99. */
  100. load( url, onLoad, onProgress, onError ) {
  101. const builder = this.meshBuilder.setCrossOrigin( this.crossOrigin );
  102. // resource path
  103. let resourcePath;
  104. if ( this.resourcePath !== '' ) {
  105. resourcePath = this.resourcePath;
  106. } else if ( this.path !== '' ) {
  107. resourcePath = this.path;
  108. } else {
  109. resourcePath = LoaderUtils.extractUrlBase( url );
  110. }
  111. const modelExtension = this._extractExtension( url ).toLowerCase();
  112. // Should I detect by seeing header?
  113. if ( modelExtension !== 'pmd' && modelExtension !== 'pmx' ) {
  114. if ( onError ) onError( new Error( 'THREE.MMDLoader: Unknown model file extension .' + modelExtension + '.' ) );
  115. return;
  116. }
  117. this[ modelExtension === 'pmd' ? 'loadPMD' : 'loadPMX' ]( url, function ( data ) {
  118. onLoad( builder.build( data, resourcePath, onProgress, onError ) );
  119. }, onProgress, onError );
  120. }
  121. /**
  122. * Loads Motion file(s) (.vmd) as a AnimationClip.
  123. * If two or more files are specified, they'll be merged.
  124. *
  125. * @param {string|Array<string>} url - url(s) to animation(.vmd) file(s)
  126. * @param {SkinnedMesh|THREE.Camera} object - tracks will be fitting to this object
  127. * @param {function} onLoad
  128. * @param {function} onProgress
  129. * @param {function} onError
  130. */
  131. loadAnimation( url, object, onLoad, onProgress, onError ) {
  132. const builder = this.animationBuilder;
  133. this.loadVMD( url, function ( vmd ) {
  134. onLoad( object.isCamera
  135. ? builder.buildCameraAnimation( vmd )
  136. : builder.build( vmd, object ) );
  137. }, onProgress, onError );
  138. }
  139. /**
  140. * Loads mode file and motion file(s) as an object containing
  141. * a SkinnedMesh and a AnimationClip.
  142. * Tracks of AnimationClip are fitting to the model.
  143. *
  144. * @param {string} modelUrl - url to Model(.pmd or .pmx) file
  145. * @param {string|Array{string}} vmdUrl - url(s) to animation(.vmd) file
  146. * @param {function} onLoad
  147. * @param {function} onProgress
  148. * @param {function} onError
  149. */
  150. loadWithAnimation( modelUrl, vmdUrl, onLoad, onProgress, onError ) {
  151. const scope = this;
  152. this.load( modelUrl, function ( mesh ) {
  153. scope.loadAnimation( vmdUrl, mesh, function ( animation ) {
  154. onLoad( {
  155. mesh: mesh,
  156. animation: animation
  157. } );
  158. }, onProgress, onError );
  159. }, onProgress, onError );
  160. }
  161. // Load MMD assets as Object data parsed by MMDParser
  162. /**
  163. * Loads .pmd file as an Object.
  164. *
  165. * @param {string} url - url to .pmd file
  166. * @param {function} onLoad
  167. * @param {function} onProgress
  168. * @param {function} onError
  169. */
  170. loadPMD( url, onLoad, onProgress, onError ) {
  171. const parser = this._getParser();
  172. this.loader
  173. .setMimeType( undefined )
  174. .setPath( this.path )
  175. .setResponseType( 'arraybuffer' )
  176. .setRequestHeader( this.requestHeader )
  177. .setWithCredentials( this.withCredentials )
  178. .load( url, function ( buffer ) {
  179. onLoad( parser.parsePmd( buffer, true ) );
  180. }, onProgress, onError );
  181. }
  182. /**
  183. * Loads .pmx file as an Object.
  184. *
  185. * @param {string} url - url to .pmx file
  186. * @param {function} onLoad
  187. * @param {function} onProgress
  188. * @param {function} onError
  189. */
  190. loadPMX( url, onLoad, onProgress, onError ) {
  191. const parser = this._getParser();
  192. this.loader
  193. .setMimeType( undefined )
  194. .setPath( this.path )
  195. .setResponseType( 'arraybuffer' )
  196. .setRequestHeader( this.requestHeader )
  197. .setWithCredentials( this.withCredentials )
  198. .load( url, function ( buffer ) {
  199. onLoad( parser.parsePmx( buffer, true ) );
  200. }, onProgress, onError );
  201. }
  202. /**
  203. * Loads .vmd file as an Object. If two or more files are specified
  204. * they'll be merged.
  205. *
  206. * @param {string|Array<string>} url - url(s) to .vmd file(s)
  207. * @param {function} onLoad
  208. * @param {function} onProgress
  209. * @param {function} onError
  210. */
  211. loadVMD( url, onLoad, onProgress, onError ) {
  212. const urls = Array.isArray( url ) ? url : [ url ];
  213. const vmds = [];
  214. const vmdNum = urls.length;
  215. const parser = this._getParser();
  216. this.loader
  217. .setMimeType( undefined )
  218. .setPath( this.animationPath )
  219. .setResponseType( 'arraybuffer' )
  220. .setRequestHeader( this.requestHeader )
  221. .setWithCredentials( this.withCredentials );
  222. for ( let i = 0, il = urls.length; i < il; i ++ ) {
  223. this.loader.load( urls[ i ], function ( buffer ) {
  224. vmds.push( parser.parseVmd( buffer, true ) );
  225. if ( vmds.length === vmdNum ) onLoad( parser.mergeVmds( vmds ) );
  226. }, onProgress, onError );
  227. }
  228. }
  229. /**
  230. * Loads .vpd file as an Object.
  231. *
  232. * @param {string} url - url to .vpd file
  233. * @param {boolean} isUnicode
  234. * @param {function} onLoad
  235. * @param {function} onProgress
  236. * @param {function} onError
  237. */
  238. loadVPD( url, isUnicode, onLoad, onProgress, onError ) {
  239. const parser = this._getParser();
  240. this.loader
  241. .setMimeType( isUnicode ? undefined : 'text/plain; charset=shift_jis' )
  242. .setPath( this.animationPath )
  243. .setResponseType( 'text' )
  244. .setRequestHeader( this.requestHeader )
  245. .setWithCredentials( this.withCredentials )
  246. .load( url, function ( text ) {
  247. onLoad( parser.parseVpd( text, true ) );
  248. }, onProgress, onError );
  249. }
  250. // private methods
  251. _extractExtension( url ) {
  252. const index = url.lastIndexOf( '.' );
  253. return index < 0 ? '' : url.slice( index + 1 );
  254. }
  255. _getParser() {
  256. if ( this.parser === null ) {
  257. this.parser = new MMDParser.Parser();
  258. }
  259. return this.parser;
  260. }
  261. }
  262. // Utilities
  263. /*
  264. * base64 encoded defalut toon textures toon00.bmp - toon10.bmp.
  265. * We don't need to request external toon image files.
  266. */
  267. const DEFAULT_TOON_TEXTURES = [
  268. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
  269. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/bWiiMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh8aBHZBl14e8wAAAABJRU5ErkJggg==',
  270. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOUlEQVRYR+3WMREAMAwDsYY/yoDI7MLwIiP40+RJklfcCCBAgAABAgTqArfb/QMCCBAgQIAAgbbAB3z/e0F3js2cAAAAAElFTkSuQmCC',
  271. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/B5ilMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh81dWyx0gFwKAAAAABJRU5ErkJggg==',
  272. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOklEQVRYR+3WoREAMAwDsWb/UQtCy9wxTOQJ/oQ8SXKKGwEECBAgQIBAXeDt7f4BAQQIECBAgEBb4AOz8Hzx7WLY4wAAAABJRU5ErkJggg==',
  273. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABPUlEQVRYR+1XwW7CMAy1+f9fZOMysSEOEweEOPRNdm3HbdOyIhAcklPrOs/PLy9RygBALxzcCDQFmgJNgaZAU6Ap0BR4PwX8gsRMVLssMRH5HcpzJEaWL7EVg9F1IHRlyqQohgVr4FGUlUcMJSjcUlDw0zvjeun70cLWmneoyf7NgBTQSniBTQQSuJAZsOnnaczjIMb5hCiuHKxokCrJfVnrctyZL0PkJAJe1HMil4nxeyi3Ypfn1kX51jpPvo/JeCNC4PhVdHdJw2XjBR8brF8PEIhNVn12AgP7uHsTBguBn53MUZCqv7Lp07Pn5k1Ro+uWmUNn7D+M57rtk7aG0Vo73xyF/fbFf0bPJjDXngnGocDTdFhygZjwUQrMNrDcmZlQT50VJ/g/UwNyHpu778+yW+/ksOz/BFo54P4AsUXMfRq7XWsAAAAASUVORK5CYII=',
  274. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACMElEQVRYR+2Xv4pTQRTGf2dubhLdICiii2KnYKHVolhauKWPoGAnNr6BD6CvIVaihYuI2i1ia0BY0MZGRHQXjZj/mSPnnskfNWiWZUlzJ5k7M2cm833nO5Mziej2DWWJRUoCpQKlAntSQCqgw39/iUWAGmh37jrRnVsKlgpiqmkoGVABA7E57fvY+pJDdgKqF6HzFCSADkDq+F6AHABtQ+UMVE5D7zXod7fFNhTEckTbj5XQgHzNN+5tQvc5NG7C6BNkp6D3EmpXHDR+dQAjFLchW3VS9rlw3JBh+B7ys5Cf9z0GW1C/7P32AyBAOAz1q4jGliIH3YPuBnSfQX4OGreTIgEYQb/pBDtPnEQ4CivXYPAWBk13oHrB54yA9QuSn2H4AcKRpEILDt0BUzj+RLR1V5EqjD66NPRBVpLcQwjHoHYJOhsQv6U4mnzmrIXJCFr4LDwm/xBUoboG9XX4cc9VKdYoSA2yk5NQLJaKDUjTBoveG3Z2TElTxwjNK4M3LEZgUdDdruvcXzKBpStgp2NPiWi3ks9ZXxIoFVi+AvHLdc9TqtjL3/aYjpPlrzOcEnK62Szhimdd7xX232zFDTgtxezOu3WNMRLjiKgjtOhHVMd1loynVHvOgjuIIJMaELEqhJAV/RCSLbWTcfPFakFgFlALTRRvx+ok6Hlp/Q+v3fmx90bMyUzaEAhmM3KvHlXTL5DxnbGf/1M8RNNACLL5MNtPxP/mypJAqcDSFfgFhpYqWUzhTEAAAAAASUVORK5CYII=',
  275. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
  276. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
  277. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
  278. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII='
  279. ];
  280. const NON_ALPHA_CHANNEL_FORMATS = [
  281. RGB_S3TC_DXT1_Format,
  282. RGB_PVRTC_4BPPV1_Format,
  283. RGB_PVRTC_2BPPV1_Format,
  284. RGB_ETC1_Format,
  285. RGB_ETC2_Format
  286. ];
  287. // Builders. They build Three.js object from Object data parsed by MMDParser.
  288. /**
  289. * @param {THREE.LoadingManager} manager
  290. */
  291. class MeshBuilder {
  292. constructor( manager ) {
  293. this.crossOrigin = 'anonymous';
  294. this.geometryBuilder = new GeometryBuilder();
  295. this.materialBuilder = new MaterialBuilder( manager );
  296. }
  297. /**
  298. * @param {string} crossOrigin
  299. * @return {MeshBuilder}
  300. */
  301. setCrossOrigin( crossOrigin ) {
  302. this.crossOrigin = crossOrigin;
  303. return this;
  304. }
  305. /**
  306. * @param {Object} data - parsed PMD/PMX data
  307. * @param {string} resourcePath
  308. * @param {function} onProgress
  309. * @param {function} onError
  310. * @return {SkinnedMesh}
  311. */
  312. build( data, resourcePath, onProgress, onError ) {
  313. const geometry = this.geometryBuilder.build( data );
  314. const material = this.materialBuilder
  315. .setCrossOrigin( this.crossOrigin )
  316. .setResourcePath( resourcePath )
  317. .build( data, geometry, onProgress, onError );
  318. const mesh = new SkinnedMesh( geometry, material );
  319. const skeleton = new Skeleton( initBones( mesh ) );
  320. mesh.bind( skeleton );
  321. // console.log( mesh ); // for console debug
  322. return mesh;
  323. }
  324. }
  325. // TODO: Try to remove this function
  326. function initBones( mesh ) {
  327. const geometry = mesh.geometry;
  328. const bones = [];
  329. if ( geometry && geometry.bones !== undefined ) {
  330. // first, create array of 'Bone' objects from geometry data
  331. for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
  332. const gbone = geometry.bones[ i ];
  333. // create new 'Bone' object
  334. const bone = new Bone();
  335. bones.push( bone );
  336. // apply values
  337. bone.name = gbone.name;
  338. bone.position.fromArray( gbone.pos );
  339. bone.quaternion.fromArray( gbone.rotq );
  340. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  341. }
  342. // second, create bone hierarchy
  343. for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
  344. const gbone = geometry.bones[ i ];
  345. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  346. // subsequent bones in the hierarchy
  347. bones[ gbone.parent ].add( bones[ i ] );
  348. } else {
  349. // topmost bone, immediate child of the skinned mesh
  350. mesh.add( bones[ i ] );
  351. }
  352. }
  353. }
  354. // now the bones are part of the scene graph and children of the skinned mesh.
  355. // let's update the corresponding matrices
  356. mesh.updateMatrixWorld( true );
  357. return bones;
  358. }
  359. //
  360. class GeometryBuilder {
  361. /**
  362. * @param {Object} data - parsed PMD/PMX data
  363. * @return {BufferGeometry}
  364. */
  365. build( data ) {
  366. // for geometry
  367. const positions = [];
  368. const uvs = [];
  369. const normals = [];
  370. const indices = [];
  371. const groups = [];
  372. const bones = [];
  373. const skinIndices = [];
  374. const skinWeights = [];
  375. const morphTargets = [];
  376. const morphPositions = [];
  377. const iks = [];
  378. const grants = [];
  379. const rigidBodies = [];
  380. const constraints = [];
  381. // for work
  382. let offset = 0;
  383. const boneTypeTable = {};
  384. // positions, normals, uvs, skinIndices, skinWeights
  385. for ( let i = 0; i < data.metadata.vertexCount; i ++ ) {
  386. const v = data.vertices[ i ];
  387. for ( let j = 0, jl = v.position.length; j < jl; j ++ ) {
  388. positions.push( v.position[ j ] );
  389. }
  390. for ( let j = 0, jl = v.normal.length; j < jl; j ++ ) {
  391. normals.push( v.normal[ j ] );
  392. }
  393. for ( let j = 0, jl = v.uv.length; j < jl; j ++ ) {
  394. uvs.push( v.uv[ j ] );
  395. }
  396. for ( let j = 0; j < 4; j ++ ) {
  397. skinIndices.push( v.skinIndices.length - 1 >= j ? v.skinIndices[ j ] : 0.0 );
  398. }
  399. for ( let j = 0; j < 4; j ++ ) {
  400. skinWeights.push( v.skinWeights.length - 1 >= j ? v.skinWeights[ j ] : 0.0 );
  401. }
  402. }
  403. // indices
  404. for ( let i = 0; i < data.metadata.faceCount; i ++ ) {
  405. const face = data.faces[ i ];
  406. for ( let j = 0, jl = face.indices.length; j < jl; j ++ ) {
  407. indices.push( face.indices[ j ] );
  408. }
  409. }
  410. // groups
  411. for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
  412. const material = data.materials[ i ];
  413. groups.push( {
  414. offset: offset * 3,
  415. count: material.faceCount * 3
  416. } );
  417. offset += material.faceCount;
  418. }
  419. // bones
  420. for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
  421. const body = data.rigidBodies[ i ];
  422. let value = boneTypeTable[ body.boneIndex ];
  423. // keeps greater number if already value is set without any special reasons
  424. value = value === undefined ? body.type : Math.max( body.type, value );
  425. boneTypeTable[ body.boneIndex ] = value;
  426. }
  427. for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
  428. const boneData = data.bones[ i ];
  429. const bone = {
  430. index: i,
  431. transformationClass: boneData.transformationClass,
  432. parent: boneData.parentIndex,
  433. name: boneData.name,
  434. pos: boneData.position.slice( 0, 3 ),
  435. rotq: [ 0, 0, 0, 1 ],
  436. scl: [ 1, 1, 1 ],
  437. rigidBodyType: boneTypeTable[ i ] !== undefined ? boneTypeTable[ i ] : - 1
  438. };
  439. if ( bone.parent !== - 1 ) {
  440. bone.pos[ 0 ] -= data.bones[ bone.parent ].position[ 0 ];
  441. bone.pos[ 1 ] -= data.bones[ bone.parent ].position[ 1 ];
  442. bone.pos[ 2 ] -= data.bones[ bone.parent ].position[ 2 ];
  443. }
  444. bones.push( bone );
  445. }
  446. // iks
  447. // TODO: remove duplicated codes between PMD and PMX
  448. if ( data.metadata.format === 'pmd' ) {
  449. for ( let i = 0; i < data.metadata.ikCount; i ++ ) {
  450. const ik = data.iks[ i ];
  451. const param = {
  452. target: ik.target,
  453. effector: ik.effector,
  454. iteration: ik.iteration,
  455. maxAngle: ik.maxAngle * 4,
  456. links: []
  457. };
  458. for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
  459. const link = {};
  460. link.index = ik.links[ j ].index;
  461. link.enabled = true;
  462. if ( data.bones[ link.index ].name.indexOf( 'ひざ' ) >= 0 ) {
  463. link.limitation = new Vector3( 1.0, 0.0, 0.0 );
  464. }
  465. param.links.push( link );
  466. }
  467. iks.push( param );
  468. }
  469. } else {
  470. for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
  471. const ik = data.bones[ i ].ik;
  472. if ( ik === undefined ) continue;
  473. const param = {
  474. target: i,
  475. effector: ik.effector,
  476. iteration: ik.iteration,
  477. maxAngle: ik.maxAngle,
  478. links: []
  479. };
  480. for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
  481. const link = {};
  482. link.index = ik.links[ j ].index;
  483. link.enabled = true;
  484. if ( ik.links[ j ].angleLimitation === 1 ) {
  485. // Revert if rotationMin/Max doesn't work well
  486. // link.limitation = new Vector3( 1.0, 0.0, 0.0 );
  487. const rotationMin = ik.links[ j ].lowerLimitationAngle;
  488. const rotationMax = ik.links[ j ].upperLimitationAngle;
  489. // Convert Left to Right coordinate by myself because
  490. // MMDParser doesn't convert. It's a MMDParser's bug
  491. const tmp1 = - rotationMax[ 0 ];
  492. const tmp2 = - rotationMax[ 1 ];
  493. rotationMax[ 0 ] = - rotationMin[ 0 ];
  494. rotationMax[ 1 ] = - rotationMin[ 1 ];
  495. rotationMin[ 0 ] = tmp1;
  496. rotationMin[ 1 ] = tmp2;
  497. link.rotationMin = new Vector3().fromArray( rotationMin );
  498. link.rotationMax = new Vector3().fromArray( rotationMax );
  499. }
  500. param.links.push( link );
  501. }
  502. iks.push( param );
  503. // Save the reference even from bone data for efficiently
  504. // simulating PMX animation system
  505. bones[ i ].ik = param;
  506. }
  507. }
  508. // grants
  509. if ( data.metadata.format === 'pmx' ) {
  510. // bone index -> grant entry map
  511. const grantEntryMap = {};
  512. for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
  513. const boneData = data.bones[ i ];
  514. const grant = boneData.grant;
  515. if ( grant === undefined ) continue;
  516. const param = {
  517. index: i,
  518. parentIndex: grant.parentIndex,
  519. ratio: grant.ratio,
  520. isLocal: grant.isLocal,
  521. affectRotation: grant.affectRotation,
  522. affectPosition: grant.affectPosition,
  523. transformationClass: boneData.transformationClass
  524. };
  525. grantEntryMap[ i ] = { parent: null, children: [], param: param, visited: false };
  526. }
  527. const rootEntry = { parent: null, children: [], param: null, visited: false };
  528. // Build a tree representing grant hierarchy
  529. for ( const boneIndex in grantEntryMap ) {
  530. const grantEntry = grantEntryMap[ boneIndex ];
  531. const parentGrantEntry = grantEntryMap[ grantEntry.parentIndex ] || rootEntry;
  532. grantEntry.parent = parentGrantEntry;
  533. parentGrantEntry.children.push( grantEntry );
  534. }
  535. // Sort grant parameters from parents to children because
  536. // grant uses parent's transform that parent's grant is already applied
  537. // so grant should be applied in order from parents to children
  538. function traverse( entry ) {
  539. if ( entry.param ) {
  540. grants.push( entry.param );
  541. // Save the reference even from bone data for efficiently
  542. // simulating PMX animation system
  543. bones[ entry.param.index ].grant = entry.param;
  544. }
  545. entry.visited = true;
  546. for ( let i = 0, il = entry.children.length; i < il; i ++ ) {
  547. const child = entry.children[ i ];
  548. // Cut off a loop if exists. (Is a grant loop invalid?)
  549. if ( ! child.visited ) traverse( child );
  550. }
  551. }
  552. traverse( rootEntry );
  553. }
  554. // morph
  555. function updateAttributes( attribute, morph, ratio ) {
  556. for ( let i = 0; i < morph.elementCount; i ++ ) {
  557. const element = morph.elements[ i ];
  558. let index;
  559. if ( data.metadata.format === 'pmd' ) {
  560. index = data.morphs[ 0 ].elements[ element.index ].index;
  561. } else {
  562. index = element.index;
  563. }
  564. attribute.array[ index * 3 + 0 ] += element.position[ 0 ] * ratio;
  565. attribute.array[ index * 3 + 1 ] += element.position[ 1 ] * ratio;
  566. attribute.array[ index * 3 + 2 ] += element.position[ 2 ] * ratio;
  567. }
  568. }
  569. for ( let i = 0; i < data.metadata.morphCount; i ++ ) {
  570. const morph = data.morphs[ i ];
  571. const params = { name: morph.name };
  572. const attribute = new Float32BufferAttribute( data.metadata.vertexCount * 3, 3 );
  573. attribute.name = morph.name;
  574. for ( let j = 0; j < data.metadata.vertexCount * 3; j ++ ) {
  575. attribute.array[ j ] = positions[ j ];
  576. }
  577. if ( data.metadata.format === 'pmd' ) {
  578. if ( i !== 0 ) {
  579. updateAttributes( attribute, morph, 1.0 );
  580. }
  581. } else {
  582. if ( morph.type === 0 ) { // group
  583. for ( let j = 0; j < morph.elementCount; j ++ ) {
  584. const morph2 = data.morphs[ morph.elements[ j ].index ];
  585. const ratio = morph.elements[ j ].ratio;
  586. if ( morph2.type === 1 ) {
  587. updateAttributes( attribute, morph2, ratio );
  588. } else {
  589. // TODO: implement
  590. }
  591. }
  592. } else if ( morph.type === 1 ) { // vertex
  593. updateAttributes( attribute, morph, 1.0 );
  594. } else if ( morph.type === 2 ) { // bone
  595. // TODO: implement
  596. } else if ( morph.type === 3 ) { // uv
  597. // TODO: implement
  598. } else if ( morph.type === 4 ) { // additional uv1
  599. // TODO: implement
  600. } else if ( morph.type === 5 ) { // additional uv2
  601. // TODO: implement
  602. } else if ( morph.type === 6 ) { // additional uv3
  603. // TODO: implement
  604. } else if ( morph.type === 7 ) { // additional uv4
  605. // TODO: implement
  606. } else if ( morph.type === 8 ) { // material
  607. // TODO: implement
  608. }
  609. }
  610. morphTargets.push( params );
  611. morphPositions.push( attribute );
  612. }
  613. // rigid bodies from rigidBodies field.
  614. for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
  615. const rigidBody = data.rigidBodies[ i ];
  616. const params = {};
  617. for ( const key in rigidBody ) {
  618. params[ key ] = rigidBody[ key ];
  619. }
  620. /*
  621. * RigidBody position parameter in PMX seems global position
  622. * while the one in PMD seems offset from corresponding bone.
  623. * So unify being offset.
  624. */
  625. if ( data.metadata.format === 'pmx' ) {
  626. if ( params.boneIndex !== - 1 ) {
  627. const bone = data.bones[ params.boneIndex ];
  628. params.position[ 0 ] -= bone.position[ 0 ];
  629. params.position[ 1 ] -= bone.position[ 1 ];
  630. params.position[ 2 ] -= bone.position[ 2 ];
  631. }
  632. }
  633. rigidBodies.push( params );
  634. }
  635. // constraints from constraints field.
  636. for ( let i = 0; i < data.metadata.constraintCount; i ++ ) {
  637. const constraint = data.constraints[ i ];
  638. const params = {};
  639. for ( const key in constraint ) {
  640. params[ key ] = constraint[ key ];
  641. }
  642. const bodyA = rigidBodies[ params.rigidBodyIndex1 ];
  643. const bodyB = rigidBodies[ params.rigidBodyIndex2 ];
  644. // Refer to http://www20.atpages.jp/katwat/wp/?p=4135
  645. if ( bodyA.type !== 0 && bodyB.type === 2 ) {
  646. if ( bodyA.boneIndex !== - 1 && bodyB.boneIndex !== - 1 &&
  647. data.bones[ bodyB.boneIndex ].parentIndex === bodyA.boneIndex ) {
  648. bodyB.type = 1;
  649. }
  650. }
  651. constraints.push( params );
  652. }
  653. // build BufferGeometry.
  654. const geometry = new BufferGeometry();
  655. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  656. geometry.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  657. geometry.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  658. geometry.setAttribute( 'skinIndex', new Uint16BufferAttribute( skinIndices, 4 ) );
  659. geometry.setAttribute( 'skinWeight', new Float32BufferAttribute( skinWeights, 4 ) );
  660. geometry.setIndex( indices );
  661. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  662. geometry.addGroup( groups[ i ].offset, groups[ i ].count, i );
  663. }
  664. geometry.bones = bones;
  665. geometry.morphTargets = morphTargets;
  666. geometry.morphAttributes.position = morphPositions;
  667. geometry.morphTargetsRelative = false;
  668. geometry.userData.MMD = {
  669. bones: bones,
  670. iks: iks,
  671. grants: grants,
  672. rigidBodies: rigidBodies,
  673. constraints: constraints,
  674. format: data.metadata.format
  675. };
  676. geometry.computeBoundingSphere();
  677. return geometry;
  678. }
  679. }
  680. //
  681. /**
  682. * @param {THREE.LoadingManager} manager
  683. */
  684. class MaterialBuilder {
  685. constructor( manager ) {
  686. this.manager = manager;
  687. this.textureLoader = new TextureLoader( this.manager );
  688. this.tgaLoader = null; // lazy generation
  689. this.crossOrigin = 'anonymous';
  690. this.resourcePath = undefined;
  691. }
  692. /**
  693. * @param {string} crossOrigin
  694. * @return {MaterialBuilder}
  695. */
  696. setCrossOrigin( crossOrigin ) {
  697. this.crossOrigin = crossOrigin;
  698. return this;
  699. }
  700. /**
  701. * @param {string} resourcePath
  702. * @return {MaterialBuilder}
  703. */
  704. setResourcePath( resourcePath ) {
  705. this.resourcePath = resourcePath;
  706. return this;
  707. }
  708. /**
  709. * @param {Object} data - parsed PMD/PMX data
  710. * @param {BufferGeometry} geometry - some properties are dependend on geometry
  711. * @param {function} onProgress
  712. * @param {function} onError
  713. * @return {Array<MMDToonMaterial>}
  714. */
  715. build( data, geometry /*, onProgress, onError */ ) {
  716. const materials = [];
  717. const textures = {};
  718. this.textureLoader.setCrossOrigin( this.crossOrigin );
  719. // materials
  720. for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
  721. const material = data.materials[ i ];
  722. const params = { userData: { MMD: {} } };
  723. if ( material.name !== undefined ) params.name = material.name;
  724. /*
  725. * Color
  726. *
  727. * MMD MMDToonMaterial
  728. * ambient - emissive * a
  729. * (a = 1.0 without map texture or 0.2 with map texture)
  730. *
  731. * MMDToonMaterial doesn't have ambient. Set it to emissive instead.
  732. * It'll be too bright if material has map texture so using coef 0.2.
  733. */
  734. params.diffuse = new Color().fromArray( material.diffuse );
  735. params.opacity = material.diffuse[ 3 ];
  736. params.specular = new Color().fromArray( material.specular );
  737. params.shininess = material.shininess;
  738. params.emissive = new Color().fromArray( material.ambient );
  739. params.transparent = params.opacity !== 1.0;
  740. if ( ColorManagement.enabled === true ) {
  741. params.diffuse.convertSRGBToLinear();
  742. params.specular.convertSRGBToLinear();
  743. params.emissive.convertSRGBToLinear();
  744. }
  745. //
  746. params.fog = true;
  747. // blend
  748. params.blending = CustomBlending;
  749. params.blendSrc = SrcAlphaFactor;
  750. params.blendDst = OneMinusSrcAlphaFactor;
  751. params.blendSrcAlpha = SrcAlphaFactor;
  752. params.blendDstAlpha = DstAlphaFactor;
  753. // side
  754. if ( data.metadata.format === 'pmx' && ( material.flag & 0x1 ) === 1 ) {
  755. params.side = DoubleSide;
  756. } else {
  757. params.side = params.opacity === 1.0 ? FrontSide : DoubleSide;
  758. }
  759. if ( data.metadata.format === 'pmd' ) {
  760. // map, matcap
  761. if ( material.fileName ) {
  762. const fileName = material.fileName;
  763. const fileNames = fileName.split( '*' );
  764. // fileNames[ 0 ]: mapFileName
  765. // fileNames[ 1 ]: matcapFileName( optional )
  766. params.map = this._loadTexture( fileNames[ 0 ], textures );
  767. if ( fileNames.length > 1 ) {
  768. const extension = fileNames[ 1 ].slice( - 4 ).toLowerCase();
  769. params.matcap = this._loadTexture(
  770. fileNames[ 1 ],
  771. textures
  772. );
  773. params.matcapCombine = extension === '.sph'
  774. ? MultiplyOperation
  775. : AddOperation;
  776. }
  777. }
  778. // gradientMap
  779. const toonFileName = ( material.toonIndex === - 1 )
  780. ? 'toon00.bmp'
  781. : data.toonTextures[ material.toonIndex ].fileName;
  782. params.gradientMap = this._loadTexture(
  783. toonFileName,
  784. textures,
  785. {
  786. isToonTexture: true,
  787. isDefaultToonTexture: this._isDefaultToonTexture( toonFileName )
  788. }
  789. );
  790. // parameters for OutlineEffect
  791. params.userData.outlineParameters = {
  792. thickness: material.edgeFlag === 1 ? 0.003 : 0.0,
  793. color: [ 0, 0, 0 ],
  794. alpha: 1.0,
  795. visible: material.edgeFlag === 1
  796. };
  797. } else {
  798. // map
  799. if ( material.textureIndex !== - 1 ) {
  800. params.map = this._loadTexture( data.textures[ material.textureIndex ], textures );
  801. // Since PMX spec don't have standard to list map files except color map and env map,
  802. // we need to save file name for further mapping, like matching normal map file names after model loaded.
  803. // ref: https://gist.github.com/felixjones/f8a06bd48f9da9a4539f#texture
  804. params.userData.MMD.mapFileName = data.textures[ material.textureIndex ];
  805. }
  806. // matcap TODO: support m.envFlag === 3
  807. if ( material.envTextureIndex !== - 1 && ( material.envFlag === 1 || material.envFlag == 2 ) ) {
  808. params.matcap = this._loadTexture(
  809. data.textures[ material.envTextureIndex ],
  810. textures
  811. );
  812. // Same as color map above, keep file name in userData for further usage.
  813. params.userData.MMD.matcapFileName = data.textures[ material.envTextureIndex ];
  814. params.matcapCombine = material.envFlag === 1
  815. ? MultiplyOperation
  816. : AddOperation;
  817. }
  818. // gradientMap
  819. let toonFileName, isDefaultToon;
  820. if ( material.toonIndex === - 1 || material.toonFlag !== 0 ) {
  821. toonFileName = 'toon' + ( '0' + ( material.toonIndex + 1 ) ).slice( - 2 ) + '.bmp';
  822. isDefaultToon = true;
  823. } else {
  824. toonFileName = data.textures[ material.toonIndex ];
  825. isDefaultToon = false;
  826. }
  827. params.gradientMap = this._loadTexture(
  828. toonFileName,
  829. textures,
  830. {
  831. isToonTexture: true,
  832. isDefaultToonTexture: isDefaultToon
  833. }
  834. );
  835. // parameters for OutlineEffect
  836. params.userData.outlineParameters = {
  837. thickness: material.edgeSize / 300, // TODO: better calculation?
  838. color: material.edgeColor.slice( 0, 3 ),
  839. alpha: material.edgeColor[ 3 ],
  840. visible: ( material.flag & 0x10 ) !== 0 && material.edgeSize > 0.0
  841. };
  842. }
  843. if ( params.map !== undefined ) {
  844. if ( ! params.transparent ) {
  845. this._checkImageTransparency( params.map, geometry, i );
  846. }
  847. params.emissive.multiplyScalar( 0.2 );
  848. }
  849. materials.push( new MMDToonMaterial( params ) );
  850. }
  851. if ( data.metadata.format === 'pmx' ) {
  852. // set transparent true if alpha morph is defined.
  853. function checkAlphaMorph( elements, materials ) {
  854. for ( let i = 0, il = elements.length; i < il; i ++ ) {
  855. const element = elements[ i ];
  856. if ( element.index === - 1 ) continue;
  857. const material = materials[ element.index ];
  858. if ( material.opacity !== element.diffuse[ 3 ] ) {
  859. material.transparent = true;
  860. }
  861. }
  862. }
  863. for ( let i = 0, il = data.morphs.length; i < il; i ++ ) {
  864. const morph = data.morphs[ i ];
  865. const elements = morph.elements;
  866. if ( morph.type === 0 ) {
  867. for ( let j = 0, jl = elements.length; j < jl; j ++ ) {
  868. const morph2 = data.morphs[ elements[ j ].index ];
  869. if ( morph2.type !== 8 ) continue;
  870. checkAlphaMorph( morph2.elements, materials );
  871. }
  872. } else if ( morph.type === 8 ) {
  873. checkAlphaMorph( elements, materials );
  874. }
  875. }
  876. }
  877. return materials;
  878. }
  879. // private methods
  880. _getTGALoader() {
  881. if ( this.tgaLoader === null ) {
  882. if ( TGALoader === undefined ) {
  883. throw new Error( 'THREE.MMDLoader: Import TGALoader' );
  884. }
  885. this.tgaLoader = new TGALoader( this.manager );
  886. }
  887. return this.tgaLoader;
  888. }
  889. _isDefaultToonTexture( name ) {
  890. if ( name.length !== 10 ) return false;
  891. return /toon(10|0[0-9])\.bmp/.test( name );
  892. }
  893. _loadTexture( filePath, textures, params, onProgress, onError ) {
  894. params = params || {};
  895. const scope = this;
  896. let fullPath;
  897. if ( params.isDefaultToonTexture === true ) {
  898. let index;
  899. try {
  900. index = parseInt( filePath.match( /toon([0-9]{2})\.bmp$/ )[ 1 ] );
  901. } catch ( e ) {
  902. console.warn( 'THREE.MMDLoader: ' + filePath + ' seems like a '
  903. + 'not right default texture path. Using toon00.bmp instead.' );
  904. index = 0;
  905. }
  906. fullPath = DEFAULT_TOON_TEXTURES[ index ];
  907. } else {
  908. fullPath = this.resourcePath + filePath;
  909. }
  910. if ( textures[ fullPath ] !== undefined ) return textures[ fullPath ];
  911. let loader = this.manager.getHandler( fullPath );
  912. if ( loader === null ) {
  913. loader = ( filePath.slice( - 4 ).toLowerCase() === '.tga' )
  914. ? this._getTGALoader()
  915. : this.textureLoader;
  916. }
  917. const texture = loader.load( fullPath, function ( t ) {
  918. // MMD toon texture is Axis-Y oriented
  919. // but Three.js gradient map is Axis-X oriented.
  920. // So here replaces the toon texture image with the rotated one.
  921. if ( params.isToonTexture === true ) {
  922. t.image = scope._getRotatedImage( t.image );
  923. t.magFilter = NearestFilter;
  924. t.minFilter = NearestFilter;
  925. }
  926. t.flipY = false;
  927. t.wrapS = RepeatWrapping;
  928. t.wrapT = RepeatWrapping;
  929. for ( let i = 0; i < texture.readyCallbacks.length; i ++ ) {
  930. texture.readyCallbacks[ i ]( texture );
  931. }
  932. delete texture.readyCallbacks;
  933. }, onProgress, onError );
  934. texture.readyCallbacks = [];
  935. textures[ fullPath ] = texture;
  936. return texture;
  937. }
  938. _getRotatedImage( image ) {
  939. const canvas = document.createElement( 'canvas' );
  940. const context = canvas.getContext( '2d' );
  941. const width = image.width;
  942. const height = image.height;
  943. canvas.width = width;
  944. canvas.height = height;
  945. context.clearRect( 0, 0, width, height );
  946. context.translate( width / 2.0, height / 2.0 );
  947. context.rotate( 0.5 * Math.PI ); // 90.0 * Math.PI / 180.0
  948. context.translate( - width / 2.0, - height / 2.0 );
  949. context.drawImage( image, 0, 0 );
  950. return context.getImageData( 0, 0, width, height );
  951. }
  952. // Check if the partial image area used by the texture is transparent.
  953. _checkImageTransparency( map, geometry, groupIndex ) {
  954. map.readyCallbacks.push( function ( texture ) {
  955. // Is there any efficient ways?
  956. function createImageData( image ) {
  957. const canvas = document.createElement( 'canvas' );
  958. canvas.width = image.width;
  959. canvas.height = image.height;
  960. const context = canvas.getContext( '2d' );
  961. context.drawImage( image, 0, 0 );
  962. return context.getImageData( 0, 0, canvas.width, canvas.height );
  963. }
  964. function detectImageTransparency( image, uvs, indices ) {
  965. const width = image.width;
  966. const height = image.height;
  967. const data = image.data;
  968. const threshold = 253;
  969. if ( data.length / ( width * height ) !== 4 ) return false;
  970. for ( let i = 0; i < indices.length; i += 3 ) {
  971. const centerUV = { x: 0.0, y: 0.0 };
  972. for ( let j = 0; j < 3; j ++ ) {
  973. const index = indices[ i * 3 + j ];
  974. const uv = { x: uvs[ index * 2 + 0 ], y: uvs[ index * 2 + 1 ] };
  975. if ( getAlphaByUv( image, uv ) < threshold ) return true;
  976. centerUV.x += uv.x;
  977. centerUV.y += uv.y;
  978. }
  979. centerUV.x /= 3;
  980. centerUV.y /= 3;
  981. if ( getAlphaByUv( image, centerUV ) < threshold ) return true;
  982. }
  983. return false;
  984. }
  985. /*
  986. * This method expects
  987. * texture.flipY = false
  988. * texture.wrapS = RepeatWrapping
  989. * texture.wrapT = RepeatWrapping
  990. * TODO: more precise
  991. */
  992. function getAlphaByUv( image, uv ) {
  993. const width = image.width;
  994. const height = image.height;
  995. let x = Math.round( uv.x * width ) % width;
  996. let y = Math.round( uv.y * height ) % height;
  997. if ( x < 0 ) x += width;
  998. if ( y < 0 ) y += height;
  999. const index = y * width + x;
  1000. return image.data[ index * 4 + 3 ];
  1001. }
  1002. if ( texture.isCompressedTexture === true ) {
  1003. if ( NON_ALPHA_CHANNEL_FORMATS.includes( texture.format ) ) {
  1004. map.transparent = false;
  1005. } else {
  1006. // any other way to check transparency of CompressedTexture?
  1007. map.transparent = true;
  1008. }
  1009. return;
  1010. }
  1011. const imageData = texture.image.data !== undefined
  1012. ? texture.image
  1013. : createImageData( texture.image );
  1014. const group = geometry.groups[ groupIndex ];
  1015. if ( detectImageTransparency(
  1016. imageData,
  1017. geometry.attributes.uv.array,
  1018. geometry.index.array.slice( group.start, group.start + group.count ) ) ) {
  1019. map.transparent = true;
  1020. }
  1021. } );
  1022. }
  1023. }
  1024. //
  1025. class AnimationBuilder {
  1026. /**
  1027. * @param {Object} vmd - parsed VMD data
  1028. * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
  1029. * @return {AnimationClip}
  1030. */
  1031. build( vmd, mesh ) {
  1032. // combine skeletal and morph animations
  1033. const tracks = this.buildSkeletalAnimation( vmd, mesh ).tracks;
  1034. const tracks2 = this.buildMorphAnimation( vmd, mesh ).tracks;
  1035. for ( let i = 0, il = tracks2.length; i < il; i ++ ) {
  1036. tracks.push( tracks2[ i ] );
  1037. }
  1038. return new AnimationClip( '', - 1, tracks );
  1039. }
  1040. /**
  1041. * @param {Object} vmd - parsed VMD data
  1042. * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
  1043. * @return {AnimationClip}
  1044. */
  1045. buildSkeletalAnimation( vmd, mesh ) {
  1046. function pushInterpolation( array, interpolation, index ) {
  1047. array.push( interpolation[ index + 0 ] / 127 ); // x1
  1048. array.push( interpolation[ index + 8 ] / 127 ); // x2
  1049. array.push( interpolation[ index + 4 ] / 127 ); // y1
  1050. array.push( interpolation[ index + 12 ] / 127 ); // y2
  1051. }
  1052. const tracks = [];
  1053. const motions = {};
  1054. const bones = mesh.skeleton.bones;
  1055. const boneNameDictionary = {};
  1056. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  1057. boneNameDictionary[ bones[ i ].name ] = true;
  1058. }
  1059. for ( let i = 0; i < vmd.metadata.motionCount; i ++ ) {
  1060. const motion = vmd.motions[ i ];
  1061. const boneName = motion.boneName;
  1062. if ( boneNameDictionary[ boneName ] === undefined ) continue;
  1063. motions[ boneName ] = motions[ boneName ] || [];
  1064. motions[ boneName ].push( motion );
  1065. }
  1066. for ( const key in motions ) {
  1067. const array = motions[ key ];
  1068. array.sort( function ( a, b ) {
  1069. return a.frameNum - b.frameNum;
  1070. } );
  1071. const times = [];
  1072. const positions = [];
  1073. const rotations = [];
  1074. const pInterpolations = [];
  1075. const rInterpolations = [];
  1076. const basePosition = mesh.skeleton.getBoneByName( key ).position.toArray();
  1077. for ( let i = 0, il = array.length; i < il; i ++ ) {
  1078. const time = array[ i ].frameNum / 30;
  1079. const position = array[ i ].position;
  1080. const rotation = array[ i ].rotation;
  1081. const interpolation = array[ i ].interpolation;
  1082. times.push( time );
  1083. for ( let j = 0; j < 3; j ++ ) positions.push( basePosition[ j ] + position[ j ] );
  1084. for ( let j = 0; j < 4; j ++ ) rotations.push( rotation[ j ] );
  1085. for ( let j = 0; j < 3; j ++ ) pushInterpolation( pInterpolations, interpolation, j );
  1086. pushInterpolation( rInterpolations, interpolation, 3 );
  1087. }
  1088. const targetName = '.bones[' + key + ']';
  1089. tracks.push( this._createTrack( targetName + '.position', VectorKeyframeTrack, times, positions, pInterpolations ) );
  1090. tracks.push( this._createTrack( targetName + '.quaternion', QuaternionKeyframeTrack, times, rotations, rInterpolations ) );
  1091. }
  1092. return new AnimationClip( '', - 1, tracks );
  1093. }
  1094. /**
  1095. * @param {Object} vmd - parsed VMD data
  1096. * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
  1097. * @return {AnimationClip}
  1098. */
  1099. buildMorphAnimation( vmd, mesh ) {
  1100. const tracks = [];
  1101. const morphs = {};
  1102. const morphTargetDictionary = mesh.morphTargetDictionary;
  1103. for ( let i = 0; i < vmd.metadata.morphCount; i ++ ) {
  1104. const morph = vmd.morphs[ i ];
  1105. const morphName = morph.morphName;
  1106. if ( morphTargetDictionary[ morphName ] === undefined ) continue;
  1107. morphs[ morphName ] = morphs[ morphName ] || [];
  1108. morphs[ morphName ].push( morph );
  1109. }
  1110. for ( const key in morphs ) {
  1111. const array = morphs[ key ];
  1112. array.sort( function ( a, b ) {
  1113. return a.frameNum - b.frameNum;
  1114. } );
  1115. const times = [];
  1116. const values = [];
  1117. for ( let i = 0, il = array.length; i < il; i ++ ) {
  1118. times.push( array[ i ].frameNum / 30 );
  1119. values.push( array[ i ].weight );
  1120. }
  1121. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetDictionary[ key ] + ']', times, values ) );
  1122. }
  1123. return new AnimationClip( '', - 1, tracks );
  1124. }
  1125. /**
  1126. * @param {Object} vmd - parsed VMD data
  1127. * @return {AnimationClip}
  1128. */
  1129. buildCameraAnimation( vmd ) {
  1130. function pushVector3( array, vec ) {
  1131. array.push( vec.x );
  1132. array.push( vec.y );
  1133. array.push( vec.z );
  1134. }
  1135. function pushQuaternion( array, q ) {
  1136. array.push( q.x );
  1137. array.push( q.y );
  1138. array.push( q.z );
  1139. array.push( q.w );
  1140. }
  1141. function pushInterpolation( array, interpolation, index ) {
  1142. array.push( interpolation[ index * 4 + 0 ] / 127 ); // x1
  1143. array.push( interpolation[ index * 4 + 1 ] / 127 ); // x2
  1144. array.push( interpolation[ index * 4 + 2 ] / 127 ); // y1
  1145. array.push( interpolation[ index * 4 + 3 ] / 127 ); // y2
  1146. }
  1147. const cameras = vmd.cameras === undefined ? [] : vmd.cameras.slice();
  1148. cameras.sort( function ( a, b ) {
  1149. return a.frameNum - b.frameNum;
  1150. } );
  1151. const times = [];
  1152. const centers = [];
  1153. const quaternions = [];
  1154. const positions = [];
  1155. const fovs = [];
  1156. const cInterpolations = [];
  1157. const qInterpolations = [];
  1158. const pInterpolations = [];
  1159. const fInterpolations = [];
  1160. const quaternion = new Quaternion();
  1161. const euler = new Euler();
  1162. const position = new Vector3();
  1163. const center = new Vector3();
  1164. for ( let i = 0, il = cameras.length; i < il; i ++ ) {
  1165. const motion = cameras[ i ];
  1166. const time = motion.frameNum / 30;
  1167. const pos = motion.position;
  1168. const rot = motion.rotation;
  1169. const distance = motion.distance;
  1170. const fov = motion.fov;
  1171. const interpolation = motion.interpolation;
  1172. times.push( time );
  1173. position.set( 0, 0, - distance );
  1174. center.set( pos[ 0 ], pos[ 1 ], pos[ 2 ] );
  1175. euler.set( - rot[ 0 ], - rot[ 1 ], - rot[ 2 ] );
  1176. quaternion.setFromEuler( euler );
  1177. position.add( center );
  1178. position.applyQuaternion( quaternion );
  1179. pushVector3( centers, center );
  1180. pushQuaternion( quaternions, quaternion );
  1181. pushVector3( positions, position );
  1182. fovs.push( fov );
  1183. for ( let j = 0; j < 3; j ++ ) {
  1184. pushInterpolation( cInterpolations, interpolation, j );
  1185. }
  1186. pushInterpolation( qInterpolations, interpolation, 3 );
  1187. // use the same parameter for x, y, z axis.
  1188. for ( let j = 0; j < 3; j ++ ) {
  1189. pushInterpolation( pInterpolations, interpolation, 4 );
  1190. }
  1191. pushInterpolation( fInterpolations, interpolation, 5 );
  1192. }
  1193. const tracks = [];
  1194. // I expect an object whose name 'target' exists under THREE.Camera
  1195. tracks.push( this._createTrack( 'target.position', VectorKeyframeTrack, times, centers, cInterpolations ) );
  1196. tracks.push( this._createTrack( '.quaternion', QuaternionKeyframeTrack, times, quaternions, qInterpolations ) );
  1197. tracks.push( this._createTrack( '.position', VectorKeyframeTrack, times, positions, pInterpolations ) );
  1198. tracks.push( this._createTrack( '.fov', NumberKeyframeTrack, times, fovs, fInterpolations ) );
  1199. return new AnimationClip( '', - 1, tracks );
  1200. }
  1201. // private method
  1202. _createTrack( node, typedKeyframeTrack, times, values, interpolations ) {
  1203. /*
  1204. * optimizes here not to let KeyframeTrackPrototype optimize
  1205. * because KeyframeTrackPrototype optimizes times and values but
  1206. * doesn't optimize interpolations.
  1207. */
  1208. if ( times.length > 2 ) {
  1209. times = times.slice();
  1210. values = values.slice();
  1211. interpolations = interpolations.slice();
  1212. const stride = values.length / times.length;
  1213. const interpolateStride = interpolations.length / times.length;
  1214. let index = 1;
  1215. for ( let aheadIndex = 2, endIndex = times.length; aheadIndex < endIndex; aheadIndex ++ ) {
  1216. for ( let i = 0; i < stride; i ++ ) {
  1217. if ( values[ index * stride + i ] !== values[ ( index - 1 ) * stride + i ] ||
  1218. values[ index * stride + i ] !== values[ aheadIndex * stride + i ] ) {
  1219. index ++;
  1220. break;
  1221. }
  1222. }
  1223. if ( aheadIndex > index ) {
  1224. times[ index ] = times[ aheadIndex ];
  1225. for ( let i = 0; i < stride; i ++ ) {
  1226. values[ index * stride + i ] = values[ aheadIndex * stride + i ];
  1227. }
  1228. for ( let i = 0; i < interpolateStride; i ++ ) {
  1229. interpolations[ index * interpolateStride + i ] = interpolations[ aheadIndex * interpolateStride + i ];
  1230. }
  1231. }
  1232. }
  1233. times.length = index + 1;
  1234. values.length = ( index + 1 ) * stride;
  1235. interpolations.length = ( index + 1 ) * interpolateStride;
  1236. }
  1237. const track = new typedKeyframeTrack( node, times, values );
  1238. track.createInterpolant = function InterpolantFactoryMethodCubicBezier( result ) {
  1239. return new CubicBezierInterpolation( this.times, this.values, this.getValueSize(), result, new Float32Array( interpolations ) );
  1240. };
  1241. return track;
  1242. }
  1243. }
  1244. // interpolation
  1245. class CubicBezierInterpolation extends Interpolant {
  1246. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer, params ) {
  1247. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  1248. this.interpolationParams = params;
  1249. }
  1250. interpolate_( i1, t0, t, t1 ) {
  1251. const result = this.resultBuffer;
  1252. const values = this.sampleValues;
  1253. const stride = this.valueSize;
  1254. const params = this.interpolationParams;
  1255. const offset1 = i1 * stride;
  1256. const offset0 = offset1 - stride;
  1257. // No interpolation if next key frame is in one frame in 30fps.
  1258. // This is from MMD animation spec.
  1259. // '1.5' is for precision loss. times are Float32 in Three.js Animation system.
  1260. const weight1 = ( ( t1 - t0 ) < 1 / 30 * 1.5 ) ? 0.0 : ( t - t0 ) / ( t1 - t0 );
  1261. if ( stride === 4 ) { // Quaternion
  1262. const x1 = params[ i1 * 4 + 0 ];
  1263. const x2 = params[ i1 * 4 + 1 ];
  1264. const y1 = params[ i1 * 4 + 2 ];
  1265. const y2 = params[ i1 * 4 + 3 ];
  1266. const ratio = this._calculate( x1, x2, y1, y2, weight1 );
  1267. Quaternion.slerpFlat( result, 0, values, offset0, values, offset1, ratio );
  1268. } else if ( stride === 3 ) { // Vector3
  1269. for ( let i = 0; i !== stride; ++ i ) {
  1270. const x1 = params[ i1 * 12 + i * 4 + 0 ];
  1271. const x2 = params[ i1 * 12 + i * 4 + 1 ];
  1272. const y1 = params[ i1 * 12 + i * 4 + 2 ];
  1273. const y2 = params[ i1 * 12 + i * 4 + 3 ];
  1274. const ratio = this._calculate( x1, x2, y1, y2, weight1 );
  1275. result[ i ] = values[ offset0 + i ] * ( 1 - ratio ) + values[ offset1 + i ] * ratio;
  1276. }
  1277. } else { // Number
  1278. const x1 = params[ i1 * 4 + 0 ];
  1279. const x2 = params[ i1 * 4 + 1 ];
  1280. const y1 = params[ i1 * 4 + 2 ];
  1281. const y2 = params[ i1 * 4 + 3 ];
  1282. const ratio = this._calculate( x1, x2, y1, y2, weight1 );
  1283. result[ 0 ] = values[ offset0 ] * ( 1 - ratio ) + values[ offset1 ] * ratio;
  1284. }
  1285. return result;
  1286. }
  1287. _calculate( x1, x2, y1, y2, x ) {
  1288. /*
  1289. * Cubic Bezier curves
  1290. * https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves
  1291. *
  1292. * B(t) = ( 1 - t ) ^ 3 * P0
  1293. * + 3 * ( 1 - t ) ^ 2 * t * P1
  1294. * + 3 * ( 1 - t ) * t^2 * P2
  1295. * + t ^ 3 * P3
  1296. * ( 0 <= t <= 1 )
  1297. *
  1298. * MMD uses Cubic Bezier curves for bone and camera animation interpolation.
  1299. * http://d.hatena.ne.jp/edvakf/20111016/1318716097
  1300. *
  1301. * x = ( 1 - t ) ^ 3 * x0
  1302. * + 3 * ( 1 - t ) ^ 2 * t * x1
  1303. * + 3 * ( 1 - t ) * t^2 * x2
  1304. * + t ^ 3 * x3
  1305. * y = ( 1 - t ) ^ 3 * y0
  1306. * + 3 * ( 1 - t ) ^ 2 * t * y1
  1307. * + 3 * ( 1 - t ) * t^2 * y2
  1308. * + t ^ 3 * y3
  1309. * ( x0 = 0, y0 = 0 )
  1310. * ( x3 = 1, y3 = 1 )
  1311. * ( 0 <= t, x1, x2, y1, y2 <= 1 )
  1312. *
  1313. * Here solves this equation with Bisection method,
  1314. * https://en.wikipedia.org/wiki/Bisection_method
  1315. * gets t, and then calculate y.
  1316. *
  1317. * f(t) = 3 * ( 1 - t ) ^ 2 * t * x1
  1318. * + 3 * ( 1 - t ) * t^2 * x2
  1319. * + t ^ 3 - x = 0
  1320. *
  1321. * (Another option: Newton's method
  1322. * https://en.wikipedia.org/wiki/Newton%27s_method)
  1323. */
  1324. let c = 0.5;
  1325. let t = c;
  1326. let s = 1.0 - t;
  1327. const loop = 15;
  1328. const eps = 1e-5;
  1329. const math = Math;
  1330. let sst3, stt3, ttt;
  1331. for ( let i = 0; i < loop; i ++ ) {
  1332. sst3 = 3.0 * s * s * t;
  1333. stt3 = 3.0 * s * t * t;
  1334. ttt = t * t * t;
  1335. const ft = ( sst3 * x1 ) + ( stt3 * x2 ) + ( ttt ) - x;
  1336. if ( math.abs( ft ) < eps ) break;
  1337. c /= 2.0;
  1338. t += ( ft < 0 ) ? c : - c;
  1339. s = 1.0 - t;
  1340. }
  1341. return ( sst3 * y1 ) + ( stt3 * y2 ) + ttt;
  1342. }
  1343. }
  1344. class MMDToonMaterial extends ShaderMaterial {
  1345. constructor( parameters ) {
  1346. super();
  1347. this.isMMDToonMaterial = true;
  1348. this.type = 'MMDToonMaterial';
  1349. this._matcapCombine = AddOperation;
  1350. this.emissiveIntensity = 1.0;
  1351. this.normalMapType = TangentSpaceNormalMap;
  1352. this.combine = MultiplyOperation;
  1353. this.wireframeLinecap = 'round';
  1354. this.wireframeLinejoin = 'round';
  1355. this.flatShading = false;
  1356. this.lights = true;
  1357. this.vertexShader = MMDToonShader.vertexShader;
  1358. this.fragmentShader = MMDToonShader.fragmentShader;
  1359. this.defines = Object.assign( {}, MMDToonShader.defines );
  1360. Object.defineProperty( this, 'matcapCombine', {
  1361. get: function () {
  1362. return this._matcapCombine;
  1363. },
  1364. set: function ( value ) {
  1365. this._matcapCombine = value;
  1366. switch ( value ) {
  1367. case MultiplyOperation:
  1368. this.defines.MATCAP_BLENDING_MULTIPLY = true;
  1369. delete this.defines.MATCAP_BLENDING_ADD;
  1370. break;
  1371. default:
  1372. case AddOperation:
  1373. this.defines.MATCAP_BLENDING_ADD = true;
  1374. delete this.defines.MATCAP_BLENDING_MULTIPLY;
  1375. break;
  1376. }
  1377. },
  1378. } );
  1379. this.uniforms = UniformsUtils.clone( MMDToonShader.uniforms );
  1380. // merged from MeshToon/Phong/MatcapMaterial
  1381. const exposePropertyNames = [
  1382. 'specular',
  1383. 'opacity',
  1384. 'diffuse',
  1385. 'map',
  1386. 'matcap',
  1387. 'gradientMap',
  1388. 'lightMap',
  1389. 'lightMapIntensity',
  1390. 'aoMap',
  1391. 'aoMapIntensity',
  1392. 'emissive',
  1393. 'emissiveMap',
  1394. 'bumpMap',
  1395. 'bumpScale',
  1396. 'normalMap',
  1397. 'normalScale',
  1398. 'displacemantBias',
  1399. 'displacemantMap',
  1400. 'displacemantScale',
  1401. 'specularMap',
  1402. 'alphaMap',
  1403. 'reflectivity',
  1404. 'refractionRatio',
  1405. ];
  1406. for ( const propertyName of exposePropertyNames ) {
  1407. Object.defineProperty( this, propertyName, {
  1408. get: function () {
  1409. return this.uniforms[ propertyName ].value;
  1410. },
  1411. set: function ( value ) {
  1412. this.uniforms[ propertyName ].value = value;
  1413. },
  1414. } );
  1415. }
  1416. // Special path for shininess to handle zero shininess properly
  1417. this._shininess = 30;
  1418. Object.defineProperty( this, 'shininess', {
  1419. get: function () {
  1420. return this._shininess;
  1421. },
  1422. set: function ( value ) {
  1423. this._shininess = value;
  1424. this.uniforms.shininess.value = Math.max( this._shininess, 1e-4 ); // To prevent pow( 0.0, 0.0 )
  1425. },
  1426. } );
  1427. Object.defineProperty(
  1428. this,
  1429. 'color',
  1430. Object.getOwnPropertyDescriptor( this, 'diffuse' )
  1431. );
  1432. this.setValues( parameters );
  1433. }
  1434. copy( source ) {
  1435. super.copy( source );
  1436. this.matcapCombine = source.matcapCombine;
  1437. this.emissiveIntensity = source.emissiveIntensity;
  1438. this.normalMapType = source.normalMapType;
  1439. this.combine = source.combine;
  1440. this.wireframeLinecap = source.wireframeLinecap;
  1441. this.wireframeLinejoin = source.wireframeLinejoin;
  1442. this.flatShading = source.flatShading;
  1443. return this;
  1444. }
  1445. }
  1446. export { MMDLoader };