addLight now accepts a LightType enum; added support for setting falloff, spot light radius, sun radius & halo
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
import 'dart:async';
|
||||
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
||||
@@ -6,6 +8,15 @@ import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
|
||||
// "picking" means clicking/tapping on the viewport, and unprojecting the X/Y coordinate to determine whether any renderable entities were present at those coordinates.
|
||||
typedef FilamentPickResult = ({FilamentEntity entity, double x, double y});
|
||||
|
||||
enum LightType {
|
||||
SUN, //!< Directional light that also draws a sun's disk in the sky.
|
||||
DIRECTIONAL, //!< Directional light, emits light in a given direction.
|
||||
POINT, //!< Point light, emits light from a position, in all directions.
|
||||
FOCUSED_SPOT, //!< Physically correct spot light.
|
||||
SPOT,
|
||||
}
|
||||
|
||||
|
||||
// copied from filament/backened/DriverEnums.h
|
||||
enum PrimitiveType {
|
||||
// don't change the enums values (made to match GL)
|
||||
@@ -119,17 +130,13 @@ abstract class AbstractFilamentViewer {
|
||||
Future removeIbl();
|
||||
|
||||
///
|
||||
/// Adds a dynamic light to the scene.
|
||||
/// copied from filament LightManager.h
|
||||
/// enum class Type : uint8_t {
|
||||
/// SUN, //!< Directional light that also draws a sun's disk in the sky.
|
||||
/// DIRECTIONAL, //!< Directional light, emits light in a given direction.
|
||||
/// POINT, //!< Point light, emits light from a position, in all directions.
|
||||
/// FOCUSED_SPOT, //!< Physically correct spot light.
|
||||
/// SPOT, //!< Spot light with coupling of outer cone and illumination disabled.
|
||||
/// };
|
||||
/// Add a light to the scene.
|
||||
/// See LightManager.h for details
|
||||
/// Note that [sunAngularRadius] is in degrees,
|
||||
/// whereas [spotLightConeInner] and [spotLightConeOuter] are in radians
|
||||
///
|
||||
Future<FilamentEntity> addLight(
|
||||
int type,
|
||||
LightType type,
|
||||
double colour,
|
||||
double intensity,
|
||||
double posX,
|
||||
@@ -138,7 +145,16 @@ abstract class AbstractFilamentViewer {
|
||||
double dirX,
|
||||
double dirY,
|
||||
double dirZ,
|
||||
bool castShadows);
|
||||
{
|
||||
double falloffRadius=1.0,
|
||||
double spotLightConeInner=pi/8,
|
||||
double spotLightConeOuter=pi/4,
|
||||
double sunAngularRadius=0.545,
|
||||
double sunHaloSize=10.0,
|
||||
double sunHaloFallof=80.0,
|
||||
bool castShadows=true
|
||||
}
|
||||
);
|
||||
|
||||
Future removeLight(FilamentEntity light);
|
||||
|
||||
|
||||
@@ -163,6 +163,12 @@ external void remove_ibl(
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Bool)>(
|
||||
symbol: 'add_light', assetId: 'package:dart_filament/dart_filament.dart')
|
||||
external int add_light(
|
||||
@@ -176,6 +182,12 @@ external int add_light(
|
||||
double dirX,
|
||||
double dirY,
|
||||
double dirZ,
|
||||
double falloffRadius,
|
||||
double spotLightConeInner,
|
||||
double spotLightConeOuter,
|
||||
double sunAngularRadius,
|
||||
double sunHaloSize,
|
||||
double sunHaloFallof,
|
||||
bool shadows,
|
||||
);
|
||||
|
||||
@@ -1307,6 +1319,12 @@ external void remove_ibl_ffi(
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Float,
|
||||
ffi.Bool,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
|
||||
symbol: 'add_light_ffi',
|
||||
@@ -1322,6 +1340,12 @@ external void add_light_ffi(
|
||||
double dirX,
|
||||
double dirY,
|
||||
double dirZ,
|
||||
double falloffRadius,
|
||||
double spotLightConeInner,
|
||||
double spotLightConeOuter,
|
||||
double sunAngularRadius,
|
||||
double sunHaloSize,
|
||||
double sunHaloFallof,
|
||||
bool shadows,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
|
||||
);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
||||
import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
|
||||
import 'package:dart_filament/dart_filament/entities/gizmo.dart';
|
||||
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
import 'abstract_filament_viewer.dart';
|
||||
@@ -100,6 +102,9 @@ class FilamentViewer extends AbstractFilamentViewer {
|
||||
});
|
||||
}
|
||||
|
||||
Gizmo? _gizmo;
|
||||
Gizmo? get gizmo => _gizmo;
|
||||
|
||||
Future _initialize() async {
|
||||
final uberarchivePtr =
|
||||
uberArchivePath?.toNativeUtf8(allocator: allocator).cast<Char>() ??
|
||||
@@ -119,6 +124,11 @@ class FilamentViewer extends AbstractFilamentViewer {
|
||||
_scene = SceneImpl(this);
|
||||
|
||||
await setCameraManipulatorOptions(zoomSpeed: 10.0);
|
||||
|
||||
final out = calloc<Int32>(3);
|
||||
get_gizmo(_sceneManager!, out);
|
||||
_gizmo = Gizmo(out[0], out[1], out[2], this);
|
||||
calloc.free(out);
|
||||
|
||||
this._initialized.complete(true);
|
||||
}
|
||||
@@ -217,7 +227,7 @@ class FilamentViewer extends AbstractFilamentViewer {
|
||||
|
||||
@override
|
||||
Future<FilamentEntity> addLight(
|
||||
int type,
|
||||
LightType type,
|
||||
double colour,
|
||||
double intensity,
|
||||
double posX,
|
||||
@@ -226,10 +236,16 @@ class FilamentViewer extends AbstractFilamentViewer {
|
||||
double dirX,
|
||||
double dirY,
|
||||
double dirZ,
|
||||
bool castShadows) async {
|
||||
{double falloffRadius = 1.0,
|
||||
double spotLightConeInner = pi / 8,
|
||||
double spotLightConeOuter = pi / 4,
|
||||
double sunAngularRadius = 0.545,
|
||||
double sunHaloSize = 10.0,
|
||||
double sunHaloFallof = 80.0,
|
||||
bool castShadows = true}) async {
|
||||
var entity = await withIntCallback((callback) => add_light_ffi(
|
||||
_viewer!,
|
||||
type,
|
||||
type.index,
|
||||
colour,
|
||||
intensity,
|
||||
posX,
|
||||
@@ -238,8 +254,17 @@ class FilamentViewer extends AbstractFilamentViewer {
|
||||
dirX,
|
||||
dirY,
|
||||
dirZ,
|
||||
falloffRadius,
|
||||
spotLightConeInner,
|
||||
spotLightConeOuter,
|
||||
sunAngularRadius = 0.545,
|
||||
sunHaloSize = 10.0,
|
||||
sunHaloFallof = 80.0,
|
||||
castShadows,
|
||||
callback));
|
||||
if (entity == _FILAMENT_ASSET_ERROR) {
|
||||
throw Exception("Failed to add light to scene");
|
||||
}
|
||||
|
||||
_scene.registerLight(entity);
|
||||
return entity;
|
||||
@@ -1144,6 +1169,5 @@ class FilamentViewer extends AbstractFilamentViewer {
|
||||
set_priority(_sceneManager!, entityId, priority);
|
||||
}
|
||||
|
||||
@override
|
||||
AbstractGizmo? get gizmo => null;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user