|
10 | 10 | * sv.createImage({ url: "photo.jpg", position: [1, 1, 0] }); |
11 | 11 | * sv.createVideo({ url: "clip.mp4", position: [-1, 1, 0] }); |
12 | 12 | * |
| 13 | + * Quality, Bloom, and Lighting: |
| 14 | + * sv.setQuality("high"); |
| 15 | + * sv.setBloom(true); |
| 16 | + * sv.addLight({ type: "point", position: [2, 3, 0], color: [1, 0.9, 0.8] }); |
| 17 | + * |
13 | 18 | * Powered by Filament.js v1.70.1 (Google's PBR renderer, WASM). |
14 | 19 | * https://sceneview.github.io |
15 | 20 | * |
|
485 | 490 | return this; |
486 | 491 | } |
487 | 492 |
|
| 493 | + // --------------------------------------------------------------- |
| 494 | + // Quality, Bloom, and Lighting controls |
| 495 | + // --------------------------------------------------------------- |
| 496 | + |
| 497 | + /** |
| 498 | + * Set rendering quality level. |
| 499 | + * |
| 500 | + * @param {string} level - 'low', 'medium', or 'high' (default: 'medium') |
| 501 | + * @returns {SceneViewInstance} this (for chaining) |
| 502 | + */ |
| 503 | + setQuality(level) { |
| 504 | + try { |
| 505 | + if (level === 'low') { |
| 506 | + this._view.setAmbientOcclusionOptions({ enabled: false }); |
| 507 | + this._view.setAntiAliasing(Filament.View$AntiAliasing.NONE); |
| 508 | + } else if (level === 'high') { |
| 509 | + this._view.setAmbientOcclusionOptions({ |
| 510 | + enabled: true, radius: 0.4, bias: 0.0003, intensity: 1.2, quality: 2 |
| 511 | + }); |
| 512 | + this._view.setAntiAliasing(Filament.View$AntiAliasing.FXAA); |
| 513 | + } else { // medium (default) |
| 514 | + this._view.setAmbientOcclusionOptions({ |
| 515 | + enabled: true, radius: 0.3, bias: 0.0005, intensity: 1.0, quality: 1 |
| 516 | + }); |
| 517 | + this._view.setAntiAliasing(Filament.View$AntiAliasing.FXAA); |
| 518 | + } |
| 519 | + } catch (e) { console.warn('SceneView: setQuality not supported', e); } |
| 520 | + return this; |
| 521 | + } |
| 522 | + |
| 523 | + /** |
| 524 | + * Enable or configure bloom post-processing effect. |
| 525 | + * |
| 526 | + * @param {Object|boolean} options - true for defaults, false to disable, |
| 527 | + * or { strength, resolution, threshold, levels } |
| 528 | + * @returns {SceneViewInstance} this (for chaining) |
| 529 | + */ |
| 530 | + setBloom(options) { |
| 531 | + try { |
| 532 | + if (options === false) { |
| 533 | + this._view.setBloomOptions({ enabled: false }); |
| 534 | + } else { |
| 535 | + var opts = (options === true || options === undefined) ? {} : options; |
| 536 | + this._view.setBloomOptions({ |
| 537 | + enabled: true, |
| 538 | + strength: opts.strength !== undefined ? opts.strength : 0.1, |
| 539 | + resolution: opts.resolution !== undefined ? opts.resolution : 360, |
| 540 | + threshold: opts.threshold !== undefined ? opts.threshold : true, |
| 541 | + levels: opts.levels !== undefined ? opts.levels : 6 |
| 542 | + }); |
| 543 | + } |
| 544 | + } catch (e) { console.warn('SceneView: setBloom not supported', e); } |
| 545 | + return this; |
| 546 | + } |
| 547 | + |
| 548 | + /** |
| 549 | + * Add a custom light to the scene. |
| 550 | + * |
| 551 | + * @param {Object} options |
| 552 | + * @param {string} [options.type='directional'] - 'directional', 'point', or 'spot' |
| 553 | + * @param {number[]} [options.color=[1,1,1]] - RGB color [0-1] |
| 554 | + * @param {number} [options.intensity=100000] - Light intensity in lux |
| 555 | + * @param {number[]} [options.direction=[0,-1,0]] - Direction for directional/spot lights |
| 556 | + * @param {number[]} [options.position=[0,2,0]] - Position for point/spot lights |
| 557 | + * @param {number} [options.falloff=10] - Falloff radius for point/spot lights |
| 558 | + * @returns {number} Entity handle (use with removeNode to delete) |
| 559 | + */ |
| 560 | + addLight(options) { |
| 561 | + options = options || {}; |
| 562 | + var type = options.type || 'directional'; |
| 563 | + var color = options.color || [1, 1, 1]; |
| 564 | + var intensity = options.intensity !== undefined ? options.intensity : 100000; |
| 565 | + var direction = options.direction || [0, -1, 0]; |
| 566 | + var position = options.position || [0, 2, 0]; |
| 567 | + var falloff = options.falloff !== undefined ? options.falloff : 10; |
| 568 | + |
| 569 | + var entity = Filament.EntityManager.get().create(); |
| 570 | + var lightType; |
| 571 | + |
| 572 | + if (type === 'point') { |
| 573 | + lightType = Filament.LightManager$Type.POINT; |
| 574 | + } else if (type === 'spot') { |
| 575 | + lightType = Filament.LightManager$Type.SPOT; |
| 576 | + } else { |
| 577 | + lightType = Filament.LightManager$Type.DIRECTIONAL; |
| 578 | + } |
| 579 | + |
| 580 | + var builder = Filament.LightManager.Builder(lightType) |
| 581 | + .color(color) |
| 582 | + .intensity(intensity) |
| 583 | + .direction(direction); |
| 584 | + |
| 585 | + if (type === 'point' || type === 'spot') { |
| 586 | + builder.falloff(falloff); |
| 587 | + // Position point/spot lights via transform |
| 588 | + var tm = this._engine.getTransformManager(); |
| 589 | + var inst = tm.getInstance(entity); |
| 590 | + tm.setTransform(inst, Filament.mat4.translation(position)); |
| 591 | + } |
| 592 | + |
| 593 | + builder.build(this._engine, entity); |
| 594 | + this._scene.addEntity(entity); |
| 595 | + return entity; |
| 596 | + } |
| 597 | + |
488 | 598 | // --------------------------------------------------------------- |
489 | 599 | // createText — Render text as a textured quad in the 3D scene |
490 | 600 | // --------------------------------------------------------------- |
|
1508 | 1618 | } |
1509 | 1619 |
|
1510 | 1620 | global.SceneView = { |
1511 | | - version: '1.4.0', |
| 1621 | + version: '1.5.0', |
1512 | 1622 | create: create, |
1513 | 1623 | modelViewer: modelViewer |
1514 | 1624 | }; |
|
0 commit comments