babylon.terrainMaterial.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON {
  3. var maxSimultaneousLights = 4;
  4. class TerrainMaterialDefines extends MaterialDefines {
  5. public DIFFUSE = false;
  6. public BUMP = false;
  7. public CLIPPLANE = false;
  8. public ALPHATEST = false;
  9. public POINTSIZE = false;
  10. public FOG = false;
  11. public LIGHT0 = false;
  12. public LIGHT1 = false;
  13. public LIGHT2 = false;
  14. public LIGHT3 = false;
  15. public SPOTLIGHT0 = false;
  16. public SPOTLIGHT1 = false;
  17. public SPOTLIGHT2 = false;
  18. public SPOTLIGHT3 = false;
  19. public HEMILIGHT0 = false;
  20. public HEMILIGHT1 = false;
  21. public HEMILIGHT2 = false;
  22. public HEMILIGHT3 = false;
  23. public DIRLIGHT0 = false;
  24. public DIRLIGHT1 = false;
  25. public DIRLIGHT2 = false;
  26. public DIRLIGHT3 = false;
  27. public POINTLIGHT0 = false;
  28. public POINTLIGHT1 = false;
  29. public POINTLIGHT2 = false;
  30. public POINTLIGHT3 = false;
  31. public SHADOW0 = false;
  32. public SHADOW1 = false;
  33. public SHADOW2 = false;
  34. public SHADOW3 = false;
  35. public SHADOWS = false;
  36. public SHADOWVSM0 = false;
  37. public SHADOWVSM1 = false;
  38. public SHADOWVSM2 = false;
  39. public SHADOWVSM3 = false;
  40. public SHADOWPCF0 = false;
  41. public SHADOWPCF1 = false;
  42. public SHADOWPCF2 = false;
  43. public SHADOWPCF3 = false;
  44. public SPECULARTERM = false;
  45. public NORMAL = false;
  46. public UV1 = false;
  47. public UV2 = false;
  48. public VERTEXCOLOR = false;
  49. public VERTEXALPHA = false;
  50. public BONES = false;
  51. public BONES4 = false;
  52. public BonesPerMesh = 0;
  53. public INSTANCES = false;
  54. constructor() {
  55. super();
  56. this._keys = Object.keys(this);
  57. }
  58. }
  59. export class TerrainMaterial extends Material {
  60. public mixTexture: BaseTexture;
  61. public diffuseTexture1: Texture;
  62. public diffuseTexture2: Texture;
  63. public diffuseTexture3: Texture;
  64. public bumpTexture1: Texture;
  65. public bumpTexture2: Texture;
  66. public bumpTexture3: Texture;
  67. public diffuseColor = new Color3(1, 1, 1);
  68. public specularColor = new Color3(0, 0, 0);
  69. public specularPower = 64;
  70. public disableLighting = false;
  71. private _worldViewProjectionMatrix = Matrix.Zero();
  72. private _scaledDiffuse = new Color3();
  73. private _scaledSpecular = new Color3();
  74. private _renderId: number;
  75. private _defines = new TerrainMaterialDefines();
  76. private _cachedDefines = new TerrainMaterialDefines();
  77. constructor(name: string, scene: Scene) {
  78. super(name, scene);
  79. this._cachedDefines.BonesPerMesh = -1;
  80. }
  81. public needAlphaBlending(): boolean {
  82. return (this.alpha < 1.0);
  83. }
  84. public needAlphaTesting(): boolean {
  85. return false;
  86. }
  87. public getAlphaTestTexture(): BaseTexture {
  88. return null;
  89. }
  90. // Methods
  91. private _checkCache(scene: Scene, mesh?: AbstractMesh, useInstances?: boolean): boolean {
  92. if (!mesh) {
  93. return true;
  94. }
  95. if (this._defines.INSTANCES !== useInstances) {
  96. return false;
  97. }
  98. if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
  99. return true;
  100. }
  101. return false;
  102. }
  103. public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
  104. if (this.checkReadyOnlyOnce) {
  105. if (this._wasPreviouslyReady) {
  106. return true;
  107. }
  108. }
  109. var scene = this.getScene();
  110. if (!this.checkReadyOnEveryCall) {
  111. if (this._renderId === scene.getRenderId()) {
  112. if (this._checkCache(scene, mesh, useInstances)) {
  113. return true;
  114. }
  115. }
  116. }
  117. var engine = scene.getEngine();
  118. var needNormals = false;
  119. var needUVs = false;
  120. this._defines.reset();
  121. // Textures
  122. if (scene.texturesEnabled) {
  123. if (this.mixTexture && StandardMaterial.DiffuseTextureEnabled) {
  124. if (!this.mixTexture.isReady()) {
  125. return false;
  126. } else {
  127. needUVs = true;
  128. this._defines.DIFFUSE = true;
  129. }
  130. }
  131. if ((this.bumpTexture1 || this.bumpTexture2 || this.bumpTexture3) && StandardMaterial.BumpTextureEnabled) {
  132. needUVs = true;
  133. needNormals = true;
  134. this._defines.BUMP = true;
  135. }
  136. }
  137. // Effect
  138. if (scene.clipPlane) {
  139. this._defines.CLIPPLANE = true;
  140. }
  141. if (engine.getAlphaTesting()) {
  142. this._defines.ALPHATEST = true;
  143. }
  144. // Point size
  145. if (this.pointsCloud || scene.forcePointsCloud) {
  146. this._defines.POINTSIZE = true;
  147. }
  148. // Fog
  149. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled) {
  150. this._defines.FOG = true;
  151. }
  152. var lightIndex = 0;
  153. if (scene.lightsEnabled && !this.disableLighting) {
  154. for (var index = 0; index < scene.lights.length; index++) {
  155. var light = scene.lights[index];
  156. if (!light.isEnabled()) {
  157. continue;
  158. }
  159. // Excluded check
  160. if (light._excludedMeshesIds.length > 0) {
  161. for (var excludedIndex = 0; excludedIndex < light._excludedMeshesIds.length; excludedIndex++) {
  162. var excludedMesh = scene.getMeshByID(light._excludedMeshesIds[excludedIndex]);
  163. if (excludedMesh) {
  164. light.excludedMeshes.push(excludedMesh);
  165. }
  166. }
  167. light._excludedMeshesIds = [];
  168. }
  169. // Included check
  170. if (light._includedOnlyMeshesIds.length > 0) {
  171. for (var includedOnlyIndex = 0; includedOnlyIndex < light._includedOnlyMeshesIds.length; includedOnlyIndex++) {
  172. var includedOnlyMesh = scene.getMeshByID(light._includedOnlyMeshesIds[includedOnlyIndex]);
  173. if (includedOnlyMesh) {
  174. light.includedOnlyMeshes.push(includedOnlyMesh);
  175. }
  176. }
  177. light._includedOnlyMeshesIds = [];
  178. }
  179. if (!light.canAffectMesh(mesh)) {
  180. continue;
  181. }
  182. needNormals = true;
  183. this._defines["LIGHT" + lightIndex] = true;
  184. var type;
  185. if (light instanceof SpotLight) {
  186. type = "SPOTLIGHT" + lightIndex;
  187. } else if (light instanceof HemisphericLight) {
  188. type = "HEMILIGHT" + lightIndex;
  189. } else if (light instanceof PointLight) {
  190. type = "POINTLIGHT" + lightIndex;
  191. } else {
  192. type = "DIRLIGHT" + lightIndex;
  193. }
  194. this._defines[type] = true;
  195. // Specular
  196. if (!light.specular.equalsFloats(0, 0, 0)) {
  197. this._defines.SPECULARTERM = true;
  198. }
  199. // Shadows
  200. if (scene.shadowsEnabled) {
  201. var shadowGenerator = light.getShadowGenerator();
  202. if (mesh && mesh.receiveShadows && shadowGenerator) {
  203. this._defines["SHADOW" + lightIndex] = true;
  204. this._defines.SHADOWS = true;
  205. if (shadowGenerator.useVarianceShadowMap || shadowGenerator.useBlurVarianceShadowMap) {
  206. this._defines["SHADOWVSM" + lightIndex] = true;
  207. }
  208. if (shadowGenerator.usePoissonSampling) {
  209. this._defines["SHADOWPCF" + lightIndex] = true;
  210. }
  211. }
  212. }
  213. lightIndex++;
  214. if (lightIndex === maxSimultaneousLights)
  215. break;
  216. }
  217. }
  218. // Attribs
  219. if (mesh) {
  220. if (needNormals && mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
  221. this._defines.NORMAL = true;
  222. }
  223. if (needUVs) {
  224. if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
  225. this._defines.UV1 = true;
  226. }
  227. if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
  228. this._defines.UV2 = true;
  229. }
  230. }
  231. if (mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind)) {
  232. this._defines.VERTEXCOLOR = true;
  233. if (mesh.hasVertexAlpha) {
  234. this._defines.VERTEXALPHA = true;
  235. }
  236. }
  237. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  238. this._defines.BONES = true;
  239. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  240. this._defines.BONES4 = true;
  241. }
  242. // Instances
  243. if (useInstances) {
  244. this._defines.INSTANCES = true;
  245. }
  246. }
  247. // Get correct effect
  248. if (!this._defines.isEqual(this._cachedDefines)) {
  249. this._defines.cloneTo(this._cachedDefines);
  250. scene.resetCachedMaterial();
  251. // Fallbacks
  252. var fallbacks = new EffectFallbacks();
  253. if (this._defines.FOG) {
  254. fallbacks.addFallback(1, "FOG");
  255. }
  256. for (lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
  257. if (!this._defines["LIGHT" + lightIndex]) {
  258. continue;
  259. }
  260. if (lightIndex > 0) {
  261. fallbacks.addFallback(lightIndex, "LIGHT" + lightIndex);
  262. }
  263. if (this._defines["SHADOW" + lightIndex]) {
  264. fallbacks.addFallback(0, "SHADOW" + lightIndex);
  265. }
  266. if (this._defines["SHADOWPCF" + lightIndex]) {
  267. fallbacks.addFallback(0, "SHADOWPCF" + lightIndex);
  268. }
  269. if (this._defines["SHADOWVSM" + lightIndex]) {
  270. fallbacks.addFallback(0, "SHADOWVSM" + lightIndex);
  271. }
  272. }
  273. if (this._defines.BONES4) {
  274. fallbacks.addFallback(0, "BONES4");
  275. }
  276. //Attributes
  277. var attribs = [VertexBuffer.PositionKind];
  278. if (this._defines.NORMAL) {
  279. attribs.push(VertexBuffer.NormalKind);
  280. }
  281. if (this._defines.UV1) {
  282. attribs.push(VertexBuffer.UVKind);
  283. }
  284. if (this._defines.UV2) {
  285. attribs.push(VertexBuffer.UV2Kind);
  286. }
  287. if (this._defines.VERTEXCOLOR) {
  288. attribs.push(VertexBuffer.ColorKind);
  289. }
  290. if (this._defines.BONES) {
  291. attribs.push(VertexBuffer.MatricesIndicesKind);
  292. attribs.push(VertexBuffer.MatricesWeightsKind);
  293. }
  294. if (this._defines.INSTANCES) {
  295. attribs.push("world0");
  296. attribs.push("world1");
  297. attribs.push("world2");
  298. attribs.push("world3");
  299. }
  300. // Legacy browser patch
  301. var shaderName = "terrain";
  302. var join = this._defines.toString();
  303. this._effect = scene.getEngine().createEffect(shaderName,
  304. attribs,
  305. ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  306. "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
  307. "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
  308. "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
  309. "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
  310. "vFogInfos", "vFogColor", "pointSize",
  311. "vTextureInfos",
  312. "mBones",
  313. "vClipPlane", "textureMatrix",
  314. "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
  315. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
  316. ],
  317. ["textureSampler", "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler",
  318. "bump1Sampler", "bump2Sampler", "bump3Sampler",
  319. "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
  320. ],
  321. join, fallbacks, this.onCompiled, this.onError);
  322. }
  323. if (!this._effect.isReady()) {
  324. return false;
  325. }
  326. this._renderId = scene.getRenderId();
  327. this._wasPreviouslyReady = true;
  328. if (mesh) {
  329. if (!mesh._materialDefines) {
  330. mesh._materialDefines = new TerrainMaterialDefines();
  331. }
  332. this._defines.cloneTo(mesh._materialDefines);
  333. }
  334. return true;
  335. }
  336. public bindOnlyWorldMatrix(world: Matrix): void {
  337. this._effect.setMatrix("world", world);
  338. }
  339. public bind(world: Matrix, mesh?: Mesh): void {
  340. var scene = this.getScene();
  341. // Matrices
  342. this.bindOnlyWorldMatrix(world);
  343. this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
  344. // Bones
  345. if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
  346. this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
  347. }
  348. if (scene.getCachedMaterial() !== this) {
  349. // Textures
  350. if (this.mixTexture) {
  351. this._effect.setTexture("textureSampler", this.mixTexture);
  352. this._effect.setFloat2("vTextureInfos", this.mixTexture.coordinatesIndex, this.mixTexture.level);
  353. this._effect.setMatrix("textureMatrix", this.mixTexture.getTextureMatrix());
  354. if (StandardMaterial.DiffuseTextureEnabled) {
  355. if (this.diffuseTexture1) {
  356. this._effect.setTexture("diffuse1Sampler", this.diffuseTexture1);
  357. this._effect.setFloat2("diffuse1Infos", this.diffuseTexture1.uScale, this.diffuseTexture1.vScale);
  358. }
  359. if (this.diffuseTexture2) {
  360. this._effect.setTexture("diffuse2Sampler", this.diffuseTexture2);
  361. this._effect.setFloat2("diffuse2Infos", this.diffuseTexture2.uScale, this.diffuseTexture2.vScale);
  362. }
  363. if (this.diffuseTexture3) {
  364. this._effect.setTexture("diffuse3Sampler", this.diffuseTexture3);
  365. this._effect.setFloat2("diffuse3Infos", this.diffuseTexture3.uScale, this.diffuseTexture3.vScale);
  366. }
  367. }
  368. if (StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
  369. if (this.bumpTexture1) {
  370. this._effect.setTexture("bump1Sampler", this.bumpTexture1);
  371. }
  372. if (this.bumpTexture2) {
  373. this._effect.setTexture("bump2Sampler", this.bumpTexture2);
  374. }
  375. if (this.bumpTexture3) {
  376. this._effect.setTexture("bump3Sampler", this.bumpTexture3);
  377. }
  378. }
  379. }
  380. // Clip plane
  381. if (scene.clipPlane) {
  382. var clipPlane = scene.clipPlane;
  383. this._effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  384. }
  385. // Point size
  386. if (this.pointsCloud) {
  387. this._effect.setFloat("pointSize", this.pointSize);
  388. }
  389. this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  390. }
  391. this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  392. if (this._defines.SPECULARTERM) {
  393. this._effect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  394. }
  395. if (scene.lightsEnabled && !this.disableLighting) {
  396. var lightIndex = 0;
  397. for (var index = 0; index < scene.lights.length; index++) {
  398. var light = scene.lights[index];
  399. if (!light.isEnabled()) {
  400. continue;
  401. }
  402. if (!light.canAffectMesh(mesh)) {
  403. continue;
  404. }
  405. if (light instanceof PointLight) {
  406. // Point Light
  407. light.transferToEffect(this._effect, "vLightData" + lightIndex);
  408. } else if (light instanceof DirectionalLight) {
  409. // Directional Light
  410. light.transferToEffect(this._effect, "vLightData" + lightIndex);
  411. } else if (light instanceof SpotLight) {
  412. // Spot Light
  413. light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
  414. } else if (light instanceof HemisphericLight) {
  415. // Hemispheric Light
  416. light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
  417. }
  418. light.diffuse.scaleToRef(light.intensity, this._scaledDiffuse);
  419. this._effect.setColor4("vLightDiffuse" + lightIndex, this._scaledDiffuse, light.range);
  420. if (this._defines.SPECULARTERM) {
  421. light.specular.scaleToRef(light.intensity, this._scaledSpecular);
  422. this._effect.setColor3("vLightSpecular" + lightIndex, this._scaledSpecular);
  423. }
  424. // Shadows
  425. if (scene.shadowsEnabled) {
  426. var shadowGenerator = light.getShadowGenerator();
  427. if (mesh.receiveShadows && shadowGenerator) {
  428. this._effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
  429. this._effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
  430. this._effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
  431. }
  432. }
  433. lightIndex++;
  434. if (lightIndex === maxSimultaneousLights)
  435. break;
  436. }
  437. }
  438. // View
  439. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
  440. this._effect.setMatrix("view", scene.getViewMatrix());
  441. }
  442. // Fog
  443. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
  444. this._effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
  445. this._effect.setColor3("vFogColor", scene.fogColor);
  446. }
  447. super.bind(world, mesh);
  448. }
  449. public getAnimatables(): IAnimatable[] {
  450. var results = [];
  451. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  452. results.push(this.mixTexture);
  453. }
  454. return results;
  455. }
  456. public dispose(forceDisposeEffect?: boolean): void {
  457. if (this.mixTexture) {
  458. this.mixTexture.dispose();
  459. }
  460. super.dispose(forceDisposeEffect);
  461. }
  462. public clone(name: string): TerrainMaterial {
  463. var newMaterial = new TerrainMaterial(name, this.getScene());
  464. // Base material
  465. this.copyTo(newMaterial);
  466. // Simple material
  467. if (this.mixTexture && this.mixTexture.clone) {
  468. newMaterial.mixTexture = this.mixTexture.clone();
  469. }
  470. newMaterial.diffuseColor = this.diffuseColor.clone();
  471. return newMaterial;
  472. }
  473. public serialize(): any {
  474. var serializationObject = super.serialize();
  475. serializationObject.customType = "BABYLON.TerrainMaterial";
  476. serializationObject.diffuseColor = this.diffuseColor.asArray();
  477. serializationObject.specularColor = this.specularColor.asArray();
  478. serializationObject.specularPower = this.specularPower;
  479. serializationObject.disableLighting = this.disableLighting;
  480. if (this.diffuseTexture1) {
  481. serializationObject.diffuseTexture1 = this.diffuseTexture1.serialize();
  482. }
  483. if (this.diffuseTexture2) {
  484. serializationObject.diffuseTexture2 = this.diffuseTexture2.serialize();
  485. }
  486. if (this.diffuseTexture3) {
  487. serializationObject.diffuseTexture3 = this.diffuseTexture3.serialize();
  488. }
  489. if (this.bumpTexture1) {
  490. serializationObject.bumpTexture1 = this.bumpTexture1.serialize();
  491. }
  492. if (this.bumpTexture2) {
  493. serializationObject.bumpTexture2 = this.bumpTexture2.serialize();
  494. }
  495. if (this.bumpTexture3) {
  496. serializationObject.bumpTexture3 = this.bumpTexture3.serialize();
  497. }
  498. if (this.mixTexture) {
  499. serializationObject.mixTexture = this.mixTexture.serialize();
  500. }
  501. return serializationObject;
  502. }
  503. public static Parse(source: any, scene: Scene, rootUrl: string): TerrainMaterial {
  504. var material = new TerrainMaterial(source.name, scene);
  505. material.diffuseColor = Color3.FromArray(source.diffuseColor);
  506. material.specularColor = Color3.FromArray(source.specularColor);
  507. material.specularPower = source.specularPower;
  508. material.disableLighting = source.disableLighting;
  509. material.alpha = source.alpha;
  510. material.id = source.id;
  511. Tags.AddTagsTo(material, source.tags);
  512. material.backFaceCulling = source.backFaceCulling;
  513. material.wireframe = source.wireframe;
  514. if (source.diffuseTexture1) {
  515. material.diffuseTexture1 = <Texture>Texture.Parse(source.diffuseTexture1, scene, rootUrl);
  516. }
  517. if (source.diffuseTexture2) {
  518. material.diffuseTexture2 = <Texture>Texture.Parse(source.diffuseTexture2, scene, rootUrl);
  519. }
  520. if (source.diffuseTexture3) {
  521. material.diffuseTexture3 = <Texture>Texture.Parse(source.diffuseTexture3, scene, rootUrl);
  522. }
  523. if (source.bumpTexture1) {
  524. material.bumpTexture1 = <Texture>Texture.Parse(source.bumpTexture1, scene, rootUrl);
  525. }
  526. if (source.bumpTexture2) {
  527. material.bumpTexture2 = <Texture> Texture.Parse(source.bumpTexture2, scene, rootUrl);
  528. }
  529. if (source.bumpTexture3) {
  530. material.bumpTexture3 = <Texture> Texture.Parse(source.bumpTexture3, scene, rootUrl);
  531. }
  532. if (source.mixTexture) {
  533. material.mixTexture = Texture.Parse(source.mixTexture, scene, rootUrl);
  534. }
  535. return material;
  536. }
  537. }
  538. }