@@ -7,15 +7,21 @@ class TextureBasisExample extends Example {
7
7
static CATEGORY = 'Graphics' ;
8
8
static NAME = 'Texture Basis' ;
9
9
10
+ // Color textures have been converted with the following arguments:
11
+ // basisu seaside-rocks01-gloss.jpg -q 255 -mipmap
12
+ // The normalmap has been converted with the following arguments:
13
+ // basisu seaside-rocks01-normal.jpg -normal_map -swizzle gggr -renorm -q 255 -mipmap
10
14
load ( ) {
11
15
return < >
12
- < AssetLoader name = 'seaBasis' type = 'texture' url = 'static/assets/textures/sea.basis' />
13
- < AssetLoader name = 'playcanvasBasis' type = 'texture' url = 'static/assets/textures/playcanvas.basis' />
16
+ < AssetLoader name = 'color' type = 'texture' url = 'static/assets/textures/seaside-rocks01-color.basis' />
17
+ < AssetLoader name = 'gloss' type = 'texture' url = 'static/assets/textures/seaside-rocks01-gloss.basis' />
18
+ < AssetLoader name = 'normal' type = 'texture' url = 'static/assets/textures/seaside-rocks01-normal.basis' data = { { type : pc . TEXTURETYPE_SWIZZLEGGGR } } />
19
+ < AssetLoader name = 'helipad' type = 'cubemap' url = 'static/assets/cubemaps/helipad.dds' data = { { type : pc . TEXTURETYPE_RGBM } } />
14
20
</ > ;
15
21
}
16
22
17
23
// @ts -ignore: override class function
18
- example ( canvas : HTMLCanvasElement , assets : { seaBasis : pc . Asset , playcanvasBasis : pc . Asset } ) : void {
24
+ example ( canvas : HTMLCanvasElement , assets : { color : pc . Asset , gloss : pc . Asset , normal : pc . Asset , helipad : pc . Asset } ) : void {
19
25
20
26
// Create the application and start the update loop
21
27
const app = new pc . Application ( canvas , { } ) ;
@@ -33,30 +39,48 @@ class TextureBasisExample extends Example {
33
39
app . setCanvasFillMode ( pc . FILLMODE_FILL_WINDOW ) ;
34
40
app . setCanvasResolution ( pc . RESOLUTION_AUTO ) ;
35
41
36
- app . scene . ambientLight = new pc . Color ( 1 , 1 , 1 ) ;
37
-
38
- // material using basis texture
39
- const material1 = new pc . StandardMaterial ( ) ;
40
- material1 . diffuseMap = assets . seaBasis . resource ;
41
- material1 . update ( ) ;
42
-
43
- // Create a Entity with a Box render component
44
- const box1 = new pc . Entity ( ) ;
45
- box1 . addComponent ( "render" , {
46
- type : "box" ,
47
- material : material1
42
+ // Set skybox
43
+ app . scene . gammaCorrection = pc . GAMMA_SRGB ;
44
+ app . scene . toneMapping = pc . TONEMAP_ACES ;
45
+ app . scene . skyboxMip = 1 ;
46
+ app . scene . skyboxIntensity = 0.7 ;
47
+ app . scene . setSkybox ( assets . helipad . resources ) ;
48
+
49
+ // Create directional light
50
+ const light = new pc . Entity ( ) ;
51
+ light . addComponent ( 'light' , {
52
+ type : 'directional'
48
53
} ) ;
49
-
50
- // another material using basis texture
51
- const material2 = new pc . StandardMaterial ( ) ;
52
- material2 . diffuseMap = assets . playcanvasBasis . resource ;
53
- material2 . update ( ) ;
54
-
55
- const box2 = new pc . Entity ( ) ;
56
- box2 . addComponent ( "render" , {
57
- type : "box" ,
58
- material : material2
54
+ light . setLocalEulerAngles ( 45 , 0 , 45 ) ;
55
+
56
+ // Construct material
57
+ const material = new pc . StandardMaterial ( ) ;
58
+ material . useMetalness = true ;
59
+ material . diffuse = new pc . Color ( 0.3 , 0.3 , 0.3 ) ;
60
+ material . shininess = 80 ;
61
+ material . metalness = 0.7 ;
62
+ material . diffuseMap = assets . color . resource ;
63
+ material . normalMap = assets . normal . resource ;
64
+ material . glossMap = assets . gloss . resource ;
65
+ material . diffuseMapTiling . set ( 7 , 7 ) ;
66
+ material . normalMapTiling . set ( 7 , 7 ) ;
67
+ material . glossMapTiling . set ( 7 , 7 ) ;
68
+ material . update ( ) ;
69
+
70
+ // Create a torus shape
71
+ const torus = pc . createTorus ( app . graphicsDevice , {
72
+ tubeRadius : 0.2 ,
73
+ ringRadius : 0.3 ,
74
+ segments : 50 ,
75
+ sides : 40
76
+ } ) ;
77
+ const shape = new pc . Entity ( ) ;
78
+ shape . addComponent ( 'render' , {
79
+ material : material ,
80
+ meshInstances : [ new pc . MeshInstance ( torus , material ) ]
59
81
} ) ;
82
+ shape . setPosition ( 0 , 0 , 0 ) ;
83
+ shape . setLocalScale ( 2 , 2 , 2 ) ;
60
84
61
85
// Create an Entity with a camera component
62
86
const camera = new pc . Entity ( ) ;
@@ -65,27 +89,20 @@ class TextureBasisExample extends Example {
65
89
} ) ;
66
90
67
91
// Adjust the camera position
68
- camera . translate ( 0 , 0 , 5 ) ;
92
+ camera . translate ( 0 , 0 , 4 ) ;
69
93
70
94
// Add the new Entities to the hierarchy
71
- app . root . addChild ( box1 ) ;
72
- app . root . addChild ( box2 ) ;
95
+ app . root . addChild ( light ) ;
96
+ app . root . addChild ( shape ) ;
73
97
app . root . addChild ( camera ) ;
74
98
75
- box1 . setPosition ( 0 , - 1 , 0 ) ;
76
- box2 . setPosition ( 0 , 1 , 0 ) ;
77
-
78
99
// Set an update function on the app's update event
79
100
let angle = 0 ;
80
101
app . on ( "update" , function ( dt ) {
81
- angle += dt ;
82
- if ( angle > 360 ) {
83
- angle = 0 ;
84
- }
102
+ angle = ( angle + dt * 10 ) % 360 ;
85
103
86
104
// Rotate the boxes
87
- box1 . setEulerAngles ( angle * 2 , angle * 4 , angle * 8 ) ;
88
- box2 . setEulerAngles ( 90 - angle * 12 , 120 - angle * 8 , 150 - angle * 10 ) ;
105
+ shape . setEulerAngles ( angle , angle * 2 , angle * 4 ) ;
89
106
} ) ;
90
107
}
91
108
}
0 commit comments