rayzee 7.31.1 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +164 -0
  2. package/dist/rayzee.es.js +6366 -4361
  3. package/dist/rayzee.umd.js +122 -73
  4. package/package.json +1 -1
  5. package/src/EngineDefaults.js +168 -13
  6. package/src/EngineIssues.js +5 -0
  7. package/src/PathTracerApp.js +120 -19
  8. package/src/Processor/ArchiveReader.js +538 -0
  9. package/src/Processor/AssetLoader.js +265 -23
  10. package/src/Processor/BVHBuilder.js +48 -32
  11. package/src/Processor/BVHRefitter.js +244 -99
  12. package/src/Processor/ChunkedRecords.js +302 -0
  13. package/src/Processor/EmissiveTriangleBuilder.js +48 -21
  14. package/src/Processor/GeometryExtractor.js +577 -92
  15. package/src/Processor/HostMemory.js +222 -0
  16. package/src/Processor/InstanceTable.js +548 -97
  17. package/src/Processor/PBRT/EqualAreaOctahedral.js +32 -8
  18. package/src/Processor/PBRT/PBRTCurves.js +249 -0
  19. package/src/Processor/PBRT/PBRTMath.js +19 -0
  20. package/src/Processor/PBRT/PBRTParser.js +187 -41
  21. package/src/Processor/PBRT/PBRTSceneBuilder.js +586 -42
  22. package/src/Processor/PBRT/PBRTTokenizer.js +205 -65
  23. package/src/Processor/PBRT/index.js +257 -50
  24. package/src/Processor/PackedRayBuffer.js +29 -18
  25. package/src/Processor/ParallelBVHBuilder.js +9 -8
  26. package/src/Processor/QueueManager.js +5 -3
  27. package/src/Processor/SceneProcessor.js +1046 -365
  28. package/src/Processor/TLASBuilder.js +546 -201
  29. package/src/Processor/TextureCreator.js +11 -9
  30. package/src/Processor/VRAMTracker.js +12 -3
  31. package/src/Processor/Workers/BVHRefitWorker.js +16 -11
  32. package/src/Processor/Workers/BVHWorker.js +12 -12
  33. package/src/Processor/Workers/TLASWorker.js +37 -0
  34. package/src/Stages/NormalDepth.js +6 -2
  35. package/src/Stages/PathTracer.js +5 -5
  36. package/src/Stages/PathTracerStage.js +163 -41
  37. package/src/TSL/BVHTraversal.js +208 -90
  38. package/src/TSL/Common.js +135 -2
  39. package/src/TSL/Displacement.js +21 -11
  40. package/src/TSL/EmissiveSampling.js +49 -25
  41. package/src/TSL/ExtendKernel.js +3 -2
  42. package/src/TSL/LightBVHSampling.js +7 -4
  43. package/src/TSL/LightsDirect.js +30 -29
  44. package/src/TSL/ShadeKernel.js +8 -6
  45. package/src/TSL/Struct.js +3 -0
  46. package/src/TSL/TextureSampling.js +24 -9
  47. package/src/TSL/patches.js +128 -3
  48. package/src/index.js +3 -0
  49. package/src/managers/AnimationManager.js +86 -76
  50. package/src/managers/MaterialDataManager.js +29 -23
  51. package/src/managers/TransformManager.js +9 -192
@@ -5,7 +5,7 @@
5
5
  * disables OrbitControls during drag, and triggers BVH refit on release.
6
6
  */
7
7
 
8
- import { Matrix3, Scene, Vector3 } from 'three';
8
+ import { Scene, Vector3 } from 'three';
9
9
  import { TransformControls } from 'three/addons/controls/TransformControls.js';
10
10
  import { EngineEvents } from '../EngineEvents.js';
11
11
 
