99from PySide6 .QtWidgets import QApplication
1010from wgpu .utils import get_default_device
1111
12- from ncca .ngl import Mat4 , PerspMode , PrimData , Prims , Vec3 , look_at , perspective
12+ from ncca .ngl import Mat4 , PerspMode , PrimData , Vec3 , look_at , perspective
1313from ncca .ngl .webgpu import PipelineFactory , PipelineType , WebGPUWidget , __version__
1414
1515NUM_POINTS = 10000
@@ -319,26 +319,22 @@ def _create_buffers(self, num_points):
319319
320320 def _create_instanced_geometry_data (self , rng ):
321321 """Create data for instanced geometry rendering."""
322- # Create geometry using PrimData (try different shapes )
322+ # Create geometry using PrimData (in correct interleaved format )
323323 # geometry_data = PrimData.sphere(0.25, 16) # Small sphere with good detail
324324 # geometry_data = PrimData.cylinder(0.25, 1, 40, 40) # Small cylinder with good detail
325- geometry_data = PrimData .cone (0.25 , 1 , 20 , 10 ) # Small cone with good detail
325+ # geometry_data = PrimData.cone(0.25, 1, 20, 10) # Small cone with good detail
326326 geometry_data = PrimData .primitive ("teapot" )
327- # Ensure data is in (num_vertices, 8) format
328- # Some PrimData methods return 1D arrays, others return 2D arrays
327+
328+ # Ensure data is in (num_vertices, 8) format for new API
329329 if geometry_data .ndim == 1 :
330330 geometry_data = geometry_data .reshape (- 1 , 8 )
331331 elif geometry_data .shape [1 ] != 8 :
332332 raise ValueError (
333333 f"Expected 8 components per vertex, got { geometry_data .shape [1 ]} "
334334 )
335335
336- num_vertices = len (geometry_data )
337-
338- # Extract vertices, normals, and UVs from the interleaved data
339- self .geometry_vertices = geometry_data [:, :3 ] # x, y, z
340- self .geometry_normals = geometry_data [:, 3 :6 ] # nx, ny, nz
341- self .geometry_uvs = geometry_data [:, 6 :8 ] # u, v
336+ # Store the complete interleaved geometry data (x,y,z,nx,ny,nz,u,v)
337+ self .geometry_data = geometry_data
342338
343339 # Create instance positions (grid of geometry instances)
344340 grid_size = 5
@@ -506,13 +502,11 @@ def _render_multi_colour_instanced_geometry_pipeline(self, render_pass):
506502 """Render multi-colour instanced geometry."""
507503 pipeline = self .pipelines [self .current_pipeline_index ][0 ]
508504
509- # Set instanced geometry data
505+ # Set instanced geometry data using new simplified API
510506 pipeline .set_data (
511507 positions = self .instance_positions ,
512508 colours = self .instance_colours ,
513- geometry_vertices = self .geometry_vertices ,
514- geometry_normals = self .geometry_normals ,
515- geometry_uvs = self .geometry_uvs ,
509+ geometry_data = self .geometry_data , # Single interleaved parameter!
516510 )
517511
518512 # Update uniforms
@@ -528,12 +522,10 @@ def _render_single_colour_instanced_geometry_pipeline(self, render_pass):
528522 """Render single-colour instanced geometry."""
529523 pipeline = self .pipelines [self .current_pipeline_index ][0 ]
530524
531- # Set instanced geometry data
525+ # Set instanced geometry data using new simplified API
532526 pipeline .set_data (
533527 positions = self .instance_positions ,
534- geometry_vertices = self .geometry_vertices ,
535- geometry_normals = self .geometry_normals ,
536- geometry_uvs = self .geometry_uvs ,
528+ geometry_data = self .geometry_data , # Single interleaved parameter!
537529 )
538530
539531 # Update uniforms with orange color
@@ -568,6 +560,26 @@ def keyPressEvent(self, event) -> None:
568560 self .close () # Exit the application
569561 elif key == Qt .Key .Key_Space :
570562 self .animate = not self .animate
563+ elif key == Qt .Key .Key_Left :
564+ # Switch to previous pipeline
565+ self .current_pipeline_index = (self .current_pipeline_index - 1 ) % len (
566+ self .pipelines
567+ )
568+ print (f"Switched to { self .pipelines [self .current_pipeline_index ][2 ]} " )
569+ elif key == Qt .Key .Key_Right :
570+ # Switch to next pipeline
571+ self .current_pipeline_index = (self .current_pipeline_index + 1 ) % len (
572+ self .pipelines
573+ )
574+ print (f"Switched to { self .pipelines [self .current_pipeline_index ][2 ]} " )
575+ elif key == Qt .Key .Key_A :
576+ # Toggle automatic pipeline switching
577+ if self .pipeline_timer .isActive ():
578+ self .pipeline_timer .stop ()
579+ print ("Pipeline auto-switch disabled" )
580+ else :
581+ self .pipeline_timer .start (1000 )
582+ print ("Pipeline auto-switch enabled" )
571583 self .update ()
572584
573585 # Call the base class implementation for any unhandled events
0 commit comments