materials.tests.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. import { ObjectLoader } from '../../../src/loaders/ObjectLoader.js';
  2. import {
  3. FrontSide,
  4. BackSide,
  5. DoubleSide,
  6. NormalBlending,
  7. AdditiveBlending,
  8. SubtractiveBlending,
  9. MultiplyBlending,
  10. CustomBlending,
  11. SrcAlphaFactor,
  12. OneMinusSrcAlphaFactor
  13. } from '../../../src/constants.js';
  14. export default QUnit.module( 'JSON4 Format', () => {
  15. QUnit.module( 'Materials', () => {
  16. QUnit.test( 'MeshBasicMaterial - color, wireframe, opacity', ( assert ) => {
  17. const json = {
  18. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  19. geometries: [ {
  20. uuid: 'geom-1',
  21. type: 'BoxGeometry',
  22. width: 1,
  23. height: 1,
  24. depth: 1
  25. } ],
  26. materials: [ {
  27. uuid: 'mat-1',
  28. type: 'MeshBasicMaterial',
  29. color: 16711680,
  30. wireframe: true,
  31. opacity: 0.5,
  32. transparent: true
  33. } ],
  34. object: {
  35. uuid: 'mesh-1',
  36. type: 'Mesh',
  37. geometry: 'geom-1',
  38. material: 'mat-1',
  39. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  40. layers: 1
  41. }
  42. };
  43. const loader = new ObjectLoader();
  44. const mesh = loader.parse( json );
  45. assert.ok( mesh.material.isMeshBasicMaterial, 'Is MeshBasicMaterial' );
  46. assert.strictEqual( mesh.material.color.getHex(), 0xff0000, 'Color is red' );
  47. assert.strictEqual( mesh.material.wireframe, true, 'Wireframe is true' );
  48. assert.strictEqual( mesh.material.opacity, 0.5, 'Opacity is 0.5' );
  49. assert.strictEqual( mesh.material.transparent, true, 'Transparent is true' );
  50. } );
  51. QUnit.test( 'MeshBasicMaterial - side property', ( assert ) => {
  52. const json = {
  53. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  54. geometries: [ {
  55. uuid: 'geom-1',
  56. type: 'BoxGeometry',
  57. width: 1,
  58. height: 1,
  59. depth: 1
  60. } ],
  61. materials: [ {
  62. uuid: 'mat-1',
  63. type: 'MeshBasicMaterial',
  64. color: 16711680,
  65. side: DoubleSide
  66. } ],
  67. object: {
  68. uuid: 'mesh-1',
  69. type: 'Mesh',
  70. geometry: 'geom-1',
  71. material: 'mat-1',
  72. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  73. layers: 1
  74. }
  75. };
  76. const loader = new ObjectLoader();
  77. const mesh = loader.parse( json );
  78. assert.strictEqual( mesh.material.side, DoubleSide, 'Side is DoubleSide' );
  79. } );
  80. QUnit.test( 'MeshStandardMaterial - roughness, metalness', ( assert ) => {
  81. const json = {
  82. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  83. geometries: [ {
  84. uuid: 'geom-1',
  85. type: 'BoxGeometry',
  86. width: 1,
  87. height: 1,
  88. depth: 1
  89. } ],
  90. materials: [ {
  91. uuid: 'mat-1',
  92. type: 'MeshStandardMaterial',
  93. color: 16711680,
  94. roughness: 0.3,
  95. metalness: 0.8,
  96. emissive: 65280,
  97. emissiveIntensity: 0.5
  98. } ],
  99. object: {
  100. uuid: 'mesh-1',
  101. type: 'Mesh',
  102. geometry: 'geom-1',
  103. material: 'mat-1',
  104. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  105. layers: 1
  106. }
  107. };
  108. const loader = new ObjectLoader();
  109. const mesh = loader.parse( json );
  110. assert.ok( mesh.material.isMeshStandardMaterial, 'Is MeshStandardMaterial' );
  111. assert.strictEqual( mesh.material.color.getHex(), 0xff0000, 'Color is red' );
  112. assert.strictEqual( mesh.material.roughness, 0.3, 'Roughness is 0.3' );
  113. assert.strictEqual( mesh.material.metalness, 0.8, 'Metalness is 0.8' );
  114. assert.strictEqual( mesh.material.emissive.getHex(), 0x00ff00, 'Emissive is green' );
  115. assert.strictEqual( mesh.material.emissiveIntensity, 0.5, 'EmissiveIntensity is 0.5' );
  116. } );
  117. QUnit.test( 'MeshPhysicalMaterial - clearcoat, transmission, sheen', ( assert ) => {
  118. const json = {
  119. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  120. geometries: [ {
  121. uuid: 'geom-1',
  122. type: 'BoxGeometry',
  123. width: 1,
  124. height: 1,
  125. depth: 1
  126. } ],
  127. materials: [ {
  128. uuid: 'mat-1',
  129. type: 'MeshPhysicalMaterial',
  130. color: 16711680,
  131. clearcoat: 0.5,
  132. clearcoatRoughness: 0.1,
  133. transmission: 0.9,
  134. ior: 1.5,
  135. sheen: 0.5,
  136. sheenRoughness: 0.25,
  137. sheenColor: 255
  138. } ],
  139. object: {
  140. uuid: 'mesh-1',
  141. type: 'Mesh',
  142. geometry: 'geom-1',
  143. material: 'mat-1',
  144. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  145. layers: 1
  146. }
  147. };
  148. const loader = new ObjectLoader();
  149. const mesh = loader.parse( json );
  150. assert.ok( mesh.material.isMeshPhysicalMaterial, 'Is MeshPhysicalMaterial' );
  151. assert.strictEqual( mesh.material.clearcoat, 0.5, 'Clearcoat is 0.5' );
  152. assert.strictEqual( mesh.material.clearcoatRoughness, 0.1, 'ClearcoatRoughness is 0.1' );
  153. assert.strictEqual( mesh.material.transmission, 0.9, 'Transmission is 0.9' );
  154. assert.strictEqual( mesh.material.ior, 1.5, 'IOR is 1.5' );
  155. assert.strictEqual( mesh.material.sheen, 0.5, 'Sheen is 0.5' );
  156. assert.strictEqual( mesh.material.sheenRoughness, 0.25, 'SheenRoughness is 0.25' );
  157. } );
  158. QUnit.test( 'MeshPhysicalMaterial - iridescence, anisotropy', ( assert ) => {
  159. const json = {
  160. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  161. geometries: [ {
  162. uuid: 'geom-1',
  163. type: 'BoxGeometry',
  164. width: 1,
  165. height: 1,
  166. depth: 1
  167. } ],
  168. materials: [ {
  169. uuid: 'mat-1',
  170. type: 'MeshPhysicalMaterial',
  171. color: 16711680,
  172. iridescence: 1.0,
  173. iridescenceIOR: 1.3,
  174. iridescenceThicknessRange: [ 100, 400 ],
  175. anisotropy: 0.5,
  176. anisotropyRotation: Math.PI / 4
  177. } ],
  178. object: {
  179. uuid: 'mesh-1',
  180. type: 'Mesh',
  181. geometry: 'geom-1',
  182. material: 'mat-1',
  183. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  184. layers: 1
  185. }
  186. };
  187. const loader = new ObjectLoader();
  188. const mesh = loader.parse( json );
  189. assert.strictEqual( mesh.material.iridescence, 1.0, 'Iridescence is 1.0' );
  190. assert.strictEqual( mesh.material.iridescenceIOR, 1.3, 'IridescenceIOR is 1.3' );
  191. assert.deepEqual( mesh.material.iridescenceThicknessRange, [ 100, 400 ], 'IridescenceThicknessRange' );
  192. assert.strictEqual( mesh.material.anisotropy, 0.5, 'Anisotropy is 0.5' );
  193. assert.ok( Math.abs( mesh.material.anisotropyRotation - Math.PI / 4 ) < 0.0001, 'AnisotropyRotation' );
  194. } );
  195. QUnit.test( 'MeshPhongMaterial - shininess, specular', ( assert ) => {
  196. const json = {
  197. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  198. geometries: [ {
  199. uuid: 'geom-1',
  200. type: 'BoxGeometry',
  201. width: 1,
  202. height: 1,
  203. depth: 1
  204. } ],
  205. materials: [ {
  206. uuid: 'mat-1',
  207. type: 'MeshPhongMaterial',
  208. color: 16711680,
  209. shininess: 100,
  210. specular: 16777215
  211. } ],
  212. object: {
  213. uuid: 'mesh-1',
  214. type: 'Mesh',
  215. geometry: 'geom-1',
  216. material: 'mat-1',
  217. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  218. layers: 1
  219. }
  220. };
  221. const loader = new ObjectLoader();
  222. const mesh = loader.parse( json );
  223. assert.ok( mesh.material.isMeshPhongMaterial, 'Is MeshPhongMaterial' );
  224. assert.strictEqual( mesh.material.shininess, 100, 'Shininess is 100' );
  225. assert.strictEqual( mesh.material.specular.getHex(), 0xffffff, 'Specular is white' );
  226. } );
  227. QUnit.test( 'MeshLambertMaterial', ( assert ) => {
  228. const json = {
  229. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  230. geometries: [ {
  231. uuid: 'geom-1',
  232. type: 'BoxGeometry',
  233. width: 1,
  234. height: 1,
  235. depth: 1
  236. } ],
  237. materials: [ {
  238. uuid: 'mat-1',
  239. type: 'MeshLambertMaterial',
  240. color: 16711680,
  241. emissive: 65280
  242. } ],
  243. object: {
  244. uuid: 'mesh-1',
  245. type: 'Mesh',
  246. geometry: 'geom-1',
  247. material: 'mat-1',
  248. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  249. layers: 1
  250. }
  251. };
  252. const loader = new ObjectLoader();
  253. const mesh = loader.parse( json );
  254. assert.ok( mesh.material.isMeshLambertMaterial, 'Is MeshLambertMaterial' );
  255. assert.strictEqual( mesh.material.color.getHex(), 0xff0000, 'Color is red' );
  256. assert.strictEqual( mesh.material.emissive.getHex(), 0x00ff00, 'Emissive is green' );
  257. } );
  258. QUnit.test( 'MeshToonMaterial', ( assert ) => {
  259. const json = {
  260. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  261. geometries: [ {
  262. uuid: 'geom-1',
  263. type: 'BoxGeometry',
  264. width: 1,
  265. height: 1,
  266. depth: 1
  267. } ],
  268. materials: [ {
  269. uuid: 'mat-1',
  270. type: 'MeshToonMaterial',
  271. color: 16711680
  272. } ],
  273. object: {
  274. uuid: 'mesh-1',
  275. type: 'Mesh',
  276. geometry: 'geom-1',
  277. material: 'mat-1',
  278. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  279. layers: 1
  280. }
  281. };
  282. const loader = new ObjectLoader();
  283. const mesh = loader.parse( json );
  284. assert.ok( mesh.material.isMeshToonMaterial, 'Is MeshToonMaterial' );
  285. assert.strictEqual( mesh.material.color.getHex(), 0xff0000, 'Color is red' );
  286. } );
  287. QUnit.test( 'LineBasicMaterial - color, linewidth', ( assert ) => {
  288. const json = {
  289. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  290. geometries: [ {
  291. uuid: 'geom-1',
  292. type: 'BufferGeometry',
  293. data: {
  294. attributes: {
  295. position: {
  296. itemSize: 3,
  297. type: 'Float32Array',
  298. array: [ 0, 0, 0, 1, 1, 1 ],
  299. normalized: false
  300. }
  301. }
  302. }
  303. } ],
  304. materials: [ {
  305. uuid: 'mat-1',
  306. type: 'LineBasicMaterial',
  307. color: 65280,
  308. linewidth: 2
  309. } ],
  310. object: {
  311. uuid: 'line-1',
  312. type: 'Line',
  313. geometry: 'geom-1',
  314. material: 'mat-1',
  315. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  316. layers: 1
  317. }
  318. };
  319. const loader = new ObjectLoader();
  320. const line = loader.parse( json );
  321. assert.ok( line.material.isLineBasicMaterial, 'Is LineBasicMaterial' );
  322. assert.strictEqual( line.material.color.getHex(), 0x00ff00, 'Color is green' );
  323. assert.strictEqual( line.material.linewidth, 2, 'Linewidth is 2' );
  324. } );
  325. QUnit.test( 'LineDashedMaterial - dashSize, gapSize', ( assert ) => {
  326. const json = {
  327. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  328. geometries: [ {
  329. uuid: 'geom-1',
  330. type: 'BufferGeometry',
  331. data: {
  332. attributes: {
  333. position: {
  334. itemSize: 3,
  335. type: 'Float32Array',
  336. array: [ 0, 0, 0, 1, 1, 1 ],
  337. normalized: false
  338. }
  339. }
  340. }
  341. } ],
  342. materials: [ {
  343. uuid: 'mat-1',
  344. type: 'LineDashedMaterial',
  345. color: 65280,
  346. dashSize: 3,
  347. gapSize: 1,
  348. scale: 2
  349. } ],
  350. object: {
  351. uuid: 'line-1',
  352. type: 'Line',
  353. geometry: 'geom-1',
  354. material: 'mat-1',
  355. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  356. layers: 1
  357. }
  358. };
  359. const loader = new ObjectLoader();
  360. const line = loader.parse( json );
  361. assert.ok( line.material.isLineDashedMaterial, 'Is LineDashedMaterial' );
  362. assert.strictEqual( line.material.dashSize, 3, 'DashSize is 3' );
  363. assert.strictEqual( line.material.gapSize, 1, 'GapSize is 1' );
  364. assert.strictEqual( line.material.scale, 2, 'Scale is 2' );
  365. } );
  366. QUnit.test( 'PointsMaterial - size, sizeAttenuation', ( assert ) => {
  367. const json = {
  368. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  369. geometries: [ {
  370. uuid: 'geom-1',
  371. type: 'BufferGeometry',
  372. data: {
  373. attributes: {
  374. position: {
  375. itemSize: 3,
  376. type: 'Float32Array',
  377. array: [ 0, 0, 0, 1, 1, 1, 2, 2, 2 ],
  378. normalized: false
  379. }
  380. }
  381. }
  382. } ],
  383. materials: [ {
  384. uuid: 'mat-1',
  385. type: 'PointsMaterial',
  386. color: 255,
  387. size: 5,
  388. sizeAttenuation: false
  389. } ],
  390. object: {
  391. uuid: 'points-1',
  392. type: 'Points',
  393. geometry: 'geom-1',
  394. material: 'mat-1',
  395. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  396. layers: 1
  397. }
  398. };
  399. const loader = new ObjectLoader();
  400. const points = loader.parse( json );
  401. assert.ok( points.material.isPointsMaterial, 'Is PointsMaterial' );
  402. assert.strictEqual( points.material.color.getHex(), 0x0000ff, 'Color is blue' );
  403. assert.strictEqual( points.material.size, 5, 'Size is 5' );
  404. assert.strictEqual( points.material.sizeAttenuation, false, 'SizeAttenuation is false' );
  405. } );
  406. QUnit.test( 'SpriteMaterial - rotation', ( assert ) => {
  407. const json = {
  408. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  409. materials: [ {
  410. uuid: 'mat-1',
  411. type: 'SpriteMaterial',
  412. color: 16711680,
  413. rotation: Math.PI / 4,
  414. sizeAttenuation: true
  415. } ],
  416. object: {
  417. uuid: 'sprite-1',
  418. type: 'Sprite',
  419. material: 'mat-1',
  420. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  421. layers: 1
  422. }
  423. };
  424. const loader = new ObjectLoader();
  425. const sprite = loader.parse( json );
  426. assert.ok( sprite.material.isSpriteMaterial, 'Is SpriteMaterial' );
  427. assert.strictEqual( sprite.material.color.getHex(), 0xff0000, 'Color is red' );
  428. assert.ok( Math.abs( sprite.material.rotation - Math.PI / 4 ) < 0.0001, 'Rotation is PI/4' );
  429. } );
  430. QUnit.test( 'Blending modes - Normal, Additive', ( assert ) => {
  431. const json = {
  432. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  433. geometries: [ {
  434. uuid: 'geom-1',
  435. type: 'BoxGeometry',
  436. width: 1,
  437. height: 1,
  438. depth: 1
  439. } ],
  440. materials: [
  441. {
  442. uuid: 'mat-1',
  443. type: 'MeshBasicMaterial',
  444. color: 16711680,
  445. blending: NormalBlending
  446. },
  447. {
  448. uuid: 'mat-2',
  449. type: 'MeshBasicMaterial',
  450. color: 65280,
  451. blending: AdditiveBlending
  452. }
  453. ],
  454. object: {
  455. uuid: 'scene-1',
  456. type: 'Scene',
  457. children: [
  458. {
  459. uuid: 'mesh-1',
  460. type: 'Mesh',
  461. geometry: 'geom-1',
  462. material: 'mat-1',
  463. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  464. layers: 1
  465. },
  466. {
  467. uuid: 'mesh-2',
  468. type: 'Mesh',
  469. geometry: 'geom-1',
  470. material: 'mat-2',
  471. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1 ],
  472. layers: 1
  473. }
  474. ]
  475. }
  476. };
  477. const loader = new ObjectLoader();
  478. const scene = loader.parse( json );
  479. assert.strictEqual( scene.children[ 0 ].material.blending, NormalBlending, 'First mesh has NormalBlending' );
  480. assert.strictEqual( scene.children[ 1 ].material.blending, AdditiveBlending, 'Second mesh has AdditiveBlending' );
  481. } );
  482. QUnit.test( 'Blending modes - Subtractive, Multiply', ( assert ) => {
  483. const json = {
  484. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  485. geometries: [ {
  486. uuid: 'geom-1',
  487. type: 'BoxGeometry',
  488. width: 1,
  489. height: 1,
  490. depth: 1
  491. } ],
  492. materials: [
  493. {
  494. uuid: 'mat-1',
  495. type: 'MeshBasicMaterial',
  496. color: 16711680,
  497. blending: SubtractiveBlending
  498. },
  499. {
  500. uuid: 'mat-2',
  501. type: 'MeshBasicMaterial',
  502. color: 65280,
  503. blending: MultiplyBlending
  504. }
  505. ],
  506. object: {
  507. uuid: 'scene-1',
  508. type: 'Scene',
  509. children: [
  510. {
  511. uuid: 'mesh-1',
  512. type: 'Mesh',
  513. geometry: 'geom-1',
  514. material: 'mat-1',
  515. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  516. layers: 1
  517. },
  518. {
  519. uuid: 'mesh-2',
  520. type: 'Mesh',
  521. geometry: 'geom-1',
  522. material: 'mat-2',
  523. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1 ],
  524. layers: 1
  525. }
  526. ]
  527. }
  528. };
  529. const loader = new ObjectLoader();
  530. const scene = loader.parse( json );
  531. assert.strictEqual( scene.children[ 0 ].material.blending, SubtractiveBlending, 'First mesh has SubtractiveBlending' );
  532. assert.strictEqual( scene.children[ 1 ].material.blending, MultiplyBlending, 'Second mesh has MultiplyBlending' );
  533. } );
  534. QUnit.test( 'CustomBlending with src/dst factors', ( assert ) => {
  535. const json = {
  536. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  537. geometries: [ {
  538. uuid: 'geom-1',
  539. type: 'BoxGeometry',
  540. width: 1,
  541. height: 1,
  542. depth: 1
  543. } ],
  544. materials: [ {
  545. uuid: 'mat-1',
  546. type: 'MeshBasicMaterial',
  547. color: 16711680,
  548. blending: CustomBlending,
  549. blendSrc: SrcAlphaFactor,
  550. blendDst: OneMinusSrcAlphaFactor
  551. } ],
  552. object: {
  553. uuid: 'mesh-1',
  554. type: 'Mesh',
  555. geometry: 'geom-1',
  556. material: 'mat-1',
  557. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  558. layers: 1
  559. }
  560. };
  561. const loader = new ObjectLoader();
  562. const mesh = loader.parse( json );
  563. assert.strictEqual( mesh.material.blending, CustomBlending, 'Has CustomBlending' );
  564. assert.strictEqual( mesh.material.blendSrc, SrcAlphaFactor, 'BlendSrc is SrcAlphaFactor' );
  565. assert.strictEqual( mesh.material.blendDst, OneMinusSrcAlphaFactor, 'BlendDst is OneMinusSrcAlphaFactor' );
  566. } );
  567. QUnit.test( 'Material name and userData', ( assert ) => {
  568. const json = {
  569. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  570. geometries: [ {
  571. uuid: 'geom-1',
  572. type: 'BoxGeometry',
  573. width: 1,
  574. height: 1,
  575. depth: 1
  576. } ],
  577. materials: [ {
  578. uuid: 'mat-1',
  579. type: 'MeshBasicMaterial',
  580. name: 'MyMaterial',
  581. color: 16711680,
  582. userData: { customProp: 'customValue' }
  583. } ],
  584. object: {
  585. uuid: 'mesh-1',
  586. type: 'Mesh',
  587. geometry: 'geom-1',
  588. material: 'mat-1',
  589. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  590. layers: 1
  591. }
  592. };
  593. const loader = new ObjectLoader();
  594. const mesh = loader.parse( json );
  595. assert.strictEqual( mesh.material.name, 'MyMaterial', 'Material name' );
  596. assert.strictEqual( mesh.material.userData.customProp, 'customValue', 'Material userData' );
  597. } );
  598. QUnit.test( 'Material depthTest, depthWrite, depthFunc', ( assert ) => {
  599. const json = {
  600. metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
  601. geometries: [ {
  602. uuid: 'geom-1',
  603. type: 'BoxGeometry',
  604. width: 1,
  605. height: 1,
  606. depth: 1
  607. } ],
  608. materials: [ {
  609. uuid: 'mat-1',
  610. type: 'MeshBasicMaterial',
  611. color: 16711680,
  612. depthTest: false,
  613. depthWrite: false
  614. } ],
  615. object: {
  616. uuid: 'mesh-1',
  617. type: 'Mesh',
  618. geometry: 'geom-1',
  619. material: 'mat-1',
  620. matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  621. layers: 1
  622. }
  623. };
  624. const loader = new ObjectLoader();
  625. const mesh = loader.parse( json );
  626. assert.strictEqual( mesh.material.depthTest, false, 'DepthTest is false' );
  627. assert.strictEqual( mesh.material.depthWrite, false, 'DepthWrite is false' );
  628. } );
  629. } );
  630. } );
粤ICP备19079148号