| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Models; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | public class EntityMaterialUpdateTestController : MonoBehaviour |
| | 9 | | { |
| | 10 | | void Start() |
| | 11 | | { |
| 0 | 12 | | var sceneController = Environment.i.world.sceneController; |
| 0 | 13 | | var scenesToLoad = (Resources.Load("TestJSON/SceneLoadingTest") as TextAsset).text; |
| | 14 | |
|
| 0 | 15 | | sceneController.UnloadAllScenes(); |
| 0 | 16 | | sceneController.LoadParcelScenes(scenesToLoad); |
| | 17 | |
|
| 0 | 18 | | var scene = Environment.i.world.state.loadedScenes["0,0"] as ParcelScene; |
| | 19 | |
|
| 0 | 20 | | DCLTexture dclAtlasTexture = TestHelpers.CreateDCLTexture( |
| | 21 | | scene, |
| | 22 | | TestAssetsUtils.GetPath() + "/Images/atlas.png", |
| | 23 | | DCLTexture.BabylonWrapMode.CLAMP, |
| | 24 | | FilterMode.Bilinear); |
| | 25 | |
|
| 0 | 26 | | DCLTexture dclAvatarTexture = TestHelpers.CreateDCLTexture( |
| | 27 | | scene, |
| | 28 | | TestAssetsUtils.GetPath() + "/Images/avatar.png", |
| | 29 | | DCLTexture.BabylonWrapMode.CLAMP, |
| | 30 | | FilterMode.Bilinear); |
| | 31 | |
|
| | 32 | |
|
| | 33 | | IDCLEntity entity; |
| | 34 | |
|
| 0 | 35 | | TestHelpers.CreateEntityWithBasicMaterial( |
| | 36 | | scene, |
| | 37 | | new BasicMaterial.Model |
| | 38 | | { |
| | 39 | | texture = dclAtlasTexture.id, |
| | 40 | | }, |
| | 41 | | out entity); |
| | 42 | |
|
| 0 | 43 | | TestHelpers.CreateEntityWithPBRMaterial(scene, |
| | 44 | | new PBRMaterial.Model |
| | 45 | | { |
| | 46 | | albedoTexture = dclAvatarTexture.id, |
| | 47 | | metallic = 0, |
| | 48 | | roughness = 1, |
| | 49 | | }, |
| | 50 | | out entity); |
| | 51 | |
|
| 0 | 52 | | PBRMaterial mat = TestHelpers.CreateEntityWithPBRMaterial(scene, |
| | 53 | | new PBRMaterial.Model |
| | 54 | | { |
| | 55 | | albedoTexture = dclAvatarTexture.id, |
| | 56 | | metallic = 1, |
| | 57 | | roughness = 1, |
| | 58 | | alphaTexture = dclAvatarTexture.id, |
| | 59 | | }, |
| | 60 | | out entity); |
| | 61 | |
|
| | 62 | | // Re-assign last PBR material to new entity |
| 0 | 63 | | BoxShape shape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(5, 1, 2)); |
| 0 | 64 | | BasicMaterial m = |
| | 65 | | TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_ID.BASIC_MATERIAL); |
| | 66 | |
|
| | 67 | | Color color1; |
| 0 | 68 | | ColorUtility.TryParseHtmlString("#FF9292", out color1); |
| | 69 | |
|
| | 70 | | // Update material attached to 2 entities, adding albedoColor |
| 0 | 71 | | scene.SharedComponentUpdate(m.id, JsonUtility.ToJson(new DCL.Components.PBRMaterial.Model |
| | 72 | | { |
| | 73 | | albedoTexture = dclAvatarTexture.id, |
| | 74 | | metallic = 1, |
| | 75 | | roughness = 1, |
| | 76 | | alphaTexture = dclAvatarTexture.id, |
| | 77 | | albedoColor = color1 |
| | 78 | | })); |
| 0 | 79 | | } |
| | 80 | | } |