SceneBuilder.Materials.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. using System;
  2. using System.IO;
  3. using BabylonExport.Entities;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace Unity3D2Babylon
  7. {
  8. partial class SceneBuilder
  9. {
  10. private void CopyTextureCube(string texturePath, Cubemap cubemap, BabylonTexture babylonTexture)
  11. {
  12. if (!babylonScene.AddTextureCube(texturePath))
  13. {
  14. return;
  15. }
  16. try
  17. {
  18. foreach (CubemapFace face in Enum.GetValues(typeof(CubemapFace)))
  19. {
  20. var faceTexturePath = Path.Combine(babylonScene.OutputPath, Path.GetFileNameWithoutExtension(texturePath));
  21. switch (face)
  22. {
  23. case CubemapFace.PositiveX:
  24. faceTexturePath += "_px.jpg";
  25. break;
  26. case CubemapFace.NegativeX:
  27. faceTexturePath += "_nx.jpg";
  28. break;
  29. case CubemapFace.PositiveY:
  30. faceTexturePath += "_py.jpg";
  31. break;
  32. case CubemapFace.NegativeY:
  33. faceTexturePath += "_ny.jpg";
  34. break;
  35. case CubemapFace.PositiveZ:
  36. faceTexturePath += "_pz.jpg";
  37. break;
  38. case CubemapFace.NegativeZ:
  39. faceTexturePath += "_nz.jpg";
  40. break;
  41. default:
  42. continue;
  43. }
  44. var tempTexture = new Texture2D(cubemap.width, cubemap.height, TextureFormat.RGB24, false);
  45. tempTexture.SetPixels(cubemap.GetPixels(face));
  46. tempTexture.Apply();
  47. // Flip faces in cube texture.
  48. tempTexture = FlipTexture(tempTexture);
  49. File.WriteAllBytes(faceTexturePath, tempTexture.EncodeToJPG());
  50. }
  51. }
  52. catch (Exception ex)
  53. {
  54. Debug.LogException(ex);
  55. }
  56. var textureName = Path.GetFileNameWithoutExtension(texturePath);
  57. babylonTexture.name = textureName;
  58. babylonTexture.isCube = true;
  59. babylonTexture.level = exportationOptions.ReflectionDefaultLevel;
  60. babylonTexture.coordinatesMode = 3;
  61. }
  62. private Texture2D FlipTexture(Texture2D original)
  63. {
  64. Texture2D flipped = new Texture2D(original.width, original.height);
  65. for (int i = 0; i < original.width; i++)
  66. {
  67. for (int j = 0; j < original.height; j++)
  68. {
  69. flipped.SetPixel(i, original.height - j - 1, original.GetPixel(i, j));
  70. }
  71. }
  72. flipped.Apply();
  73. return flipped;
  74. }
  75. private void CopyTexture(string texturePath, Texture2D texture2D, BabylonTexture babylonTexture, bool isLightmap = false)
  76. {
  77. bool needToDelete = false;
  78. // Convert unsupported file extensions
  79. if (texturePath.EndsWith(".psd") || texturePath.EndsWith(".tif") || texturePath.EndsWith(".exr"))
  80. {
  81. try
  82. {
  83. // Change texture import settings to be able to read texture data
  84. var textureImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter;
  85. var previousIsReadable = textureImporter.isReadable;
  86. var previousNormalMap = textureImporter.normalmap;
  87. var previousLightmap = textureImporter.lightmap;
  88. var previousConvertToNormalmap = textureImporter.convertToNormalmap;
  89. var previousTextureType = textureImporter.textureType;
  90. var previousGrayscaleToAlpha = textureImporter.grayscaleToAlpha;
  91. textureImporter.textureType = TextureImporterType.Advanced;
  92. textureImporter.isReadable = true;
  93. textureImporter.lightmap = false;
  94. textureImporter.normalmap = false;
  95. textureImporter.convertToNormalmap = false;
  96. textureImporter.grayscaleToAlpha = false;
  97. AssetDatabase.ImportAsset(texturePath);
  98. var usePNG = texture2D.alphaIsTransparency;
  99. var tempTexture = new Texture2D(texture2D.width, texture2D.height, TextureFormat.ARGB32, false);
  100. if (isLightmap)
  101. {
  102. Color[] pixels = texture2D.GetPixels(0, 0, texture2D.width, texture2D.height);
  103. for (int index = 0; index < pixels.Length; index++)
  104. {
  105. pixels[index].r = pixels[index].r * pixels[index].a * 5;
  106. pixels[index].g = pixels[index].g * pixels[index].a * 5;
  107. pixels[index].b = pixels[index].b * pixels[index].a * 5;
  108. }
  109. tempTexture.SetPixels(pixels);
  110. }
  111. else
  112. {
  113. Color[] pixels = texture2D.GetPixels(0, 0, texture2D.width, texture2D.height);
  114. for (int index = 0; index < pixels.Length; index++)
  115. {
  116. usePNG |= pixels[index].a <= 0.99999f;
  117. }
  118. tempTexture.SetPixels32(texture2D.GetPixels32());
  119. }
  120. tempTexture.Apply();
  121. texturePath = Path.Combine(Path.GetTempPath(), Path.GetFileName(texturePath));
  122. var extension = usePNG ? ".png": ".jpg";
  123. texturePath = texturePath.Replace(".psd", extension).Replace(".tif", extension).Replace(".exr", extension);
  124. File.WriteAllBytes(texturePath, usePNG ? tempTexture.EncodeToPNG() : tempTexture.EncodeToJPG());
  125. needToDelete = true;
  126. // Restore
  127. textureImporter.isReadable = previousIsReadable;
  128. textureImporter.normalmap = previousNormalMap;
  129. textureImporter.lightmap = previousLightmap;
  130. textureImporter.convertToNormalmap = previousConvertToNormalmap;
  131. textureImporter.textureType = previousTextureType;
  132. textureImporter.grayscaleToAlpha = previousGrayscaleToAlpha;
  133. AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);
  134. }
  135. catch (Exception ex)
  136. {
  137. Debug.LogException(ex);
  138. }
  139. }
  140. else if (texture2D.alphaIsTransparency || texturePath.EndsWith(".png"))
  141. {
  142. babylonTexture.hasAlpha = true;
  143. }
  144. else
  145. {
  146. babylonTexture.hasAlpha = false;
  147. }
  148. var textureName = Path.GetFileName(texturePath);
  149. babylonTexture.name = textureName;
  150. babylonScene.AddTexture(texturePath);
  151. if (needToDelete)
  152. {
  153. File.Delete(texturePath);
  154. }
  155. }
  156. private BabylonMaterial DumpMaterial(Material material, Renderer renderer)
  157. {
  158. if (renderer.sharedMaterial.shader.name == "Standard")
  159. {
  160. return DumpPBRMaterial(renderer.sharedMaterial, renderer, true);
  161. }
  162. else if (renderer.sharedMaterial.shader.name == "Standard (Specular setup)")
  163. {
  164. return DumpPBRMaterial(renderer.sharedMaterial, renderer, false);
  165. }
  166. return DumpStandardMaterial(material, renderer);
  167. }
  168. private BabylonMaterial DumpStandardMaterial(Material material, Renderer renderer)
  169. {
  170. var materialNotSupported = false;
  171. if (!materialsDictionary.ContainsKey(material.name))
  172. {
  173. var bMat = new BabylonStandardMaterial
  174. {
  175. name = material.name,
  176. id = Guid.NewGuid().ToString(),
  177. diffuse = new float[4],
  178. specular = new float[4]
  179. };
  180. bMat.diffuse[0] = 1.0f;
  181. bMat.diffuse[1] = 1.0f;
  182. bMat.diffuse[2] = 1.0f;
  183. bMat.diffuse[3] = 1.0f;
  184. if (material.HasProperty("_Color"))
  185. {
  186. bMat.diffuse = material.color.ToFloat();
  187. }
  188. if (material.HasProperty("_SpecColor"))
  189. {
  190. var specColor = material.GetColor("_SpecColor");
  191. bMat.specular = specColor.ToFloat();
  192. }
  193. if (material.HasProperty("_Shininess"))
  194. {
  195. var specShininess = material.GetFloat("_Shininess");
  196. bMat.specularPower = specShininess * 128;
  197. }
  198. if (material.HasProperty("_Emission"))
  199. {
  200. var emissiveColor = material.GetColor("_Emission");
  201. bMat.emissive = emissiveColor.ToFloat();
  202. }
  203. if (material.mainTexture && material.mainTexture.GetType().FullName == "UnityEngine.ProceduralTexture")
  204. {
  205. materialNotSupported = true;
  206. Debug.LogWarning("ProceduralTexture: " + material.mainTexture.name + " not supported by Babylon.js");
  207. }
  208. if (material.mainTexture && !(materialNotSupported))
  209. {
  210. var mainTexturePath = AssetDatabase.GetAssetPath(material.mainTexture);
  211. bMat.diffuseTexture = new BabylonTexture
  212. {
  213. uScale = material.mainTextureScale.x,
  214. vScale = material.mainTextureScale.y,
  215. uOffset = material.mainTextureOffset.x,
  216. vOffset = material.mainTextureOffset.y
  217. };
  218. var mainTexture2D = material.mainTexture as Texture2D;
  219. CopyTexture(mainTexturePath, mainTexture2D, bMat.diffuseTexture);
  220. var alphaCuttOff = 0f;
  221. if (material.HasProperty("_Cutoff"))
  222. {
  223. alphaCuttOff = material.GetFloat("_Cutoff");
  224. }
  225. if ((mainTexture2D && mainTexture2D.alphaIsTransparency) || alphaCuttOff > 0)
  226. {
  227. bMat.diffuseTexture.hasAlpha = true;
  228. bMat.backFaceCulling = false;
  229. }
  230. bMat.diffuse[0] = 1.0f;
  231. bMat.diffuse[1] = 1.0f;
  232. bMat.diffuse[2] = 1.0f;
  233. bMat.diffuse[3] = 1.0f;
  234. }
  235. bMat.bumpTexture = DumpTextureFromMaterial(material, "_BumpMap");
  236. bMat.emissiveTexture = DumpTextureFromMaterial(material, "_Illum");
  237. bMat.ambientTexture = DumpTextureFromMaterial(material, "_LightMap");
  238. bMat.reflectionTexture = DumpTextureFromMaterial(material, "_Cube");
  239. if (bMat.ambientTexture == null && renderer.lightmapIndex >= 0 && renderer.lightmapIndex != 255 && LightmapSettings.lightmaps.Length > renderer.lightmapIndex)
  240. {
  241. var lightmap = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapFar;
  242. bMat.lightmapTexture = DumpTexture(lightmap, isLightmap: true);
  243. bMat.lightmapTexture.coordinatesIndex = 1;
  244. bMat.useLightmapAsShadowmap = true;
  245. bMat.lightmapTexture.uScale = renderer.lightmapScaleOffset.x;
  246. bMat.lightmapTexture.vScale = renderer.lightmapScaleOffset.y;
  247. bMat.lightmapTexture.uOffset = renderer.lightmapScaleOffset.z;
  248. bMat.lightmapTexture.vOffset = renderer.lightmapScaleOffset.w;
  249. }
  250. materialsDictionary.Add(bMat.name, bMat);
  251. return bMat;
  252. }
  253. return materialsDictionary[material.name];
  254. }
  255. private BabylonMaterial DumpPBRMaterial(Material material, Renderer renderer, bool metallic)
  256. {
  257. if (materialsDictionary.ContainsKey(material.name))
  258. {
  259. return materialsDictionary[material.name];
  260. }
  261. var babylonPbrMaterial = new BabylonPBRMaterial
  262. {
  263. name = material.name,
  264. id = Guid.NewGuid().ToString(),
  265. albedo = new float[4],
  266. useEmissiveAsIllumination = true,
  267. useSpecularOverAlpha = true,
  268. useRadianceOverAlpha = true,
  269. };
  270. babylonPbrMaterial.environmentIntensity = RenderSettings.ambientIntensity;
  271. // Albedo
  272. if (material.HasProperty("_Color"))
  273. {
  274. babylonPbrMaterial.albedo = material.color.ToFloat();
  275. }
  276. babylonPbrMaterial.albedoTexture = DumpTextureFromMaterial(material, "_MainTex");
  277. // Transparency
  278. DumpTransparency(material, babylonPbrMaterial);
  279. // Glossiess/Reflectivity
  280. DumpGlossinessReflectivity(material, metallic, babylonPbrMaterial);
  281. // Occlusion
  282. babylonPbrMaterial.ambientTexture = DumpTextureFromMaterial(material, "_OcclusionMap");
  283. if (babylonPbrMaterial.ambientTexture != null && material.HasProperty("_OcclusionStrength"))
  284. {
  285. babylonPbrMaterial.ambientTexture.level = material.GetFloat("_OcclusionStrength");
  286. }
  287. // Emissive
  288. if (material.HasProperty("_EmissionColor"))
  289. {
  290. babylonPbrMaterial.emissive = material.GetColor("_EmissionColor").ToFloat();
  291. }
  292. babylonPbrMaterial.emissiveTexture = DumpTextureFromMaterial(material, "_EmissionMap");
  293. // Normal
  294. babylonPbrMaterial.bumpTexture = DumpTextureFromMaterial(material, "_BumpMap");
  295. if (babylonPbrMaterial.bumpTexture != null && material.HasProperty("_BumpMapScale"))
  296. {
  297. babylonPbrMaterial.bumpTexture.level = material.GetFloat("_BumpMapScale");
  298. }
  299. // Reflection
  300. babylonPbrMaterial.reflectionTexture = DumpReflectionTexture();
  301. materialsDictionary.Add(babylonPbrMaterial.name, babylonPbrMaterial);
  302. return babylonPbrMaterial;
  303. }
  304. private void DumpGlossinessReflectivity(Material material, bool metallic, BabylonPBRMaterial babylonPbrMaterial)
  305. {
  306. if (material.HasProperty("_Glossiness"))
  307. {
  308. babylonPbrMaterial.microSurface = material.GetFloat("_Glossiness");
  309. }
  310. if (metallic)
  311. {
  312. if (material.HasProperty("_Metallic"))
  313. {
  314. var metalness = material.GetFloat("_Metallic");
  315. babylonPbrMaterial.reflectivity = new float[] { metalness * babylonPbrMaterial.albedo[0],
  316. metalness * babylonPbrMaterial.albedo[1],
  317. metalness * babylonPbrMaterial.albedo[2] };
  318. if (babylonPbrMaterial.albedoTexture != null)
  319. {
  320. var albedoTexture = material.GetTexture("_MainTex") as Texture2D;
  321. if (albedoTexture != null)
  322. {
  323. var albedoPixels = GetPixels(albedoTexture);
  324. var reflectivityTexture = new Texture2D(albedoTexture.width, albedoTexture.height, TextureFormat.RGBA32, false);
  325. reflectivityTexture.alphaIsTransparency = true;
  326. babylonPbrMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  327. var metallicTexture = material.GetTexture("_MetallicGlossMap") as Texture2D;
  328. if (metallicTexture == null)
  329. {
  330. for (var i = 0; i < albedoTexture.width; i++)
  331. {
  332. for (var j = 0; j < albedoTexture.height; j++)
  333. {
  334. albedoPixels[j * albedoTexture.width + i].r *= metalness;
  335. albedoPixels[j * albedoTexture.width + i].g *= metalness;
  336. albedoPixels[j * albedoTexture.width + i].b *= metalness;
  337. albedoPixels[j * albedoTexture.width + i].a = babylonPbrMaterial.microSurface;
  338. }
  339. }
  340. }
  341. else
  342. {
  343. var metallicPixels = GetPixels(metallicTexture);
  344. for (var i = 0; i < albedoTexture.width; i++)
  345. {
  346. for (var j = 0; j < albedoTexture.height; j++)
  347. {
  348. var metallicPixel = metallicPixels[j * albedoTexture.width + i];
  349. albedoPixels[j * albedoTexture.width + i].r *= metallicPixel.r;
  350. albedoPixels[j * albedoTexture.width + i].g *= metallicPixel.r;
  351. albedoPixels[j * albedoTexture.width + i].b *= metallicPixel.r;
  352. albedoPixels[j * albedoTexture.width + i].a = metallicPixel.a;
  353. }
  354. }
  355. }
  356. reflectivityTexture.SetPixels(albedoPixels);
  357. reflectivityTexture.Apply();
  358. var textureName = albedoTexture.name + "_MetallicGlossMap.png";
  359. var babylonTexture = new BabylonTexture { name = textureName };
  360. var textureScale = material.GetTextureScale("_MainTex");
  361. babylonTexture.uScale = textureScale.x;
  362. babylonTexture.vScale = textureScale.y;
  363. var textureOffset = material.GetTextureOffset("_MainTex");
  364. babylonTexture.uOffset = textureOffset.x;
  365. babylonTexture.vOffset = textureOffset.y;
  366. var reflectivityTexturePath = Path.Combine(Path.GetTempPath(), textureName);
  367. File.WriteAllBytes(reflectivityTexturePath, reflectivityTexture.EncodeToPNG());
  368. babylonScene.AddTexture(reflectivityTexturePath);
  369. if (File.Exists(reflectivityTexturePath))
  370. {
  371. File.Delete(reflectivityTexturePath);
  372. }
  373. babylonPbrMaterial.reflectivityTexture = babylonTexture;
  374. }
  375. }
  376. //else
  377. //{
  378. // TODO. Manage Albedo Cube Texture.
  379. //}
  380. }
  381. }
  382. else
  383. {
  384. if (material.HasProperty("_SpecColor"))
  385. {
  386. babylonPbrMaterial.reflectivity = material.GetColor("_SpecColor").ToFloat();
  387. }
  388. babylonPbrMaterial.reflectivityTexture = DumpTextureFromMaterial(material, "_SpecGlossMap");
  389. if (babylonPbrMaterial.reflectivityTexture != null && babylonPbrMaterial.reflectivityTexture.hasAlpha)
  390. {
  391. babylonPbrMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  392. }
  393. }
  394. }
  395. private static Color[] GetPixels(Texture2D texture)
  396. {
  397. string texturePath = AssetDatabase.GetAssetPath(texture);
  398. // Change texture import settings to be able to read texture data
  399. var textureImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter;
  400. var previousIsReadable = textureImporter.isReadable;
  401. var previousNormalMap = textureImporter.normalmap;
  402. var previousLightmap = textureImporter.lightmap;
  403. var previousConvertToNormalmap = textureImporter.convertToNormalmap;
  404. var previousTextureType = textureImporter.textureType;
  405. var previousGrayscaleToAlpha = textureImporter.grayscaleToAlpha;
  406. textureImporter.textureType = TextureImporterType.Advanced;
  407. textureImporter.isReadable = true;
  408. textureImporter.lightmap = false;
  409. textureImporter.normalmap = false;
  410. textureImporter.convertToNormalmap = false;
  411. textureImporter.grayscaleToAlpha = false;
  412. AssetDatabase.ImportAsset(texturePath);
  413. var pixels = texture.GetPixels();
  414. // Restore
  415. textureImporter.isReadable = previousIsReadable;
  416. textureImporter.normalmap = previousNormalMap;
  417. textureImporter.lightmap = previousLightmap;
  418. textureImporter.convertToNormalmap = previousConvertToNormalmap;
  419. textureImporter.textureType = previousTextureType;
  420. textureImporter.grayscaleToAlpha = previousGrayscaleToAlpha;
  421. return pixels;
  422. }
  423. private static void DumpTransparency(Material material, BabylonPBRMaterial babylonPbrMaterial)
  424. {
  425. if (material.HasProperty("_Mode"))
  426. {
  427. var mode = material.GetFloat("_Mode");
  428. if (mode >= 2.0f)
  429. {
  430. // Transparent Albedo
  431. if (babylonPbrMaterial.albedoTexture != null && babylonPbrMaterial.albedoTexture.hasAlpha)
  432. {
  433. babylonPbrMaterial.useAlphaFromAlbedoTexture = true;
  434. }
  435. // Material Alpha
  436. else
  437. {
  438. babylonPbrMaterial.alpha = babylonPbrMaterial.albedo[3];
  439. }
  440. }
  441. else if (mode == 1.0f)
  442. {
  443. // Cutout
  444. // Follow the texture hasAlpha property.
  445. }
  446. else
  447. {
  448. // Opaque
  449. if (babylonPbrMaterial.albedoTexture != null)
  450. {
  451. babylonPbrMaterial.albedoTexture.hasAlpha = false;
  452. }
  453. babylonPbrMaterial.alpha = 1.0f;
  454. }
  455. }
  456. }
  457. private BabylonTexture DumpReflectionTexture()
  458. {
  459. if (sceneReflectionTexture != null)
  460. {
  461. return sceneReflectionTexture;
  462. }
  463. // Take only reflection source currently and not the RenderSettings.ambientMode
  464. if (RenderSettings.defaultReflectionMode == UnityEngine.Rendering.DefaultReflectionMode.Skybox)
  465. {
  466. var skybox = RenderSettings.skybox;
  467. if (skybox != null)
  468. {
  469. if (skybox.shader.name == "Skybox/Cubemap")
  470. {
  471. var cubeMap = skybox.GetTexture("_Tex") as Cubemap;
  472. if (cubeMap != null)
  473. {
  474. sceneReflectionTexture = new BabylonTexture();
  475. CopyTextureCube("sceneReflectionTexture.hdr", cubeMap, sceneReflectionTexture);
  476. sceneReflectionTexture.level = RenderSettings.reflectionIntensity;
  477. }
  478. }
  479. //else if (skybox.shader.name == "Skybox/6 Sided")
  480. //{
  481. // // TODO. HDR faces.
  482. //}
  483. }
  484. }
  485. else if (RenderSettings.customReflection != null)
  486. {
  487. var cubeMap = RenderSettings.customReflection;
  488. sceneReflectionTexture = new BabylonTexture();
  489. CopyTextureCube("sceneReflectionTexture.hdr", cubeMap, sceneReflectionTexture);
  490. sceneReflectionTexture.level = RenderSettings.reflectionIntensity;
  491. }
  492. return sceneReflectionTexture;
  493. }
  494. private BabylonTexture DumpTextureFromMaterial(Material material, string name)
  495. {
  496. if (!material.HasProperty(name))
  497. {
  498. return null;
  499. }
  500. var texture = material.GetTexture(name);
  501. return DumpTexture(texture, material, name);
  502. }
  503. private BabylonTexture DumpTexture(Texture texture, Material material = null, string name = "", bool isLightmap = false)
  504. {
  505. if (texture == null)
  506. {
  507. return null;
  508. }
  509. var texturePath = AssetDatabase.GetAssetPath(texture);
  510. var textureName = Path.GetFileName(texturePath);
  511. var babylonTexture = new BabylonTexture { name = textureName };
  512. if (material != null)
  513. {
  514. var textureScale = material.GetTextureScale(name);
  515. babylonTexture.uScale = textureScale.x;
  516. babylonTexture.vScale = textureScale.y;
  517. var textureOffset = material.GetTextureOffset(name);
  518. babylonTexture.uOffset = textureOffset.x;
  519. babylonTexture.vOffset = textureOffset.y;
  520. }
  521. var texture2D = texture as Texture2D;
  522. if (texture2D)
  523. {
  524. CopyTexture(texturePath, texture2D, babylonTexture, isLightmap);
  525. }
  526. else
  527. {
  528. var cubemap = texture as Cubemap;
  529. if (cubemap != null)
  530. {
  531. CopyTextureCube(texturePath, cubemap, babylonTexture);
  532. }
  533. }
  534. return babylonTexture;
  535. }
  536. }
  537. }