File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
examples/src/examples/loaders Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -64,11 +64,22 @@ class LoadersGlExample extends Example {
64
64
// @ts -ignore: cannot find CORE and DRACO
65
65
const modelData = await CORE . load ( url , DRACO . DracoLoader ) ;
66
66
67
+ // loaded colors only contain RGB, convert it to an array of RGBA with alpha of 255
68
+ const srcColors = modelData . attributes . COLOR_0 . value ;
69
+ const numVertices = srcColors . length / modelData . attributes . COLOR_0 . size ;
70
+ const colors32 = new Uint8Array ( numVertices * 4 ) ;
71
+ for ( let i = 0 ; i < numVertices ; i ++ ) {
72
+ colors32 [ i * 4 + 0 ] = srcColors [ i * 3 + 0 ] ;
73
+ colors32 [ i * 4 + 1 ] = srcColors [ i * 3 + 1 ] ;
74
+ colors32 [ i * 4 + 2 ] = srcColors [ i * 3 + 2 ] ;
75
+ colors32 [ i * 4 + 3 ] = 255 ;
76
+ }
77
+
67
78
// based on the loaded data, create the mesh with position and color vertex data
68
79
const mesh = new pc . Mesh ( app . graphicsDevice ) ;
69
80
mesh . clear ( true , false ) ;
70
81
mesh . setPositions ( modelData . attributes . POSITION . value , modelData . attributes . POSITION . size ) ;
71
- mesh . setColors32 ( modelData . attributes . COLOR_0 . value , modelData . attributes . COLOR_0 . size ) ;
82
+ mesh . setColors32 ( colors32 ) ;
72
83
mesh . update ( pc . PRIMITIVE_POINTS ) ;
73
84
74
85
// Create shader to render mesh as circular points with color
You can’t perform that action at this time.
0 commit comments