@@ -630,6 +630,93 @@ describe(
630
630
} ) ;
631
631
} ) ;
632
632
633
+ it ( "creates a material using fromTypeAsync" , async function ( ) {
634
+ const material = await Material . fromTypeAsync ( "Color" ) ;
635
+ renderMaterial ( material ) ;
636
+ } ) ;
637
+
638
+ it ( "loads a 2D texture image synchronously when awaiting fromTypeAsync" , async function ( ) {
639
+ const imageMaterial = await Material . fromTypeAsync ( "Image" , {
640
+ image : "./Data/Images/Blue.png" ,
641
+ } ) ;
642
+ renderMaterial ( imageMaterial ) ;
643
+ } ) ;
644
+
645
+ it ( "loads cubemap images synchronously when awaiting fromTypeAsync" , async function ( ) {
646
+ // First make a material with a cubemap, then use its type to make a second cubemap material asynchronously.
647
+ const material = new Material ( {
648
+ strict : true ,
649
+ fabric : {
650
+ uniforms : {
651
+ cubeMap : {
652
+ positiveX : "./Data/Images/Blue.png" ,
653
+ negativeX : "./Data/Images/Blue.png" ,
654
+ positiveY : "./Data/Images/Blue.png" ,
655
+ negativeY : "./Data/Images/Blue.png" ,
656
+ positiveZ : "./Data/Images/Blue.png" ,
657
+ negativeZ : "./Data/Images/Blue.png" ,
658
+ } ,
659
+ } ,
660
+ source :
661
+ "uniform samplerCube cubeMap;\n" +
662
+ "czm_material czm_getMaterial(czm_materialInput materialInput)\n" +
663
+ "{\n" +
664
+ " czm_material material = czm_getDefaultMaterial(materialInput);\n" +
665
+ " material.diffuse = czm_textureCube(cubeMap, vec3(1.0)).xyz;\n" +
666
+ " return material;\n" +
667
+ "}\n" ,
668
+ } ,
669
+ } ) ;
670
+
671
+ const materialFromTypeAsync = await Material . fromTypeAsync (
672
+ material . type ,
673
+ {
674
+ cubeMap : {
675
+ positiveX : "./Data/Images/Green.png" ,
676
+ negativeX : "./Data/Images/Green.png" ,
677
+ positiveY : "./Data/Images/Green.png" ,
678
+ negativeY : "./Data/Images/Green.png" ,
679
+ positiveZ : "./Data/Images/Green.png" ,
680
+ negativeZ : "./Data/Images/Green.png" ,
681
+ } ,
682
+ } ,
683
+ ) ;
684
+
685
+ renderMaterial ( materialFromTypeAsync ) ;
686
+ } ) ;
687
+
688
+ it ( "loads sub-materials synchronously when awaiting fromTypeAsync" , async function ( ) {
689
+ // First make a material with submaterials, then use its type to make a second material asynchronously.
690
+ const material = new Material ( {
691
+ strict : true ,
692
+ fabric : {
693
+ materials : {
694
+ greenMaterial : {
695
+ type : "Image" ,
696
+ uniforms : {
697
+ image : "./Data/Images/Green.png" , // Green image
698
+ } ,
699
+ } ,
700
+ blueMaterial : {
701
+ type : "Image" ,
702
+ uniforms : {
703
+ image : "./Data/Images/Blue.png" , // Blue image
704
+ } ,
705
+ } ,
706
+ } ,
707
+ components : {
708
+ diffuse :
709
+ "clamp(greenMaterial.diffuse + blueMaterial.diffuse, 0.0, 1.0)" ,
710
+ } ,
711
+ } ,
712
+ } ) ;
713
+
714
+ const materialFromTypeAsync = await Material . fromTypeAsync ( material . type ) ;
715
+ renderMaterial ( materialFromTypeAsync , false , function ( rgba ) {
716
+ expect ( rgba ) . toEqual ( [ 0 , 255 , 255 , 255 ] ) ; // Expect cyan from green + blue
717
+ } ) ;
718
+ } ) ;
719
+
633
720
it ( "creates material with custom texture filter" , function ( ) {
634
721
const materialLinear = new Material ( {
635
722
fabric : {
0 commit comments