babylon.standardMaterial.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. module BABYLON {
  2. var maxSimultaneousLights = 4;
  3. export class StandardMaterial extends Material {
  4. public diffuseTexture: BaseTexture;
  5. public ambientTexture: BaseTexture;
  6. public opacityTexture: BaseTexture;
  7. public reflectionTexture: BaseTexture;
  8. public emissiveTexture: BaseTexture;
  9. public specularTexture: BaseTexture;
  10. public bumpTexture: BaseTexture;
  11. public ambientColor = new BABYLON.Color3(0, 0, 0);
  12. public diffuseColor = new BABYLON.Color3(1, 1, 1);
  13. public specularColor = new BABYLON.Color3(1, 1, 1);
  14. public specularPower = 64;
  15. public emissiveColor = new BABYLON.Color3(0, 0, 0);
  16. public useAlphaFromDiffuseTexture = false;
  17. private _cachedDefines = null;
  18. private _renderTargets = new BABYLON.SmartArray<RenderTargetTexture>(16);
  19. private _worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  20. private _globalAmbientColor = new BABYLON.Color3(0, 0, 0);
  21. private _baseColor = new BABYLON.Color3();
  22. private _scaledDiffuse = new BABYLON.Color3();
  23. private _scaledSpecular = new BABYLON.Color3();
  24. private _renderId: number;
  25. constructor(name: string, scene: Scene) {
  26. super(name, scene);
  27. this.getRenderTargetTextures = (): SmartArray<RenderTargetTexture> => {
  28. this._renderTargets.reset();
  29. if (this.reflectionTexture && this.reflectionTexture.isRenderTarget) {
  30. this._renderTargets.push(this.reflectionTexture);
  31. }
  32. return this._renderTargets;
  33. }
  34. }
  35. public needAlphaBlending(): boolean {
  36. return (this.alpha < 1.0) || (this.opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture();
  37. }
  38. public needAlphaTesting(): boolean {
  39. return this.diffuseTexture != null && this.diffuseTexture.hasAlpha && !this.diffuseTexture.getAlphaFromRGB;
  40. }
  41. private _shouldUseAlphaFromDiffuseTexture(): boolean {
  42. return this.diffuseTexture != null && this.diffuseTexture.hasAlpha && this.useAlphaFromDiffuseTexture;
  43. }
  44. public getAlphaTestTexture(): BaseTexture {
  45. return this.diffuseTexture;
  46. }
  47. // Methods
  48. public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
  49. if (this.checkReadyOnlyOnce) {
  50. if (this._wasPreviouslyReady) {
  51. return true;
  52. }
  53. }
  54. var scene = this.getScene();
  55. if (!this.checkReadyOnEveryCall) {
  56. if (this._renderId === scene.getRenderId()) {
  57. return true;
  58. }
  59. }
  60. var engine = scene.getEngine();
  61. var defines = [];
  62. var optionalDefines = new Array<string>();
  63. // Textures
  64. if (scene.texturesEnabled) {
  65. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  66. if (!this.diffuseTexture.isReady()) {
  67. return false;
  68. } else {
  69. defines.push("#define DIFFUSE");
  70. }
  71. }
  72. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  73. if (!this.ambientTexture.isReady()) {
  74. return false;
  75. } else {
  76. defines.push("#define AMBIENT");
  77. }
  78. }
  79. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  80. if (!this.opacityTexture.isReady()) {
  81. return false;
  82. } else {
  83. defines.push("#define OPACITY");
  84. if (this.opacityTexture.getAlphaFromRGB) {
  85. defines.push("#define OPACITYRGB");
  86. }
  87. }
  88. }
  89. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  90. if (!this.reflectionTexture.isReady()) {
  91. return false;
  92. } else {
  93. defines.push("#define REFLECTION");
  94. }
  95. }
  96. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  97. if (!this.emissiveTexture.isReady()) {
  98. return false;
  99. } else {
  100. defines.push("#define EMISSIVE");
  101. }
  102. }
  103. if (this.specularTexture && BABYLON.StandardMaterial.SpecularTextureEnabled) {
  104. if (!this.specularTexture.isReady()) {
  105. return false;
  106. } else {
  107. defines.push("#define SPECULAR");
  108. optionalDefines.push(defines[defines.length - 1]);
  109. }
  110. }
  111. }
  112. if (scene.getEngine().getCaps().standardDerivatives && this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  113. if (!this.bumpTexture.isReady()) {
  114. return false;
  115. } else {
  116. defines.push("#define BUMP");
  117. optionalDefines.push(defines[defines.length - 1]);
  118. }
  119. }
  120. // Effect
  121. if (scene.clipPlane) {
  122. defines.push("#define CLIPPLANE");
  123. }
  124. if (engine.getAlphaTesting()) {
  125. defines.push("#define ALPHATEST");
  126. }
  127. if (this._shouldUseAlphaFromDiffuseTexture()) {
  128. defines.push("#define ALPHAFROMDIFFUSE");
  129. }
  130. // Fog
  131. if (scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  132. defines.push("#define FOG");
  133. optionalDefines.push(defines[defines.length - 1]);
  134. }
  135. var shadowsActivated = false;
  136. var lightIndex = 0;
  137. if (scene.lightsEnabled) {
  138. for (var index = 0; index < scene.lights.length; index++) {
  139. var light = scene.lights[index];
  140. if (!light.isEnabled()) {
  141. continue;
  142. }
  143. // Excluded check
  144. if (light._excludedMeshesIds.length > 0) {
  145. for (var excludedIndex = 0; excludedIndex < light._excludedMeshesIds.length; excludedIndex++) {
  146. var excludedMesh = scene.getMeshByID(light._excludedMeshesIds[excludedIndex]);
  147. if (excludedMesh) {
  148. light.excludedMeshes.push(excludedMesh);
  149. }
  150. }
  151. light._excludedMeshesIds = [];
  152. }
  153. // Included check
  154. if (light._includedOnlyMeshesIds.length > 0) {
  155. for (var includedOnlyIndex = 0; includedOnlyIndex < light._includedOnlyMeshesIds.length; includedOnlyIndex++) {
  156. var includedOnlyMesh = scene.getMeshByID(light._includedOnlyMeshesIds[includedOnlyIndex]);
  157. if (includedOnlyMesh) {
  158. light.includedOnlyMeshes.push(includedOnlyMesh);
  159. }
  160. }
  161. light._includedOnlyMeshesIds = [];
  162. }
  163. if (!light.canAffectMesh(mesh)) {
  164. continue;
  165. }
  166. defines.push("#define LIGHT" + lightIndex);
  167. if (lightIndex > 0) {
  168. optionalDefines.push(defines[defines.length - 1]);
  169. }
  170. var type;
  171. if (light instanceof BABYLON.SpotLight) {
  172. type = "#define SPOTLIGHT" + lightIndex;
  173. } else if (light instanceof BABYLON.HemisphericLight) {
  174. type = "#define HEMILIGHT" + lightIndex;
  175. } else {
  176. type = "#define POINTDIRLIGHT" + lightIndex;
  177. }
  178. defines.push(type);
  179. if (lightIndex > 0) {
  180. optionalDefines.push(defines[defines.length - 1]);
  181. }
  182. // Shadows
  183. var shadowGenerator = light.getShadowGenerator();
  184. if (mesh && mesh.receiveShadows && shadowGenerator) {
  185. defines.push("#define SHADOW" + lightIndex);
  186. if (lightIndex > 0) {
  187. optionalDefines.push(defines[defines.length - 1]);
  188. }
  189. if (!shadowsActivated) {
  190. defines.push("#define SHADOWS");
  191. shadowsActivated = true;
  192. }
  193. if (shadowGenerator.useVarianceShadowMap) {
  194. defines.push("#define SHADOWVSM" + lightIndex);
  195. if (lightIndex > 0) {
  196. optionalDefines.push(defines[defines.length - 1]);
  197. }
  198. }
  199. if (shadowGenerator.usePoissonSampling) {
  200. defines.push("#define SHADOWPCF" + lightIndex);
  201. if (lightIndex > 0) {
  202. optionalDefines.push(defines[defines.length - 1]);
  203. }
  204. }
  205. }
  206. lightIndex++;
  207. if (lightIndex == maxSimultaneousLights)
  208. break;
  209. }
  210. }
  211. var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
  212. if (mesh) {
  213. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  214. attribs.push(BABYLON.VertexBuffer.UVKind);
  215. defines.push("#define UV1");
  216. }
  217. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  218. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  219. defines.push("#define UV2");
  220. }
  221. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  222. attribs.push(BABYLON.VertexBuffer.ColorKind);
  223. defines.push("#define VERTEXCOLOR");
  224. }
  225. if (mesh.skeleton && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
  226. attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  227. attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  228. defines.push("#define BONES");
  229. defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
  230. defines.push("#define BONES4");
  231. optionalDefines.push(defines[defines.length - 1]);
  232. }
  233. // Instances
  234. if (useInstances) {
  235. defines.push("#define INSTANCES");
  236. attribs.push("world0");
  237. attribs.push("world1");
  238. attribs.push("world2");
  239. attribs.push("world3");
  240. }
  241. }
  242. // Get correct effect
  243. var join = defines.join("\n");
  244. if (this._cachedDefines != join) {
  245. this._cachedDefines = join;
  246. // Legacy browser patch
  247. var shaderName = "default";
  248. if (!scene.getEngine().getCaps().standardDerivatives) {
  249. shaderName = "legacydefault";
  250. }
  251. this._effect = scene.getEngine().createEffect(shaderName,
  252. attribs,
  253. ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
  254. "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
  255. "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
  256. "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
  257. "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
  258. "vFogInfos", "vFogColor",
  259. "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos",
  260. "mBones",
  261. "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix",
  262. "darkness0", "darkness1", "darkness2", "darkness3"],
  263. ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler",
  264. "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
  265. ],
  266. join, optionalDefines, this.onCompiled, this.onError);
  267. }
  268. if (!this._effect.isReady()) {
  269. return false;
  270. }
  271. this._renderId = scene.getRenderId();
  272. this._wasPreviouslyReady = true;
  273. return true;
  274. }
  275. public unbind(): void {
  276. if (this.reflectionTexture && this.reflectionTexture.isRenderTarget) {
  277. this._effect.setTexture("reflection2DSampler", null);
  278. }
  279. }
  280. public bindOnlyWorldMatrix(world: Matrix): void {
  281. this._effect.setMatrix("world", world);
  282. }
  283. public bind(world: Matrix, mesh: Mesh): void {
  284. var scene = this.getScene();
  285. this._baseColor.copyFrom(this.diffuseColor);
  286. // Matrices
  287. this.bindOnlyWorldMatrix(world);
  288. this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
  289. // Bones
  290. if (mesh.skeleton && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
  291. this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
  292. }
  293. // Textures
  294. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  295. this._effect.setTexture("diffuseSampler", this.diffuseTexture);
  296. this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  297. this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  298. this._baseColor.copyFromFloats(1, 1, 1);
  299. }
  300. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  301. this._effect.setTexture("ambientSampler", this.ambientTexture);
  302. this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
  303. this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
  304. }
  305. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  306. this._effect.setTexture("opacitySampler", this.opacityTexture);
  307. this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
  308. this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
  309. }
  310. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  311. if (this.reflectionTexture.isCube) {
  312. this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
  313. } else {
  314. this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
  315. }
  316. this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
  317. this._effect.setFloat3("vReflectionInfos", this.reflectionTexture.coordinatesMode, this.reflectionTexture.level, this.reflectionTexture.isCube ? 1 : 0);
  318. }
  319. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  320. this._effect.setTexture("emissiveSampler", this.emissiveTexture);
  321. this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
  322. this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
  323. }
  324. if (this.specularTexture && BABYLON.StandardMaterial.SpecularTextureEnabled) {
  325. this._effect.setTexture("specularSampler", this.specularTexture);
  326. this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
  327. this._effect.setMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
  328. }
  329. if (this.bumpTexture && scene.getEngine().getCaps().standardDerivatives && BABYLON.StandardMaterial.BumpTextureEnabled) {
  330. this._effect.setTexture("bumpSampler", this.bumpTexture);
  331. this._effect.setFloat2("vBumpInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);
  332. this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
  333. }
  334. // Colors
  335. scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  336. this._effect.setVector3("vEyePosition", scene.activeCamera.position);
  337. this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
  338. this._effect.setColor4("vDiffuseColor", this._baseColor, this.alpha * mesh.visibility);
  339. this._effect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  340. this._effect.setColor3("vEmissiveColor", this.emissiveColor);
  341. if (scene.lightsEnabled) {
  342. var lightIndex = 0;
  343. for (var index = 0; index < scene.lights.length; index++) {
  344. var light = scene.lights[index];
  345. if (!light.isEnabled()) {
  346. continue;
  347. }
  348. if (!light.canAffectMesh(mesh)) {
  349. continue;
  350. }
  351. if (light instanceof BABYLON.PointLight) {
  352. // Point Light
  353. light.transferToEffect(this._effect, "vLightData" + lightIndex);
  354. } else if (light instanceof BABYLON.DirectionalLight) {
  355. // Directional Light
  356. light.transferToEffect(this._effect, "vLightData" + lightIndex);
  357. } else if (light instanceof BABYLON.SpotLight) {
  358. // Spot Light
  359. light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
  360. } else if (light instanceof BABYLON.HemisphericLight) {
  361. // Hemispheric Light
  362. light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
  363. }
  364. light.diffuse.scaleToRef(light.intensity, this._scaledDiffuse);
  365. light.specular.scaleToRef(light.intensity, this._scaledSpecular);
  366. this._effect.setColor4("vLightDiffuse" + lightIndex, this._scaledDiffuse, light.range);
  367. this._effect.setColor3("vLightSpecular" + lightIndex, this._scaledSpecular);
  368. // Shadows
  369. var shadowGenerator = light.getShadowGenerator();
  370. if (mesh.receiveShadows && shadowGenerator) {
  371. this._effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
  372. this._effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMap());
  373. this._effect.setFloat("darkness" + lightIndex, shadowGenerator.getDarkness());
  374. }
  375. lightIndex++;
  376. if (lightIndex == maxSimultaneousLights)
  377. break;
  378. }
  379. }
  380. if (scene.clipPlane) {
  381. var clipPlane = scene.clipPlane;
  382. this._effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  383. }
  384. // View
  385. if (scene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
  386. this._effect.setMatrix("view", scene.getViewMatrix());
  387. }
  388. // Fog
  389. if (scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  390. this._effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
  391. this._effect.setColor3("vFogColor", scene.fogColor);
  392. }
  393. }
  394. public getAnimatables(): IAnimatable[] {
  395. var results = [];
  396. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  397. results.push(this.diffuseTexture);
  398. }
  399. if (this.ambientTexture && this.ambientTexture.animations && this.ambientTexture.animations.length > 0) {
  400. results.push(this.ambientTexture);
  401. }
  402. if (this.opacityTexture && this.opacityTexture.animations && this.opacityTexture.animations.length > 0) {
  403. results.push(this.opacityTexture);
  404. }
  405. if (this.reflectionTexture && this.reflectionTexture.animations && this.reflectionTexture.animations.length > 0) {
  406. results.push(this.reflectionTexture);
  407. }
  408. if (this.emissiveTexture && this.emissiveTexture.animations && this.emissiveTexture.animations.length > 0) {
  409. results.push(this.emissiveTexture);
  410. }
  411. if (this.specularTexture && this.specularTexture.animations && this.specularTexture.animations.length > 0) {
  412. results.push(this.specularTexture);
  413. }
  414. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  415. results.push(this.bumpTexture);
  416. }
  417. return results;
  418. }
  419. public dispose(forceDisposeEffect?: boolean): void {
  420. if (this.diffuseTexture) {
  421. this.diffuseTexture.dispose();
  422. }
  423. if (this.ambientTexture) {
  424. this.ambientTexture.dispose();
  425. }
  426. if (this.opacityTexture) {
  427. this.opacityTexture.dispose();
  428. }
  429. if (this.reflectionTexture) {
  430. this.reflectionTexture.dispose();
  431. }
  432. if (this.emissiveTexture) {
  433. this.emissiveTexture.dispose();
  434. }
  435. if (this.specularTexture) {
  436. this.specularTexture.dispose();
  437. }
  438. if (this.bumpTexture) {
  439. this.bumpTexture.dispose();
  440. }
  441. super.dispose(forceDisposeEffect);
  442. }
  443. public clone(name: string): StandardMaterial {
  444. var newStandardMaterial = new BABYLON.StandardMaterial(name, this.getScene());
  445. // Base material
  446. newStandardMaterial.checkReadyOnEveryCall = this.checkReadyOnEveryCall;
  447. newStandardMaterial.alpha = this.alpha;
  448. newStandardMaterial.wireframe = this.wireframe;
  449. newStandardMaterial.backFaceCulling = this.backFaceCulling;
  450. // Standard material
  451. if (this.diffuseTexture && this.diffuseTexture.clone) {
  452. newStandardMaterial.diffuseTexture = this.diffuseTexture.clone();
  453. }
  454. if (this.ambientTexture && this.ambientTexture.clone) {
  455. newStandardMaterial.ambientTexture = this.ambientTexture.clone();
  456. }
  457. if (this.opacityTexture && this.opacityTexture.clone) {
  458. newStandardMaterial.opacityTexture = this.opacityTexture.clone();
  459. }
  460. if (this.reflectionTexture && this.reflectionTexture.clone) {
  461. newStandardMaterial.reflectionTexture = this.reflectionTexture.clone();
  462. }
  463. if (this.emissiveTexture && this.emissiveTexture.clone) {
  464. newStandardMaterial.emissiveTexture = this.emissiveTexture.clone();
  465. }
  466. if (this.specularTexture && this.specularTexture.clone) {
  467. newStandardMaterial.specularTexture = this.specularTexture.clone();
  468. }
  469. if (this.bumpTexture && this.bumpTexture.clone) {
  470. newStandardMaterial.bumpTexture = this.bumpTexture.clone();
  471. }
  472. newStandardMaterial.ambientColor = this.ambientColor.clone();
  473. newStandardMaterial.diffuseColor = this.diffuseColor.clone();
  474. newStandardMaterial.specularColor = this.specularColor.clone();
  475. newStandardMaterial.specularPower = this.specularPower;
  476. newStandardMaterial.emissiveColor = this.emissiveColor.clone();
  477. return newStandardMaterial;
  478. }
  479. // Statics
  480. // Flags used to enable or disable a type of texture for all Standard Materials
  481. public static DiffuseTextureEnabled = true;
  482. public static AmbientTextureEnabled = true;
  483. public static OpacityTextureEnabled = true;
  484. public static ReflectionTextureEnabled = true;
  485. public static EmissiveTextureEnabled = true;
  486. public static SpecularTextureEnabled = true;
  487. public static BumpTextureEnabled = true;
  488. }
  489. }