@@ -31,13 +31,6 @@ export class TransformManager {
31
31
  this._attached = null;
32
32
  this._isDragging = false;
33
33
  this._meshes = null;
34
- this._meshTriRanges = null;
35
- this._posBuffer = null;
36
- this._normalBuffer = null;
37
- this._skinnedCache = null;
38
- this._normalCache = null;
39
- this._tempVec = new Vector3();
40
- this._normalMatrix = new Matrix3();
41
34
  this._refitInFlight = false;
42
35
  this._baselineComputed = false;
43
36
 
@@ -57,38 +50,12 @@ export class TransformManager {
57
50
  }
58
51
 
59
52
  /**
60
- * Provide mesh data from SceneProcessor after scene load.
61
- * Required for position extraction during BVH refit.
53
+ * Provide the scene's mesh list from SceneProcessor after load. A drag is resolved against it
54
+ * to find which objects moved; nothing per-vertex is kept, because a move never reads vertices.
62
55
  */
63
56
  setMeshData( meshes ) {
64
57
 
65
58
  this._meshes = meshes;
66
- this._meshTriRanges = [];
67
- this._skinnedCache = [];
68
- this._normalCache = [];
69
- let offset = 0;
70
-
71
- for ( const mesh of meshes ) {
72
-
73
- const geometry = mesh.geometry;
74
- const positions = geometry.attributes.position;
75
- const indices = geometry.index ? geometry.index.array : null;
76
- const count = indices ? indices.length / 3 : positions.count / 3;
77
- const uniqueVerts = positions.count;
78
-
79
- this._meshTriRanges.push( { start: offset, count, uniqueVerts, indices } );
80
- this._skinnedCache.push( new Float32Array( uniqueVerts * 3 ) );
81
- this._normalCache.push( new Float32Array( uniqueVerts * 3 ) );
82
- offset += count;
83
-
84
- }
85
-
86
- this._posBuffer = new Float32Array( offset * 9 );
87
- this._normalBuffer = new Float32Array( offset * 9 );
88
-
89
- // Mesh indices/buffers were just reallocated (e.g. after a scene rebuild) —
90
- // force the next drag to recompute the transform baseline.
91
- this._baselineComputed = false;
92
59
 
93
60
  }
94
61
 
@@ -330,7 +297,7 @@ export class TransformManager {
330
297
  */
331
298
  _recomputeAndRefit() {
332
299
 
333
- if ( ! this._meshes || ! this._posBuffer || this._refitInFlight ) return;
300
+ if ( ! this._meshes || this._refitInFlight ) return;
334
301
  if ( ! this._attached ) return;
335
302
 
336
303
  // Update world matrices for the moved object subtree
@@ -341,29 +308,15 @@ export class TransformManager {
341
308
 
342
309
  if ( affectedIndices.length === 0 ) return;
343
310
 
344
- // On first transform or after scene reload, compute ALL positions as baseline
345
- if ( ! this._baselineComputed ) {
346
-
347
- this._computeAllPositions();
348
- this._baselineComputed = true;
349
-
350
- } else {
351
-
352
- // Recompute only affected meshes
353
- for ( const idx of affectedIndices ) {
354
-
355
- this._computeMeshPositions( idx );
356
-
357
- }
358
-
359
- }
360
-
361
311
  this._refitInFlight = true;
362
312
 
363
313
  try {
364
314
 
365
- // Use per-BLAS refit for affected meshes only (faster than full BVH refit)
366
- this._app.refitBLASes( affectedIndices, this._posBuffer, this._normalBuffer );
315
+ // A gizmo only changes an object's transform, so the triangles never move in their
316
+ // own space — only the matrix that places them does. Rewriting world-space vertices
317
+ // instead costs a pass over every vertex, and corrupts any other object sharing
318
+ // this geometry.
319
+ this._app.updateMeshTransforms( affectedIndices );
367
320
 
368
321
  } catch ( err ) {
369
322
 
@@ -413,137 +366,6 @@ export class TransformManager {
413
366
 
414
367
  }
415
368
 
416
- /**
417
- * Compute world-space positions for ALL meshes (baseline).
418
- * Mirrors AnimationManager._computePositions().
419
- */
420
- _computeAllPositions() {
421
-
422
- for ( let i = 0; i < this._meshes.length; i ++ ) {
423
-
424
- this._computeMeshPositions( i );
425
-
426
- }
427
-
428
- }
429
-
430
- /**
431
- * Compute world-space positions and normals for a single mesh.
432
- * Writes into _posBuffer and _normalBuffer at the mesh's triangle range.
433
- */
434
- _computeMeshPositions( meshIndex ) {
435
-
436
- const mesh = this._meshes[ meshIndex ];
437
- const { start, count, uniqueVerts, indices } = this._meshTriRanges[ meshIndex ];
438
- const skinned = this._skinnedCache[ meshIndex ];
439
- const nrmCache = this._normalCache[ meshIndex ];
440
- const tempVec = this._tempVec;
441
- const output = this._posBuffer;
442
- const nrmOut = this._normalBuffer;
443
-
444
- mesh.updateMatrixWorld( true );
445
- const worldMatrix = mesh.matrixWorld;
446
-
447
- // Normal matrix = inverse transpose of upper 3x3 of worldMatrix
448
- this._normalMatrix.getNormalMatrix( worldMatrix );
449
- const ne = this._normalMatrix.elements;
450
-
451
- const normalAttr = mesh.geometry.attributes.normal;
452
-
453
- // Phase 1: Compute world-space positions and normals for all unique vertices
454
- for ( let v = 0; v < uniqueVerts; v ++ ) {
455
-
456
- mesh.getVertexPosition( v, tempVec );
457
- tempVec.applyMatrix4( worldMatrix );
458
-
459
- skinned[ v * 3 ] = tempVec.x;
460
- skinned[ v * 3 + 1 ] = tempVec.y;
461
- skinned[ v * 3 + 2 ] = tempVec.z;
462
-
463
- // Transform normal by normal matrix (handles non-uniform scale)
464
- if ( normalAttr ) {
465
-
466
- const nx = normalAttr.getX( v );
467
- const ny = normalAttr.getY( v );
468
- const nz = normalAttr.getZ( v );
469
-
470
- nrmCache[ v * 3 ] = ne[ 0 ] * nx + ne[ 3 ] * ny + ne[ 6 ] * nz;
471
- nrmCache[ v * 3 + 1 ] = ne[ 1 ] * nx + ne[ 4 ] * ny + ne[ 7 ] * nz;
472
- nrmCache[ v * 3 + 2 ] = ne[ 2 ] * nx + ne[ 5 ] * ny + ne[ 8 ] * nz;
473
-
474
- }
475
-
476
- }
477
-
478
- // Phase 2: Assemble triangles (positions + normals)
479
- if ( indices ) {
480
-
481
- for ( let t = 0; t < count; t ++ ) {
482
-
483
- const t3 = t * 3;
484
- const i0 = indices[ t3 ] * 3;
485
- const i1 = indices[ t3 + 1 ] * 3;
486
- const i2 = indices[ t3 + 2 ] * 3;
487
- const o = ( start + t ) * 9;
488
-
489
- output[ o ] = skinned[ i0 ];
490
- output[ o + 1 ] = skinned[ i0 + 1 ];
491
- output[ o + 2 ] = skinned[ i0 + 2 ];
492
- output[ o + 3 ] = skinned[ i1 ];
493
- output[ o + 4 ] = skinned[ i1 + 1 ];
494
- output[ o + 5 ] = skinned[ i1 + 2 ];
495
- output[ o + 6 ] = skinned[ i2 ];
496
- output[ o + 7 ] = skinned[ i2 + 1 ];
497
- output[ o + 8 ] = skinned[ i2 + 2 ];
498
-
499
- nrmOut[ o ] = nrmCache[ i0 ];
500
- nrmOut[ o + 1 ] = nrmCache[ i0 + 1 ];
501
- nrmOut[ o + 2 ] = nrmCache[ i0 + 2 ];
502
- nrmOut[ o + 3 ] = nrmCache[ i1 ];
503
- nrmOut[ o + 4 ] = nrmCache[ i1 + 1 ];
504
- nrmOut[ o + 5 ] = nrmCache[ i1 + 2 ];
505
- nrmOut[ o + 6 ] = nrmCache[ i2 ];
506
- nrmOut[ o + 7 ] = nrmCache[ i2 + 1 ];
507
- nrmOut[ o + 8 ] = nrmCache[ i2 + 2 ];
508
-
509
- }
510
-
511
- } else {
512
-
513
- // Non-indexed: vertices are sequential triplets
514
- for ( let t = 0; t < count; t ++ ) {
515
-
516
- const v0 = ( t * 3 ) * 3;
517
- const v1 = ( t * 3 + 1 ) * 3;
518
- const v2 = ( t * 3 + 2 ) * 3;
519
- const o = ( start + t ) * 9;
520
-
521
- output[ o ] = skinned[ v0 ];
522
- output[ o + 1 ] = skinned[ v0 + 1 ];
523
- output[ o + 2 ] = skinned[ v0 + 2 ];
524
- output[ o + 3 ] = skinned[ v1 ];
525
- output[ o + 4 ] = skinned[ v1 + 1 ];
526
- output[ o + 5 ] = skinned[ v1 + 2 ];
527
- output[ o + 6 ] = skinned[ v2 ];
528
- output[ o + 7 ] = skinned[ v2 + 1 ];
529
- output[ o + 8 ] = skinned[ v2 + 2 ];
530
-
531
- nrmOut[ o ] = nrmCache[ v0 ];
532
- nrmOut[ o + 1 ] = nrmCache[ v0 + 1 ];
533
- nrmOut[ o + 2 ] = nrmCache[ v0 + 2 ];
534
- nrmOut[ o + 3 ] = nrmCache[ v1 ];
535
- nrmOut[ o + 4 ] = nrmCache[ v1 + 1 ];
536
- nrmOut[ o + 5 ] = nrmCache[ v1 + 2 ];
537
- nrmOut[ o + 6 ] = nrmCache[ v2 ];
538
- nrmOut[ o + 7 ] = nrmCache[ v2 + 1 ];
539
- nrmOut[ o + 8 ] = nrmCache[ v2 + 2 ];
540
-
541
- }
542
-
543
- }
544
-
545
- }
546
-
547
369
  dispose() {
548
370
 
549
371
  this._controls.removeEventListener( 'dragging-changed', this._onDraggingChanged );
@@ -553,11 +375,6 @@ export class TransformManager {
553
375
  this._controls.dispose();
554
376
 
555
377
  this._meshes = null;
556
- this._meshTriRanges = null;
557
- this._posBuffer = null;
558
- this._normalBuffer = null;
559
- this._skinnedCache = null;
560
- this._normalCache = null;
561
378
  this._baselineComputed = false;
562
379
  this._tempForward = null;
563
380
  this._lightTargetDistance = null;