add animation fading and revert to platform channel handler
This commit is contained in:
Binary file not shown.
@@ -21,6 +21,23 @@ class MyApp extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(
|
||||||
|
// showPerformanceOverlay: true,
|
||||||
|
color: Colors.white,
|
||||||
|
home: Scaffold(backgroundColor: Colors.white, body: ExampleWidget()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExampleWidget extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() {
|
||||||
|
return _ExampleWidgetState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExampleWidgetState extends State<ExampleWidget> {
|
||||||
late FilamentController _filamentController;
|
late FilamentController _filamentController;
|
||||||
|
|
||||||
FilamentEntity? _cube;
|
FilamentEntity? _cube;
|
||||||
@@ -28,8 +45,7 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
|||||||
FilamentEntity? _light;
|
FilamentEntity? _light;
|
||||||
|
|
||||||
final weights = List.filled(255, 0.0);
|
final weights = List.filled(255, 0.0);
|
||||||
List<String> _targetNames = [];
|
|
||||||
List<String> _animationNames = [];
|
|
||||||
bool _loop = false;
|
bool _loop = false;
|
||||||
bool _vertical = false;
|
bool _vertical = false;
|
||||||
bool _rendering = false;
|
bool _rendering = false;
|
||||||
@@ -38,7 +54,7 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_filamentController = FilamentController(this);
|
_filamentController = FilamentController();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onClick(int index) async {
|
void onClick(int index) async {
|
||||||
@@ -61,6 +77,9 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
|||||||
_filamentController.setFrameRate(_framerate);
|
_filamentController.setFrameRate(_framerate);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case -6:
|
||||||
|
_filamentController.setBackgroundColor(Color(0xFF73C9FA));
|
||||||
|
break;
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
_filamentController.setBackgroundImage('assets/background.ktx');
|
_filamentController.setBackgroundImage('assets/background.ktx');
|
||||||
@@ -76,18 +95,17 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
|||||||
_filamentController.removeSkybox();
|
_filamentController.removeSkybox();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
_cube = _filamentController.loadGlb('assets/cube.glb');
|
_cube = await _filamentController.loadGlb('assets/cube.glb');
|
||||||
_animationNames = _filamentController.getAnimationNames(_cube!);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
if (_cube != null) {
|
if (_cube != null) {
|
||||||
_filamentController.removeAsset(_cube!);
|
_filamentController.removeAsset(_cube!);
|
||||||
}
|
}
|
||||||
_cube = _filamentController.loadGltf('assets/cube.gltf', 'assets');
|
_cube =
|
||||||
|
await _filamentController.loadGltf('assets/cube.gltf', 'assets');
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
_flightHelmet ??= _filamentController.loadGltf(
|
_flightHelmet ??= await _filamentController.loadGltf(
|
||||||
'assets/FlightHelmet/FlightHelmet.gltf', 'assets/FlightHelmet');
|
'assets/FlightHelmet/FlightHelmet.gltf', 'assets/FlightHelmet');
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
@@ -102,16 +120,6 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
|||||||
_filamentController.setMorphTargetWeights(
|
_filamentController.setMorphTargetWeights(
|
||||||
_cube!, "Cube.001", List.filled(8, 0));
|
_cube!, "Cube.001", List.filled(8, 0));
|
||||||
break;
|
break;
|
||||||
case 9:
|
|
||||||
for (int i = 0; i < _animationNames.length; i++) {
|
|
||||||
print("Playing animation ${_animationNames[i]}");
|
|
||||||
_filamentController.playAnimation(_cube!, i, loop: _loop);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
_filamentController.stopAnimation(_cube!, 0);
|
|
||||||
break;
|
|
||||||
case 11:
|
case 11:
|
||||||
setState(() {
|
setState(() {
|
||||||
_loop = !_loop;
|
_loop = !_loop;
|
||||||
@@ -142,12 +150,32 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
|||||||
.set();
|
.set();
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
_targetNames = _filamentController.getMorphTargetNames(_cube!, "Cube");
|
var names =
|
||||||
setState(() {});
|
await _filamentController.getMorphTargetNames(_cube!, "Cube");
|
||||||
|
await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) {
|
||||||
|
return Container(
|
||||||
|
height: 100,
|
||||||
|
width: 100,
|
||||||
|
color: Colors.white,
|
||||||
|
child: Text(names.join(",")));
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17:
|
||||||
_animationNames = _filamentController.getAnimationNames(_cube!);
|
var animationNames =
|
||||||
setState(() {});
|
await _filamentController.getAnimationNames(_cube!);
|
||||||
|
|
||||||
|
await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) {
|
||||||
|
return Container(
|
||||||
|
height: 100,
|
||||||
|
width: 100,
|
||||||
|
color: Colors.white,
|
||||||
|
child: Text(animationNames.join(",")));
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
@@ -192,14 +220,13 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
|||||||
_filamentController.setBackgroundImagePosition(25, 25);
|
_filamentController.setBackgroundImagePosition(25, 25);
|
||||||
break;
|
break;
|
||||||
case 29:
|
case 29:
|
||||||
_light = _filamentController.addLight(
|
_light = await _filamentController.addLight(
|
||||||
1, 6500, 15000000, 0, 1, 0, 0, -1, 0, true);
|
1, 6500, 15000000, 0, 1, 0, 0, -1, 0, true);
|
||||||
_light = _filamentController.addLight(
|
|
||||||
2, 6500, 15000000, 0, 0, 1, 0, 0, -1, true);
|
|
||||||
break;
|
break;
|
||||||
case 30:
|
case 30:
|
||||||
if (_light != null) {
|
if (_light != null) {
|
||||||
_filamentController.removeLight(_light!);
|
_filamentController.removeLight(_light!);
|
||||||
|
_light = null;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 31:
|
case 31:
|
||||||
@@ -236,6 +263,22 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_coneHidden = !_coneHidden;
|
_coneHidden = !_coneHidden;
|
||||||
});
|
});
|
||||||
|
break;
|
||||||
|
case 34:
|
||||||
|
_filamentController.playAnimation(_cube!, 0,
|
||||||
|
loop: false, crossfade: 0.5);
|
||||||
|
break;
|
||||||
|
case 35:
|
||||||
|
_filamentController.playAnimation(_cube!, 1,
|
||||||
|
loop: false, crossfade: 0.5);
|
||||||
|
break;
|
||||||
|
case 36:
|
||||||
|
_filamentController.playAnimation(_cube!, 2,
|
||||||
|
loop: false, crossfade: 0.5);
|
||||||
|
break;
|
||||||
|
case 37:
|
||||||
|
_filamentController.stopAnimation(_cube!, 0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,92 +290,89 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
|||||||
onClick(value);
|
onClick(value);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: EdgeInsets.symmetric(vertical: 10), child: child));
|
color: Colors.transparent,
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||||
|
child: child));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return Row(children: [
|
||||||
// showPerformanceOverlay: true,
|
SingleChildScrollView(
|
||||||
color: Colors.white,
|
child: Column(
|
||||||
home: Scaffold(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
backgroundColor: Colors.white,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
body: Row(children: [
|
children: [
|
||||||
SingleChildScrollView(
|
_item(value: -1, child: Text("initialize")),
|
||||||
child: Column(
|
_item(value: -2, child: Text("render")),
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
_item(value: -4, child: Text("Rendering: $_rendering ")),
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
_item(value: -5, child: Text("$_framerate fps")),
|
||||||
children: [
|
_item(value: -6, child: Text("set background color")),
|
||||||
Text(
|
_item(value: 0, child: Text("load background image")),
|
||||||
"Target names : ${_targetNames.join(",")}, Animation names : ${_animationNames.join(",")}"),
|
_item(
|
||||||
_item(value: -1, child: Text("initialize")),
|
value: 1,
|
||||||
_item(value: -2, child: Text("render")),
|
child: Text('load skybox'),
|
||||||
_item(value: -4, child: Text("Rendering: $_rendering ")),
|
),
|
||||||
_item(value: -5, child: Text("$_framerate fps")),
|
_item(
|
||||||
_item(value: 0, child: Text("load background image")),
|
value: -3,
|
||||||
_item(
|
child: Text('load IBL'),
|
||||||
value: 1,
|
),
|
||||||
child: Text('load skybox'),
|
_item(
|
||||||
),
|
value: 2,
|
||||||
_item(
|
child: Text('remove skybox'),
|
||||||
value: -3,
|
),
|
||||||
child: Text('load IBL'),
|
_item(value: 3, child: Text('load cube GLB')),
|
||||||
),
|
_item(
|
||||||
_item(
|
value: 33,
|
||||||
value: 2,
|
child: Text(_coneHidden ? 'show cone' : 'hide cone')),
|
||||||
child: Text('remove skybox'),
|
_item(value: 4, child: Text('load cube GLTF')),
|
||||||
),
|
_item(value: 21, child: Text('swap cube texture')),
|
||||||
_item(value: 3, child: Text('load cube GLB')),
|
_item(value: 22, child: Text('transform to unit cube')),
|
||||||
_item(
|
_item(value: 23, child: Text('set position to 1, 1, -1')),
|
||||||
value: 33,
|
_item(value: 32, child: Text('construct bone animation')),
|
||||||
child: Text(_coneHidden ? 'show cone' : 'hide cone')),
|
_item(value: 24, child: Text('rotate by pi around Y axis')),
|
||||||
_item(value: 4, child: Text('load cube GLTF')),
|
_item(value: 5, child: Text('load flight helmet')),
|
||||||
_item(value: 21, child: Text('swap cube texture')),
|
_item(value: 6, child: Text('remove cube')),
|
||||||
_item(value: 22, child: Text('transform to unit cube')),
|
_item(value: 20, child: Text('clear all assets')),
|
||||||
_item(value: 23, child: Text('set position to 1, 1, -1')),
|
_item(value: 7, child: Text('set all weights to 1')),
|
||||||
_item(value: 32, child: Text('construct bone animation')),
|
_item(value: 8, child: Text('set all weights to 0')),
|
||||||
_item(value: 24, child: Text('rotate by pi around Y axis')),
|
_item(value: 9, child: Text('play all animations')),
|
||||||
_item(value: 5, child: Text('load flight helmet')),
|
_item(value: 34, child: Text('play animation 0')),
|
||||||
_item(value: 6, child: Text('remove cube')),
|
_item(value: 35, child: Text('play animation 1')),
|
||||||
_item(value: 20, child: Text('clear all assets')),
|
_item(value: 36, child: Text('play animation 2')),
|
||||||
_item(value: 7, child: Text('set all weights to 1')),
|
_item(value: 37, child: Text('stop animation 0')),
|
||||||
_item(value: 8, child: Text('set all weights to 0')),
|
_item(
|
||||||
_item(value: 9, child: Text('play all animations')),
|
value: 11,
|
||||||
_item(value: 10, child: Text('stop animations')),
|
child: Text(_loop ? "don't loop animation" : "loop animation")),
|
||||||
_item(
|
_item(value: 14, child: Text('set camera')),
|
||||||
value: 11,
|
_item(value: 15, child: Text('animate weights')),
|
||||||
child: Text(
|
_item(value: 16, child: Text('get target names')),
|
||||||
_loop ? "don't loop animation" : "loop animation")),
|
_item(value: 17, child: Text('get animation names')),
|
||||||
_item(value: 14, child: Text('set camera')),
|
_item(value: 18, child: Text('pan left')),
|
||||||
_item(value: 15, child: Text('animate weights')),
|
_item(value: 19, child: Text('pan right')),
|
||||||
_item(value: 16, child: Text('get target names')),
|
_item(
|
||||||
_item(value: 17, child: Text('get animation names')),
|
value: 25,
|
||||||
_item(value: 18, child: Text('pan left')),
|
child: Text(_vertical ? 'set horizontal' : 'set vertical')),
|
||||||
_item(value: 19, child: Text('pan right')),
|
_item(value: 26, child: Text('set camera pos to 0,0,3')),
|
||||||
_item(
|
_item(value: 27, child: Text('toggle framerate')),
|
||||||
value: 25,
|
_item(value: 28, child: Text('set bg image pos')),
|
||||||
child: Text(
|
_item(value: 29, child: Text('add light')),
|
||||||
_vertical ? 'set horizontal' : 'set vertical')),
|
_item(value: 30, child: Text('remove light')),
|
||||||
_item(value: 26, child: Text('set camera pos to 0,0,3')),
|
_item(value: 31, child: Text('clear all lights')),
|
||||||
_item(value: 27, child: Text('toggle framerate')),
|
_item(value: 32, child: Text('set camera model matrix')),
|
||||||
_item(value: 28, child: Text('set bg image pos')),
|
])),
|
||||||
_item(value: 29, child: Text('add light')),
|
Container(
|
||||||
_item(value: 30, child: Text('remove light')),
|
width: _vertical ? 200 : 400,
|
||||||
_item(value: 31, child: Text('clear all lights')),
|
height: _vertical ? 400 : 200,
|
||||||
_item(value: 32, child: Text('set camera model matrix')),
|
alignment: Alignment.center,
|
||||||
])),
|
child: SizedBox(
|
||||||
Container(
|
child: FilamentGestureDetector(
|
||||||
width: _vertical ? 200 : 400,
|
showControlOverlay: true,
|
||||||
height: _vertical ? 400 : 200,
|
controller: _filamentController,
|
||||||
alignment: Alignment.center,
|
child: FilamentWidget(
|
||||||
child: SizedBox(
|
controller: _filamentController,
|
||||||
child: FilamentGestureDetector(
|
)),
|
||||||
showControlOverlay: true,
|
)),
|
||||||
controller: _filamentController,
|
]);
|
||||||
child: FilamentWidget(
|
|
||||||
controller: _filamentController,
|
|
||||||
)),
|
|
||||||
)),
|
|
||||||
])));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import UIKit
|
|||||||
import GLKit
|
import GLKit
|
||||||
|
|
||||||
public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture {
|
public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture {
|
||||||
|
|
||||||
var registrar : FlutterPluginRegistrar
|
var registrar : FlutterPluginRegistrar
|
||||||
var flutterTextureId: Int64?
|
var flutterTextureId: Int64?
|
||||||
var registry: FlutterTextureRegistry
|
var registry: FlutterTextureRegistry
|
||||||
|
|
||||||
var pixelBuffer: CVPixelBuffer?;
|
var pixelBuffer: CVPixelBuffer?;
|
||||||
|
|
||||||
var createdAt = Date()
|
var createdAt = Date()
|
||||||
@@ -18,121 +18,126 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
kCVPixelBufferOpenGLESCompatibilityKey: kCFBooleanTrue,
|
kCVPixelBufferOpenGLESCompatibilityKey: kCFBooleanTrue,
|
||||||
kCVPixelBufferIOSurfacePropertiesKey: [:]
|
kCVPixelBufferIOSurfacePropertiesKey: [:]
|
||||||
] as CFDictionary
|
] as CFDictionary
|
||||||
|
|
||||||
var resources:NSMutableDictionary = [:]
|
var resources:NSMutableDictionary = [:]
|
||||||
|
|
||||||
|
var viewer:UnsafeRawPointer? = nil
|
||||||
var displayLink:CADisplayLink? = nil
|
var displayLink:CADisplayLink? = nil
|
||||||
|
var rendering:Bool = false
|
||||||
|
|
||||||
static var messenger : FlutterBinaryMessenger? = nil;
|
static var messenger : FlutterBinaryMessenger? = nil;
|
||||||
|
|
||||||
var loadResource : @convention(c) (UnsafePointer<Int8>?, UnsafeMutableRawPointer?) -> ResourceBuffer = { uri, resourcesPtr in
|
var loadResource : @convention(c) (UnsafePointer<Int8>?, UnsafeMutableRawPointer?) -> ResourceBuffer = { uri, resourcesPtr in
|
||||||
|
|
||||||
let instance:SwiftPolyvoxFilamentPlugin = Unmanaged<SwiftPolyvoxFilamentPlugin>.fromOpaque(resourcesPtr!).takeUnretainedValue()
|
let instance:SwiftPolyvoxFilamentPlugin = Unmanaged<SwiftPolyvoxFilamentPlugin>.fromOpaque(resourcesPtr!).takeUnretainedValue()
|
||||||
|
|
||||||
let uriString = String(cString:uri!)
|
let uriString = String(cString:uri!)
|
||||||
|
|
||||||
var path:String? = nil
|
|
||||||
|
|
||||||
// check for hot-reloaded asset
|
|
||||||
var found : URL? = nil
|
|
||||||
|
|
||||||
if(uriString.hasPrefix("asset://")) {
|
|
||||||
let assetPath = String(uriString.dropFirst(8))
|
|
||||||
print("Searching for hot reloaded asset under path : \(assetPath)")
|
|
||||||
let appFolder = Bundle.main.resourceURL
|
|
||||||
let dirPaths = NSSearchPathForDirectoriesInDomains(.applicationDirectory,
|
|
||||||
.userDomainMask, true)
|
|
||||||
let supportDirPaths = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory,
|
|
||||||
.userDomainMask, true)
|
|
||||||
let devFsPath = URL(fileURLWithPath: supportDirPaths.first!, isDirectory:true).deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("tmp")
|
|
||||||
|
|
||||||
|
var path:String? = nil
|
||||||
let orderedURLs = try? FileManager.default.enumerator(at: devFsPath, includingPropertiesForKeys: [ .pathKey, .creationDateKey], options: .skipsHiddenFiles)
|
|
||||||
|
|
||||||
|
|
||||||
for case let fileURL as URL in orderedURLs! {
|
// check for hot-reloaded asset
|
||||||
if !(fileURL.path.hasSuffix(assetPath)) {
|
var found : URL? = nil
|
||||||
continue
|
|
||||||
}
|
if(uriString.hasPrefix("asset://")) {
|
||||||
print("Found hot reloaded asset : \(fileURL)")
|
let assetPath = String(uriString.dropFirst(8))
|
||||||
if found == nil {
|
print("Searching for hot reloaded asset under path : \(assetPath)")
|
||||||
found = fileURL
|
let appFolder = Bundle.main.resourceURL
|
||||||
} else {
|
let dirPaths = NSSearchPathForDirectoriesInDomains(.applicationDirectory,
|
||||||
do {
|
.userDomainMask, true)
|
||||||
let c1 = try found!.resourceValues(forKeys: [.creationDateKey]).creationDate
|
let supportDirPaths = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory,
|
||||||
let c2 = try fileURL.resourceValues(forKeys: [.creationDateKey]).creationDate
|
.userDomainMask, true)
|
||||||
|
let devFsPath = URL(fileURLWithPath: supportDirPaths.first!, isDirectory:true).deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("tmp")
|
||||||
|
|
||||||
if c1! < c2! {
|
|
||||||
found = fileURL
|
let orderedURLs = try? FileManager.default.enumerator(at: devFsPath, includingPropertiesForKeys: [ .pathKey, .creationDateKey], options: .skipsHiddenFiles)
|
||||||
print("\(fileURL) is newer, replacing")
|
|
||||||
} else {
|
|
||||||
print("Ignoring older asset")
|
for case let fileURL as URL in orderedURLs! {
|
||||||
}
|
if !(fileURL.path.hasSuffix(assetPath)) {
|
||||||
} catch {
|
continue
|
||||||
|
}
|
||||||
}
|
print("Found hot reloaded asset : \(fileURL)")
|
||||||
}
|
if found == nil {
|
||||||
}
|
found = fileURL
|
||||||
}
|
} else {
|
||||||
|
do {
|
||||||
do {
|
let c1 = try found!.resourceValues(forKeys: [.creationDateKey]).creationDate
|
||||||
if let cd = try found?.resourceValues(forKeys:[.creationDateKey]).creationDate {
|
let c2 = try fileURL.resourceValues(forKeys: [.creationDateKey]).creationDate
|
||||||
if cd > instance.createdAt {
|
|
||||||
print("Using hot reloaded asset : \(found)")
|
if c1! < c2! {
|
||||||
path = found!.path
|
found = fileURL
|
||||||
}
|
print("\(fileURL) is newer, replacing")
|
||||||
}
|
} else {
|
||||||
} catch {
|
print("Ignoring older asset")
|
||||||
|
}
|
||||||
}
|
} catch {
|
||||||
if path == nil {
|
|
||||||
if(uriString.hasPrefix("file://")) {
|
}
|
||||||
path = String(uriString.dropFirst(7))
|
}
|
||||||
} else if(uriString.hasPrefix("asset://")) {
|
|
||||||
let key = instance.registrar.lookupKey(forAsset:String(uriString.dropFirst(8)))
|
|
||||||
path = Bundle.main.path(forResource: key, ofType:nil)
|
|
||||||
print("Found path \(path) for uri \(uriString)")
|
|
||||||
guard path != nil else {
|
|
||||||
print("File not present in bundle : \(uri)")
|
|
||||||
return ResourceBuffer()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let key = instance.registrar.lookupKey(forAsset:uriString)
|
|
||||||
path = Bundle.main.path(forResource: key, ofType:nil)
|
|
||||||
print("Found path \(path) for uri \(uriString)")
|
|
||||||
guard path != nil else {
|
|
||||||
print("File not present in bundle : \(uri)")
|
|
||||||
return ResourceBuffer()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
do {
|
do {
|
||||||
print("Opening data from path \(path)")
|
if let cd = try found?.resourceValues(forKeys:[.creationDateKey]).creationDate {
|
||||||
let data = try Data(contentsOf: URL(fileURLWithPath:path!))
|
if cd > instance.createdAt {
|
||||||
let resId = instance.resources.count
|
print("Using hot reloaded asset : \(found)")
|
||||||
let nsData = data as NSData
|
path = found!.path
|
||||||
instance.resources[resId] = nsData
|
}
|
||||||
let rawPtr = nsData.bytes
|
}
|
||||||
return ResourceBuffer(data:rawPtr, size:UInt32(nsData.count), id:UInt32(resId))
|
} catch {
|
||||||
} catch {
|
|
||||||
print("Error opening file: \(error)")
|
}
|
||||||
}
|
if path == nil {
|
||||||
return ResourceBuffer()
|
if(uriString.hasPrefix("file://")) {
|
||||||
|
path = String(uriString.dropFirst(7))
|
||||||
|
} else if(uriString.hasPrefix("asset://")) {
|
||||||
|
let key = instance.registrar.lookupKey(forAsset:String(uriString.dropFirst(8)))
|
||||||
|
path = Bundle.main.path(forResource: key, ofType:nil)
|
||||||
|
print("Found path \(path) for uri \(uriString)")
|
||||||
|
guard path != nil else {
|
||||||
|
print("File not present in bundle : \(uri)")
|
||||||
|
return ResourceBuffer()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let key = instance.registrar.lookupKey(forAsset:uriString)
|
||||||
|
path = Bundle.main.path(forResource: key, ofType:nil)
|
||||||
|
print("Found path \(path) for uri \(uriString)")
|
||||||
|
guard path != nil else {
|
||||||
|
print("File not present in bundle : \(uri)")
|
||||||
|
return ResourceBuffer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
print("Opening data from path \(path)")
|
||||||
|
let data = try Data(contentsOf: URL(fileURLWithPath:path!))
|
||||||
|
let resId = instance.resources.count
|
||||||
|
let nsData = data as NSData
|
||||||
|
instance.resources[resId] = nsData
|
||||||
|
let rawPtr = nsData.bytes
|
||||||
|
return ResourceBuffer(data:rawPtr, size:UInt32(nsData.count), id:UInt32(resId))
|
||||||
|
} catch {
|
||||||
|
print("Error opening file: \(error)")
|
||||||
|
}
|
||||||
|
return ResourceBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
var freeResource : @convention(c) (ResourceBuffer,UnsafeMutableRawPointer?) -> () = { rbuf, resourcesPtr in
|
var freeResource : @convention(c) (ResourceBuffer,UnsafeMutableRawPointer?) -> () = { rbuf, resourcesPtr in
|
||||||
let instance:SwiftPolyvoxFilamentPlugin = Unmanaged<SwiftPolyvoxFilamentPlugin>.fromOpaque(resourcesPtr!).takeUnretainedValue()
|
let instance:SwiftPolyvoxFilamentPlugin = Unmanaged<SwiftPolyvoxFilamentPlugin>.fromOpaque(resourcesPtr!).takeUnretainedValue()
|
||||||
instance.resources.removeObject(forKey:rbuf.id)
|
instance.resources.removeObject(forKey:rbuf.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func doRender() {
|
@objc func doRender() {
|
||||||
|
if(viewer != nil && rendering) {
|
||||||
|
render(viewer, 0)
|
||||||
|
self.registry.textureFrameAvailable(flutterTextureId!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDisplayLink() {
|
func createDisplayLink() {
|
||||||
displayLink = CADisplayLink(target: self,
|
displayLink = CADisplayLink(target: self,
|
||||||
selector: #selector(doRender))
|
selector: #selector(doRender))
|
||||||
displayLink!.add(to: .current, forMode: RunLoop.Mode.default)
|
displayLink!.add(to: .current, forMode: RunLoop.Mode.default)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
|
public func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
|
||||||
@@ -141,7 +146,7 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
}
|
}
|
||||||
return Unmanaged.passRetained(pixelBuffer!);
|
return Unmanaged.passRetained(pixelBuffer!);
|
||||||
}
|
}
|
||||||
|
|
||||||
public func onTextureUnregistered(_ texture:FlutterTexture) {
|
public func onTextureUnregistered(_ texture:FlutterTexture) {
|
||||||
print("Texture unregistered")
|
print("Texture unregistered")
|
||||||
}
|
}
|
||||||
@@ -150,57 +155,454 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
let _messenger = registrar.messenger();
|
let _messenger = registrar.messenger();
|
||||||
messenger = _messenger;
|
messenger = _messenger;
|
||||||
let channel = FlutterMethodChannel(name: "app.polyvox.filament/event", binaryMessenger: _messenger)
|
let channel = FlutterMethodChannel(name: "app.polyvox.filament/event", binaryMessenger: _messenger)
|
||||||
let instance = SwiftPolyvoxFilamentPlugin(textureRegistry: registrar.textures(), registrar:registrar)
|
let instance = SwiftPolyvoxFilamentPlugin(textureRegistry: registrar.textures(), registrar:registrar)
|
||||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(textureRegistry: FlutterTextureRegistry, registrar:FlutterPluginRegistrar) {
|
init(textureRegistry: FlutterTextureRegistry, registrar:FlutterPluginRegistrar) {
|
||||||
self.registry = textureRegistry;
|
self.registry = textureRegistry;
|
||||||
self.registrar = registrar
|
self.registrar = registrar
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createPixelBuffer(width:Int, height:Int) {
|
private func createPixelBuffer(width:Int, height:Int) {
|
||||||
if(CVPixelBufferCreate(kCFAllocatorDefault, Int(width), Int(height),
|
if(CVPixelBufferCreate(kCFAllocatorDefault, Int(width), Int(height),
|
||||||
kCVPixelFormatType_32BGRA, pixelBufferAttrs, &pixelBuffer) != kCVReturnSuccess) {
|
kCVPixelFormatType_32BGRA, pixelBufferAttrs, &pixelBuffer) != kCVReturnSuccess) {
|
||||||
print("Error allocating pixel buffer")
|
print("Error allocating pixel buffer")
|
||||||
}
|
}
|
||||||
self.flutterTextureId = self.registry.register(self)
|
self.flutterTextureId = self.registry.register(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func resize(width:Int32, height:Int32) {
|
private func resize(width:Int32, height:Int32) {
|
||||||
if(self.flutterTextureId != nil) {
|
if(self.flutterTextureId != nil) {
|
||||||
self.registry.unregisterTexture(self.flutterTextureId!)
|
self.registry.unregisterTexture(self.flutterTextureId!)
|
||||||
}
|
}
|
||||||
createPixelBuffer(width: Int(width), height:Int(height))
|
createPixelBuffer(width: Int(width), height:Int(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||||
let methodName = call.method;
|
let methodName = call.method;
|
||||||
print(methodName)
|
switch methodName {
|
||||||
switch methodName {
|
|
||||||
case "createTexture":
|
case "createTexture":
|
||||||
let args = call.arguments as! Array<Int32>
|
let args = call.arguments as! Array<Int32>
|
||||||
createPixelBuffer(width:Int(args[0]), height:Int(args[1]))
|
createPixelBuffer(width:Int(args[0]), height:Int(args[1]))
|
||||||
// we no longer need to call createDisplayLink() because we drive our render ticker from the Dart side, not the platform side
|
createDisplayLink()
|
||||||
result(self.flutterTextureId)
|
result(self.flutterTextureId)
|
||||||
case "getResourceLoader":
|
case "getResourceLoader":
|
||||||
let callback = make_resource_loader(loadResource, freeResource, Unmanaged.passUnretained(self).toOpaque())
|
let callback = make_resource_loader(loadResource, freeResource, Unmanaged.passUnretained(self).toOpaque())
|
||||||
result(unsafeBitCast(callback, to:Int64.self))
|
result(unsafeBitCast(callback, to:Int64.self))
|
||||||
case "getGlTextureId":
|
|
||||||
result(FlutterMethodNotImplemented)
|
|
||||||
case "getSurface":
|
|
||||||
var pixelBufferTextureId = Int64(Int(bitPattern:unsafeBitCast(pixelBuffer!, to: UnsafeMutableRawPointer.self)))
|
|
||||||
result(pixelBufferTextureId)
|
|
||||||
case "getContext":
|
|
||||||
result(0) //nullptr
|
|
||||||
case "resize":
|
case "resize":
|
||||||
result(self.flutterTextureId);
|
result(self.flutterTextureId);
|
||||||
case "tick":
|
case "createFilamentViewer":
|
||||||
self.registry.textureFrameAvailable(flutterTextureId!)
|
let callback = make_resource_loader(loadResource, freeResource, Unmanaged.passUnretained(self).toOpaque())
|
||||||
result(true)
|
let args = call.arguments as! [Any]
|
||||||
|
let width = args[0] as! Int64
|
||||||
|
let height = args[1] as! Int64
|
||||||
|
viewer = create_filament_viewer(nil, callback)
|
||||||
|
var pixelBufferTextureId = unsafeBitCast(pixelBuffer!, to: UnsafeRawPointer.self)
|
||||||
|
create_swap_chain(viewer, pixelBufferTextureId, UInt32(width), UInt32(height))
|
||||||
|
result(unsafeBitCast(viewer, to:Int64.self))
|
||||||
|
case "deleteFilamentViewer":
|
||||||
|
delete_filament_viewer(viewer)
|
||||||
|
viewer = nil
|
||||||
|
result(true)
|
||||||
|
case "getAssetManager":
|
||||||
|
let assetManager = get_asset_manager(viewer)
|
||||||
|
result(unsafeBitCast(assetManager, to:Int64.self))
|
||||||
|
case "createRenderTarget":
|
||||||
|
let args = call.arguments as! [Any]
|
||||||
|
create_render_target(viewer, args[0] as! UInt32, args[1] as! UInt32, args[2] as! UInt32)
|
||||||
|
result(true)
|
||||||
|
case "clearBackgroundImage":
|
||||||
|
clear_background_image(viewer)
|
||||||
|
result(true)
|
||||||
|
case "setBackgroundImage":
|
||||||
|
set_background_image(viewer, call.arguments as! String)
|
||||||
|
result(true)
|
||||||
|
case "setBackgroundImagePosition":
|
||||||
|
let args = call.arguments as! [Any]
|
||||||
|
set_background_image_position(viewer, Float(args[0] as! Double), Float(args[1] as! Double), args[2] as! Bool)
|
||||||
|
result(true)
|
||||||
|
case "setBackgroundColor":
|
||||||
|
guard let args = call.arguments as? [Double], args.count == 4 else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected RGBA values for setBackgroundColor", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
set_background_color(viewer, Float(args[0]), Float(args[1]), Float(args[2]), Float(args[3]))
|
||||||
|
result(true)
|
||||||
|
|
||||||
|
case "loadSkybox":
|
||||||
|
|
||||||
|
load_skybox(viewer, call.arguments as! String)
|
||||||
|
result(true)
|
||||||
|
case "loadIbl":
|
||||||
|
let args = call.arguments as! [Any]
|
||||||
|
load_ibl(viewer, args[0] as! String, args[1] as! Float)
|
||||||
|
result(true)
|
||||||
|
case "removeSkybox":
|
||||||
|
remove_skybox(viewer)
|
||||||
|
result(true)
|
||||||
|
case "removeIbl":
|
||||||
|
remove_ibl(viewer)
|
||||||
|
result(true)
|
||||||
|
case "addLight":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 10,
|
||||||
|
let type = args[0] as? Int32,
|
||||||
|
let colour = args[1] as? Double,
|
||||||
|
let intensity = args[2] as? Double,
|
||||||
|
let posX = args[3] as? Double,
|
||||||
|
let posY = args[4] as? Double,
|
||||||
|
let posZ = args[5] as? Double,
|
||||||
|
let dirX = args[6] as? Double,
|
||||||
|
let dirY = args[7] as? Double,
|
||||||
|
let dirZ = args[8] as? Double,
|
||||||
|
let shadows = args[9] as? Bool else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected viewer and light parameters for addLight", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let entityId = add_light(viewer, UInt8(type), Float(colour), Float(intensity),Float(posX), Float(posY), Float(posZ), Float(dirX), Float(dirY), Float(dirZ), shadows)
|
||||||
|
result(entityId)
|
||||||
|
|
||||||
|
case "removeLight":
|
||||||
|
remove_light(viewer, Int32(call.arguments as! Int64))
|
||||||
|
result(true)
|
||||||
|
case "clearLights":
|
||||||
|
clear_lights(viewer)
|
||||||
|
result(true)
|
||||||
|
case "loadGlb":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let assetPath = args[1] as? String,
|
||||||
|
let unlit = args[2] as? Bool else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected assetManager, assetPath, and unlit for load_glb", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let entityId = load_glb(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), assetPath, unlit)
|
||||||
|
result(entityId)
|
||||||
|
case "loadGltf":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let assetPath = args[1] as? String,
|
||||||
|
let relativePath = args[2] as? String else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected assetManager, assetPath, and relativePath for load_gltf", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let entityId = load_gltf(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), assetPath, relativePath)
|
||||||
|
result(entityId)
|
||||||
|
case "transformToUnitCube":
|
||||||
|
let args = call.arguments as! [Any]
|
||||||
|
transform_to_unit_cube(unsafeBitCast(args[0] as! Int64, to:UnsafeMutableRawPointer.self), args[1] as! EntityId)
|
||||||
|
result(true)
|
||||||
|
case "render":
|
||||||
|
render(viewer, 0)
|
||||||
|
result(true)
|
||||||
|
case "setRendering":
|
||||||
|
rendering = call.arguments as! Bool
|
||||||
|
result(true)
|
||||||
|
case "setFrameInterval":
|
||||||
|
set_frame_interval(viewer, Float(call.arguments as! Double))
|
||||||
|
result(true)
|
||||||
|
case "updateViewportAndCameraProjection":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let width = args[0] as? Int,
|
||||||
|
let height = args[1] as? Int,
|
||||||
|
let scaleFactor = args[2] as? Float else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected viewer, width, height, and scaleFactor for update_viewport_and_camera_projection", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
update_viewport_and_camera_projection(viewer, Int32(width), Int32(height), scaleFactor)
|
||||||
|
result(true)
|
||||||
|
case "scrollBegin":
|
||||||
|
scroll_begin(viewer)
|
||||||
|
result(true)
|
||||||
|
case "scrollUpdate":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let x = args[0] as? Double,
|
||||||
|
let y = args[1] as? Double,
|
||||||
|
let z = args[2] as? Double else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected viewer, x, y, and z for scroll_update", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
scroll_update(viewer, Float(x), Float(y), Float(z))
|
||||||
|
result(true)
|
||||||
|
|
||||||
|
case "scrollEnd":
|
||||||
|
scroll_end(viewer)
|
||||||
|
result(true)
|
||||||
|
case "grabBegin":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let x = args[0] as? Double,
|
||||||
|
let y = args[1] as? Double,
|
||||||
|
let pan = args[2] as? Bool else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected viewer, x, y, and pan for grab_begin", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
grab_begin(viewer, Float(x), Float(y), pan)
|
||||||
|
result(true)
|
||||||
|
|
||||||
|
case "grabUpdate":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 2,
|
||||||
|
let x = args[0] as? Float,
|
||||||
|
let y = args[1] as? Float else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected viewer, x, and y for grab_update", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
grab_update(viewer, x, y)
|
||||||
|
result(true)
|
||||||
|
|
||||||
|
case "grabEnd":
|
||||||
|
grab_end(viewer)
|
||||||
|
result(true)
|
||||||
|
case "applyWeights":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 5,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let entityName = args[2] as? String,
|
||||||
|
let weights = args[3] as? [Float],
|
||||||
|
let count = args[4] as? Int else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for apply_weights", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// apply_weights(assetManager, asset, entityName, UnsafeMutablePointer(&weights), Int32(count))
|
||||||
|
result(true)
|
||||||
|
case "setMorphTargetWeights":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 4,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let entityName = args[2] as? String,
|
||||||
|
let morphData = args[3] as? [Float],
|
||||||
|
let numWeights = args[4] as? Int else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for set_morph_target_weights", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// set_morph_target_weights(assetManager, asset, entityName, UnsafeMutablePointer(&morphData), numWeights)
|
||||||
|
result(true)
|
||||||
|
|
||||||
|
case "setMorphAnimation":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 7,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let entityName = args[2] as? String,
|
||||||
|
let morphData = args[3] as? [Float],
|
||||||
|
let numMorphWeights = args[4] as? Int,
|
||||||
|
let numFrames = args[5] as? Int,
|
||||||
|
let frameLengthInMs = args[6] as? Float else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for set_morph_animation", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// let success = set_morph_animation(assetManager, asset, entityName, UnsafeMutablePointer(&morphData), numMorphWeights, numFrames, frameLengthInMs)
|
||||||
|
result(-1)
|
||||||
|
case "setBoneAnimation":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 9,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let frameData = args[2] as? [Float],
|
||||||
|
let numFrames = args[3] as? Int,
|
||||||
|
let numBones = args[4] as? Int,
|
||||||
|
let boneNames = args[5] as? [String],
|
||||||
|
let meshName = args[6] as? [String],
|
||||||
|
let numMeshTargets = args[7] as? Int,
|
||||||
|
let frameLengthInMs = args[8] as? Float else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for set_bone_animation", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Convert boneNames and meshName to C-style strings array.
|
||||||
|
// var cBoneNames: [UnsafePointer<CChar>?] = boneNames.map { $0.cString(using: .utf8) }
|
||||||
|
// var cMeshName: [UnsafePointer<CChar>?] = meshName.map { $0.cString(using: .utf8) }
|
||||||
|
//
|
||||||
|
// set_bone_animation(assetManager, asset, UnsafeMutablePointer(&frameData), numFrames, numBones, &cBoneNames, &cMeshName, numMeshTargets, frameLengthInMs)
|
||||||
|
|
||||||
|
// // Clean up after conversion
|
||||||
|
// for cStr in cBoneNames { free(UnsafeMutablePointer(mutating: cStr)) }
|
||||||
|
// for cStr in cMeshName { free(UnsafeMutablePointer(mutating: cStr)) }
|
||||||
|
|
||||||
|
result(true)
|
||||||
|
|
||||||
|
case "playAnimation":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 6,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let index = args[2] as? Int,
|
||||||
|
let loop = args[3] as? Bool,
|
||||||
|
let reverse = args[4] as? Bool,
|
||||||
|
let crossfade = args[5] as? Float else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for play_animation", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
play_animation(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, Int32(index), loop, reverse, crossfade)
|
||||||
|
result(true)
|
||||||
|
case "setAnimationFrame":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 4,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let animationIndex = args[2] as? Int,
|
||||||
|
let animationFrame = args[3] as? Int else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for set_animation_frame", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
set_animation_frame(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, Int32(animationIndex), Int32(animationFrame))
|
||||||
|
result(true)
|
||||||
|
|
||||||
|
case "stopAnimation":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let index = args[2] as? Int else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for stop_animation", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stop_animation(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, Int32(index))
|
||||||
|
result(true)
|
||||||
|
case "getAnimationCount":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 2,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for get_animation_count", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let count = get_animation_count(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset)
|
||||||
|
result(count)
|
||||||
|
case "getAnimationNames":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 2,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for get_animation_name", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var names:[String] = [];
|
||||||
|
var count = get_animation_count(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset)
|
||||||
|
var buffer = [CChar](repeating: 0, count: 256) // Assuming max name length of 256 for simplicity
|
||||||
|
for i in 0...count - 1 {
|
||||||
|
get_animation_name(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, &buffer, Int32(i))
|
||||||
|
let name = String(cString: buffer)
|
||||||
|
names.append(name)
|
||||||
|
}
|
||||||
|
result(names)
|
||||||
|
case "getAnimationName":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let index = args[2] as? Int else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for get_animation_name", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var buffer = [CChar](repeating: 0, count: 256) // Assuming max name length of 256 for simplicity
|
||||||
|
get_animation_name(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, &buffer, Int32(index))
|
||||||
|
let name = String(cString: buffer)
|
||||||
|
result(name)
|
||||||
|
|
||||||
|
case "getMorphTargetName":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 4,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let meshName = args[2] as? String,
|
||||||
|
let index = args[3] as? Int else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for get_morph_target_name", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var buffer = [CChar](repeating: 0, count: 256) // Assuming max name length of 256 for simplicity
|
||||||
|
get_morph_target_name(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, meshName, &buffer, Int32(index))
|
||||||
|
let targetName = String(cString: buffer)
|
||||||
|
result(targetName)
|
||||||
|
case "getMorphTargetNames":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let meshName = args[2] as? String else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for get_morph_target_name", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let count = get_morph_target_name_count(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, meshName)
|
||||||
|
var names:[String] = []
|
||||||
|
for i in 0...count - 1 {
|
||||||
|
var buffer = [CChar](repeating: 0, count: 256) // Assuming max name length of 256 for simplicity
|
||||||
|
get_morph_target_name(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, meshName, &buffer, Int32(i))
|
||||||
|
names.append(String(cString:buffer))
|
||||||
|
}
|
||||||
|
result(names)
|
||||||
|
case "getMorphTargetNameCount":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let meshName = args[2] as? String else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for get_morph_target_name_count", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let count = get_morph_target_name_count(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, meshName)
|
||||||
|
result(count)
|
||||||
|
|
||||||
|
case "removeAsset":
|
||||||
|
remove_asset(viewer, call.arguments as! EntityId)
|
||||||
|
result(true)
|
||||||
|
case "clearAssets":
|
||||||
|
clear_assets(viewer)
|
||||||
|
result(true)
|
||||||
|
case "setCamera":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let asset = args[0] as? Int64,
|
||||||
|
let nodeName = args[1] as? String else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected viewer, asset, and nodeName for set_camera", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let success = set_camera(viewer, Int32(asset), nodeName)
|
||||||
|
result(success)
|
||||||
|
|
||||||
|
case "setCameraPosition":
|
||||||
|
let args = call.arguments as! [Any]
|
||||||
|
set_camera_position(viewer, Float(args[0] as! Double), Float(args[1] as! Double), Float(args[2] as! Double))
|
||||||
|
result(true)
|
||||||
|
|
||||||
|
case "setCameraRotation":
|
||||||
|
let args = call.arguments as! [Any]
|
||||||
|
set_camera_rotation(viewer, Float(args[0] as! Double), Float(args[1] as! Double), Float(args[2] as! Double), Float(args[3] as! Double))
|
||||||
|
result(true)
|
||||||
|
case "setCameraModelMatrix":
|
||||||
|
guard let matrix = call.arguments as? [Float], matrix.count == 16 else { // Assuming a 4x4 matrix
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for set_camera_model_matrix", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
set_camera_model_matrix(viewer, matrix)
|
||||||
|
result(true)
|
||||||
|
case "setCameraFocalLength":
|
||||||
|
set_camera_focal_length(viewer, call.arguments as! Float)
|
||||||
|
result(true)
|
||||||
|
case "setCameraFocusDistance":
|
||||||
|
set_camera_focus_distance(viewer, call.arguments as! Float)
|
||||||
|
result(true)
|
||||||
|
|
||||||
|
|
||||||
|
case "hideMesh":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let meshName = args[2] as? String else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for hide_mesh", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = hide_mesh(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, meshName)
|
||||||
|
result(status)
|
||||||
|
|
||||||
|
case "revealMesh":
|
||||||
|
guard let args = call.arguments as? [Any], args.count == 3,
|
||||||
|
let assetManager = args[0] as? Int64,
|
||||||
|
let asset = args[1] as? EntityId,
|
||||||
|
let meshName = args[2] as? String else {
|
||||||
|
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for reveal_mesh", details: nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = reveal_mesh(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, meshName)
|
||||||
|
result(status)
|
||||||
default:
|
default:
|
||||||
result(FlutterMethodNotImplemented)
|
result(FlutterMethodNotImplemented)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace polyvox {
|
|||||||
|
|
||||||
class AssetManager {
|
class AssetManager {
|
||||||
public:
|
public:
|
||||||
AssetManager(ResourceLoaderWrapper* loader,
|
AssetManager(const ResourceLoaderWrapper* const loader,
|
||||||
NameComponentManager *ncm,
|
NameComponentManager *ncm,
|
||||||
Engine *engine,
|
Engine *engine,
|
||||||
Scene *scene);
|
Scene *scene);
|
||||||
@@ -40,7 +40,6 @@ namespace polyvox {
|
|||||||
size_t getLightEntityCount(EntityId e) const noexcept;
|
size_t getLightEntityCount(EntityId e) const noexcept;
|
||||||
void updateAnimations();
|
void updateAnimations();
|
||||||
|
|
||||||
|
|
||||||
bool setMorphAnimationBuffer(
|
bool setMorphAnimationBuffer(
|
||||||
EntityId entityId,
|
EntityId entityId,
|
||||||
const char* entityName,
|
const char* entityName,
|
||||||
@@ -59,7 +58,7 @@ namespace polyvox {
|
|||||||
const char** const meshName,
|
const char** const meshName,
|
||||||
int numMeshTargets,
|
int numMeshTargets,
|
||||||
float frameLengthInMs);
|
float frameLengthInMs);
|
||||||
void playAnimation(EntityId e, int index, bool loop, bool reverse);
|
void playAnimation(EntityId e, int index, bool loop, bool reverse, float crossfade = 0.3f);
|
||||||
void stopAnimation(EntityId e, int index);
|
void stopAnimation(EntityId e, int index);
|
||||||
void setMorphTargetWeights(const char* const entityName, float *weights, int count);
|
void setMorphTargetWeights(const char* const entityName, float *weights, int count);
|
||||||
void loadTexture(EntityId entity, const char* resourcePath, int renderableIndex);
|
void loadTexture(EntityId entity, const char* resourcePath, int renderableIndex);
|
||||||
@@ -69,7 +68,7 @@ namespace polyvox {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
AssetLoader* _assetLoader = nullptr;
|
AssetLoader* _assetLoader = nullptr;
|
||||||
ResourceLoaderWrapper* _resourceLoaderWrapper;
|
const ResourceLoaderWrapper* const _resourceLoaderWrapper;
|
||||||
NameComponentManager* _ncm = nullptr;
|
NameComponentManager* _ncm = nullptr;
|
||||||
Engine* _engine;
|
Engine* _engine;
|
||||||
Scene* _scene;
|
Scene* _scene;
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ typedef int32_t EntityId;
|
|||||||
namespace polyvox {
|
namespace polyvox {
|
||||||
class FilamentViewer {
|
class FilamentViewer {
|
||||||
public:
|
public:
|
||||||
// FilamentViewer(void* layer, LoadResource loadResource, FreeResource freeResource);
|
FilamentViewer(const void* context, const ResourceLoaderWrapper* const resourceLoaderWrapper);
|
||||||
FilamentViewer(void* context, ResourceLoaderWrapper* resourceLoaderWrapper);
|
|
||||||
~FilamentViewer();
|
~FilamentViewer();
|
||||||
|
|
||||||
void loadSkybox(const char* const skyboxUri);
|
void loadSkybox(const char* const skyboxUri);
|
||||||
@@ -64,7 +63,7 @@ namespace polyvox {
|
|||||||
|
|
||||||
bool setCamera(EntityId asset, const char* nodeName);
|
bool setCamera(EntityId asset, const char* nodeName);
|
||||||
|
|
||||||
void createSwapChain(void* surface, uint32_t width, uint32_t height);
|
void createSwapChain(const void* surface, uint32_t width, uint32_t height);
|
||||||
void destroySwapChain();
|
void destroySwapChain();
|
||||||
|
|
||||||
void createRenderTarget(uint32_t glTextureId, uint32_t width,uint32_t height);
|
void createRenderTarget(uint32_t glTextureId, uint32_t width,uint32_t height);
|
||||||
@@ -108,7 +107,7 @@ namespace polyvox {
|
|||||||
math::mat4f _cameraPosition;
|
math::mat4f _cameraPosition;
|
||||||
math::mat4f _cameraRotation;
|
math::mat4f _cameraRotation;
|
||||||
|
|
||||||
ResourceLoaderWrapper* _resourceLoaderWrapper;
|
const ResourceLoaderWrapper* const _resourceLoaderWrapper;
|
||||||
|
|
||||||
Scene* _scene;
|
Scene* _scene;
|
||||||
View* _view;
|
View* _view;
|
||||||
|
|||||||
@@ -3,43 +3,38 @@
|
|||||||
|
|
||||||
#include "ResourceBuffer.hpp"
|
#include "ResourceBuffer.hpp"
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
typedef int32_t EntityId;
|
typedef int32_t EntityId;
|
||||||
|
|
||||||
void* create_filament_viewer(void *context, ResourceLoaderWrapper* loader);
|
const void* create_filament_viewer(const void* const context, const ResourceLoaderWrapper* const loader);
|
||||||
ResourceLoaderWrapper* make_resource_loader(LoadResourceFromOwner loadFn, FreeResourceFromOwner freeFn, void* owner);
|
ResourceLoaderWrapper* make_resource_loader(LoadResourceFromOwner loadFn, FreeResourceFromOwner freeFn, void* owner);
|
||||||
void delete_filament_viewer(void *viewer);
|
void delete_filament_viewer(const void* const viewer);
|
||||||
void* get_asset_manager(void* viewer);
|
void* get_asset_manager(const void* const viewer);
|
||||||
void create_render_target(void *viewer, uint32_t textureId, uint32_t width, uint32_t height);
|
void create_render_target(const void* const viewer, uint32_t textureId, uint32_t width, uint32_t height);
|
||||||
void clear_background_image(void *viewer);
|
void clear_background_image(const void* const viewer);
|
||||||
void set_background_image(void *viewer, const char *path);
|
void set_background_image(const void* const viewer, const char *path);
|
||||||
void set_background_image_position(void *viewer, float x, float y, bool clamp);
|
void set_background_image_position(const void* const viewer, float x, float y, bool clamp);
|
||||||
void set_background_color(void *viewer, const float r, const float g, const float b, const float a);
|
void set_background_color(const void* const viewer, const float r, const float g, const float b, const float a);
|
||||||
void load_skybox(void *viewer, const char *skyboxPath);
|
void load_skybox(const void* const viewer, const char *skyboxPath);
|
||||||
void load_ibl(void *viewer, const char *iblPath, float intensity);
|
void load_ibl(const void* const viewer, const char *iblPath, float intensity);
|
||||||
void remove_skybox(void *viewer);
|
void remove_skybox(const void* const viewer);
|
||||||
void remove_ibl(void *viewer);
|
void remove_ibl(const void* const viewer);
|
||||||
EntityId add_light(void *viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
EntityId add_light(const void* const viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||||
void remove_light(void *viewer, EntityId entityId);
|
void remove_light(const void* const viewer, EntityId entityId);
|
||||||
void clear_lights(void *viewer);
|
void clear_lights(const void* const viewer);
|
||||||
EntityId load_glb(void *assetManager, const char *assetPath, bool unlit);
|
EntityId load_glb(void *assetManager, const char *assetPath, bool unlit);
|
||||||
EntityId load_gltf(void *assetManager, const char *assetPath, const char *relativePath);
|
EntityId load_gltf(void *assetManager, const char *assetPath, const char *relativePath);
|
||||||
bool set_camera(void *viewer, EntityId asset, const char *nodeName);
|
bool set_camera(const void* const viewer, EntityId asset, const char *nodeName);
|
||||||
void render(void *viewer, uint64_t frameTimeInNanos);
|
void render(const void* const viewer, uint64_t frameTimeInNanos);
|
||||||
void create_swap_chain(void *viewer, void *surface, uint32_t width, uint32_t height);
|
void create_swap_chain(const void* const viewer, const void* const surface, uint32_t width, uint32_t height);
|
||||||
void destroy_swap_chain(void *viewer);
|
void destroy_swap_chain(const void* const viewer);
|
||||||
void set_frame_interval(void *viewer, float interval);
|
void set_frame_interval(const void* const viewer, float interval);
|
||||||
void* get_renderer(void *viewer);
|
void update_viewport_and_camera_projection(const void* const viewer, int width, int height, float scaleFactor);
|
||||||
void update_viewport_and_camera_projection(void *viewer, int width, int height, float scaleFactor);
|
void scroll_begin(const void* const viewer);
|
||||||
void scroll_begin(void *viewer);
|
void scroll_update(const void* const viewer, float x, float y, float z);
|
||||||
void scroll_update(void *viewer, float x, float y, float z);
|
void scroll_end(const void* const viewer);
|
||||||
void scroll_end(void *viewer);
|
void grab_begin(const void* const viewer, float x, float y, bool pan);
|
||||||
|
void grab_update(const void* const viewer, float x, float y);
|
||||||
void grab_begin(void *viewer, float x, float y, bool pan);
|
void grab_end(const void* const viewer);
|
||||||
void grab_update(void *viewer, float x, float y);
|
|
||||||
void grab_end(void *viewer);
|
|
||||||
|
|
||||||
void apply_weights(
|
void apply_weights(
|
||||||
void* assetManager,
|
void* assetManager,
|
||||||
EntityId asset,
|
EntityId asset,
|
||||||
@@ -47,7 +42,6 @@ void apply_weights(
|
|||||||
float *const weights,
|
float *const weights,
|
||||||
int count
|
int count
|
||||||
);
|
);
|
||||||
|
|
||||||
void set_morph_target_weights(
|
void set_morph_target_weights(
|
||||||
void* assetManager,
|
void* assetManager,
|
||||||
EntityId asset,
|
EntityId asset,
|
||||||
@@ -55,7 +49,6 @@ void set_morph_target_weights(
|
|||||||
const float *const morphData,
|
const float *const morphData,
|
||||||
int numWeights
|
int numWeights
|
||||||
);
|
);
|
||||||
|
|
||||||
bool set_morph_animation(
|
bool set_morph_animation(
|
||||||
void* assetManager,
|
void* assetManager,
|
||||||
EntityId asset,
|
EntityId asset,
|
||||||
@@ -64,7 +57,6 @@ bool set_morph_animation(
|
|||||||
int numMorphWeights,
|
int numMorphWeights,
|
||||||
int numFrames,
|
int numFrames,
|
||||||
float frameLengthInMs);
|
float frameLengthInMs);
|
||||||
|
|
||||||
void set_bone_animation(
|
void set_bone_animation(
|
||||||
void* assetManager,
|
void* assetManager,
|
||||||
EntityId asset,
|
EntityId asset,
|
||||||
@@ -76,29 +68,30 @@ void set_bone_animation(
|
|||||||
int numMeshTargets,
|
int numMeshTargets,
|
||||||
float frameLengthInMs);
|
float frameLengthInMs);
|
||||||
|
|
||||||
void play_animation(void* assetManager, EntityId asset, int index, bool loop, bool reverse);
|
void play_animation(void* assetManager, EntityId asset, int index, bool loop, bool reverse, float crossfade);
|
||||||
void set_animation_frame(void* assetManager, EntityId asset, int animationIndex, int animationFrame);
|
void set_animation_frame(void* assetManager, EntityId asset, int animationIndex, int animationFrame);
|
||||||
void stop_animation(void* assetManager, EntityId asset, int index);
|
void stop_animation(void* assetManager, EntityId asset, int index);
|
||||||
int get_animation_count(void* assetManager, EntityId asset);
|
int get_animation_count(void* assetManager, EntityId asset);
|
||||||
void get_animation_name(void* assetManager, EntityId asset, char *const outPtr, int index);
|
void get_animation_name(void* assetManager, EntityId asset, char *const outPtr, int index);
|
||||||
void get_morph_target_name(void* assetManager, EntityId asset, const char *meshName, char *const outPtr, int index);
|
void get_morph_target_name(void* assetManager, EntityId asset, const char *meshName, char *const outPtr, int index);
|
||||||
int get_morph_target_name_count(void* assetManager, EntityId asset, const char *meshName);
|
int get_morph_target_name_count(void* assetManager, EntityId asset, const char *meshName);
|
||||||
void remove_asset(void *viewer, EntityId asset);
|
void remove_asset(const void* const viewer, EntityId asset);
|
||||||
void clear_assets(void *viewer);
|
void clear_assets(const void* const viewer);
|
||||||
void load_texture(void* assetManager, EntityId asset, const char *assetPath, int renderableIndex);
|
void load_texture(void* assetManager, EntityId asset, const char *assetPath, int renderableIndex);
|
||||||
void set_texture(void* assetManager, EntityId asset);
|
void set_texture(void* assetManager, EntityId asset);
|
||||||
void transform_to_unit_cube(void* assetManager, EntityId asset);
|
void transform_to_unit_cube(void* assetManager, EntityId asset);
|
||||||
void set_position(void* assetManager, EntityId asset, float x, float y, float z);
|
void set_position(void* assetManager, EntityId asset, float x, float y, float z);
|
||||||
void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z);
|
void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z);
|
||||||
void set_scale(void* assetManager, EntityId asset, float scale);
|
void set_scale(void* assetManager, EntityId asset, float scale);
|
||||||
void set_camera_exposure(void *viewer, float aperture, float shutterSpeed, float sensitivity);
|
void set_camera_exposure(const void* const viewer, float aperture, float shutterSpeed, float sensitivity);
|
||||||
void set_camera_position(void *viewer, float x, float y, float z);
|
void set_camera_position(const void* const viewer, float x, float y, float z);
|
||||||
void set_camera_rotation(void *viewer, float rads, float x, float y, float z);
|
void set_camera_rotation(const void* const viewer, float rads, float x, float y, float z);
|
||||||
void set_camera_model_matrix(void *viewer, const float *const matrix);
|
void set_camera_model_matrix(const void* const viewer, const float *const matrix);
|
||||||
void set_camera_focal_length(void *viewer, float focalLength);
|
void set_camera_focal_length(const void* const viewer, float focalLength);
|
||||||
void set_camera_focus_distance(void *viewer, float focusDistance);
|
void set_camera_focus_distance(const void* const viewer, float focusDistance);
|
||||||
int hide_mesh(void* assetManager, EntityId asset, const char* meshName);
|
int hide_mesh(void* assetManager, EntityId asset, const char* meshName);
|
||||||
int reveal_mesh(void* assetManager, EntityId asset, const char* meshName);
|
int reveal_mesh(void* assetManager, EntityId asset, const char* meshName);
|
||||||
void ios_dummy();
|
void ios_dummy();
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -51,14 +51,14 @@ extern "C" {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ResourceBuffer load(const char* uri) {
|
ResourceBuffer load(const char* uri) const {
|
||||||
if(mLoadResourceFromOwner) {
|
if(mLoadResourceFromOwner) {
|
||||||
return mLoadResourceFromOwner(uri, mOwner);
|
return mLoadResourceFromOwner(uri, mOwner);
|
||||||
}
|
}
|
||||||
return mLoadResource(uri);
|
return mLoadResource(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(ResourceBuffer rb) {
|
void free(ResourceBuffer rb) const {
|
||||||
if(mFreeResourceFromOwner) {
|
if(mFreeResourceFromOwner) {
|
||||||
mFreeResourceFromOwner(rb, mOwner);
|
mFreeResourceFromOwner(rb, mOwner);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ namespace polyvox {
|
|||||||
time_point_t mStart = time_point_t::max();
|
time_point_t mStart = time_point_t::max();
|
||||||
bool mLoop = false;
|
bool mLoop = false;
|
||||||
bool mReverse = false;
|
bool mReverse = false;
|
||||||
float mDuration = 0;
|
float mDuration = 0;
|
||||||
bool mAnimating = false;
|
bool mActive = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -73,10 +73,16 @@ namespace polyvox {
|
|||||||
FilamentAsset* mAsset = nullptr;
|
FilamentAsset* mAsset = nullptr;
|
||||||
Animator* mAnimator = nullptr;
|
Animator* mAnimator = nullptr;
|
||||||
|
|
||||||
// fixed-sized vector containing the status of the morph, bone and GLTF animations.
|
// fixed-sized array containing pointers to the active morph, bone and GLTF animations.
|
||||||
// entries 0 and 1 are the morph/bone animations.
|
AnimationStatus mAnimations[3];
|
||||||
// subsequent entries are the GLTF animations.
|
// the index of the active glTF animation in the Filament Asset animations array
|
||||||
vector<AnimationStatus> mAnimations;
|
// if no glTF animation is active, this is -1
|
||||||
|
int gltfAnimationIndex = -1;
|
||||||
|
// the index of the last active glTF animation,
|
||||||
|
// used to cross-fade
|
||||||
|
int fadeGltfAnimationIndex = -1;
|
||||||
|
float fadeDuration = 0.0f;
|
||||||
|
float fadeOutAnimationStart = 0.0f;
|
||||||
|
|
||||||
MorphAnimationBuffer mMorphAnimationBuffer;
|
MorphAnimationBuffer mMorphAnimationBuffer;
|
||||||
BoneAnimationBuffer mBoneAnimationBuffer;
|
BoneAnimationBuffer mBoneAnimationBuffer;
|
||||||
@@ -96,12 +102,6 @@ namespace polyvox {
|
|||||||
FilamentAsset* asset
|
FilamentAsset* asset
|
||||||
) : mAsset(asset) {
|
) : mAsset(asset) {
|
||||||
mAnimator = mAsset->getInstance()->getAnimator();
|
mAnimator = mAsset->getInstance()->getAnimator();
|
||||||
|
|
||||||
mAnimations.resize(2 + mAnimator->getAnimationCount());
|
|
||||||
|
|
||||||
for(int i=0; i < mAnimations.size() - 2; i++) {
|
|
||||||
mAnimations[i].mDuration = mAnimator->getAnimationDuration(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ using namespace utils;
|
|||||||
using namespace filament;
|
using namespace filament;
|
||||||
using namespace filament::gltfio;
|
using namespace filament::gltfio;
|
||||||
|
|
||||||
AssetManager::AssetManager(ResourceLoaderWrapper* resourceLoaderWrapper,
|
AssetManager::AssetManager(const ResourceLoaderWrapper* const resourceLoaderWrapper,
|
||||||
NameComponentManager *ncm,
|
NameComponentManager *ncm,
|
||||||
Engine *engine,
|
Engine *engine,
|
||||||
Scene *scene)
|
Scene *scene)
|
||||||
@@ -249,37 +249,34 @@ void AssetManager::updateAnimations() {
|
|||||||
asset.mAnimating = false;
|
asset.mAnimating = false;
|
||||||
|
|
||||||
// GLTF animations
|
// GLTF animations
|
||||||
for(int j = 0; j < asset.mAnimations.size() - 2; j++) {
|
AnimationStatus& anim = asset.mAnimations[2];
|
||||||
AnimationStatus& anim = asset.mAnimations[j];
|
|
||||||
|
|
||||||
if(!anim.mAnimating) {
|
if(anim.mActive) {
|
||||||
// Log("Skipping anim at %d", j);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto elapsed = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - anim.mStart).count()) / 1000.0f;
|
auto elapsed = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - anim.mStart).count()) / 1000.0f;
|
||||||
|
|
||||||
if(anim.mLoop || elapsed < anim.mDuration) {
|
if(anim.mLoop || elapsed < anim.mDuration) {
|
||||||
asset.mAnimator->applyAnimation(j, elapsed);
|
asset.mAnimator->applyAnimation(asset.gltfAnimationIndex, elapsed);
|
||||||
asset.mAnimating = true;
|
asset.mAnimating = true;
|
||||||
} else if(elapsed - anim.mDuration < 0.3) {
|
if(asset.fadeGltfAnimationIndex != -1 && elapsed < asset.fadeDuration) {
|
||||||
// cross-fade
|
// cross-fade
|
||||||
// animator->applyCrossFade(j-2, anim.mDuration - 0.05, elapsed / 0.3);
|
auto fadeFromTime = asset.fadeOutAnimationStart + elapsed;
|
||||||
// asset.mAnimating = true;
|
auto alpha = elapsed / asset.fadeDuration;
|
||||||
// anim.mStart = time_point_t::max();
|
asset.mAnimator->applyCrossFade(asset.fadeGltfAnimationIndex, fadeFromTime, alpha);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// stop
|
// stop
|
||||||
anim.mStart = time_point_t::max();
|
anim.mStart = time_point_t::max();
|
||||||
anim.mAnimating = false;
|
anim.mActive = false;
|
||||||
Log("Finished");
|
asset.gltfAnimationIndex = -1;
|
||||||
|
asset.fadeGltfAnimationIndex = -1;
|
||||||
}
|
}
|
||||||
asset.mAnimator->updateBoneMatrices();
|
asset.mAnimator->updateBoneMatrices();
|
||||||
}
|
}
|
||||||
|
|
||||||
// dynamically constructed morph animation
|
// dynamic morph animation
|
||||||
AnimationStatus& morphAnimation = asset.mAnimations[asset.mAnimations.size() - 2];
|
AnimationStatus& morphAnimation = asset.mAnimations[0];
|
||||||
|
|
||||||
if(morphAnimation.mAnimating) {
|
if(morphAnimation.mActive) {
|
||||||
|
|
||||||
auto elapsed = float(
|
auto elapsed = float(
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
@@ -290,13 +287,11 @@ void AssetManager::updateAnimations() {
|
|||||||
asset.mMorphAnimationBuffer.mFrameLengthInMs
|
asset.mMorphAnimationBuffer.mFrameLengthInMs
|
||||||
);
|
);
|
||||||
|
|
||||||
// if more time has elapsed than the animation duration && not looping
|
// if more time has elapsed than the animation duration && we aren't looping, then mark the animation as complete
|
||||||
// mark the animation as complete
|
|
||||||
if(elapsed >= morphAnimation.mDuration && !morphAnimation.mLoop) {
|
if(elapsed >= morphAnimation.mDuration && !morphAnimation.mLoop) {
|
||||||
morphAnimation.mStart = time_point_t::max();
|
morphAnimation.mStart = time_point_t::max();
|
||||||
morphAnimation.mAnimating = false;
|
morphAnimation.mActive = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
asset.mAnimating = true;
|
asset.mAnimating = true;
|
||||||
int frameNumber = static_cast<int>(elapsed * 1000.0f / asset.mMorphAnimationBuffer.mFrameLengthInMs) % lengthInFrames;
|
int frameNumber = static_cast<int>(elapsed * 1000.0f / asset.mMorphAnimationBuffer.mFrameLengthInMs) % lengthInFrames;
|
||||||
// offset from the end if reverse
|
// offset from the end if reverse
|
||||||
@@ -304,17 +299,18 @@ void AssetManager::updateAnimations() {
|
|||||||
frameNumber = lengthInFrames - frameNumber;
|
frameNumber = lengthInFrames - frameNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the weights appropriately
|
// set the weights appropriately
|
||||||
rm.setMorphWeights(
|
rm.setMorphWeights(
|
||||||
rm.getInstance(asset.mMorphAnimationBuffer.mMeshTarget),
|
rm.getInstance(asset.mMorphAnimationBuffer.mMeshTarget),
|
||||||
asset.mMorphAnimationBuffer.mFrameData.data() + (frameNumber * asset.mMorphAnimationBuffer.mNumMorphWeights),
|
asset.mMorphAnimationBuffer.mFrameData.data() + (frameNumber * asset.mMorphAnimationBuffer.mNumMorphWeights),
|
||||||
asset.mMorphAnimationBuffer.mNumMorphWeights);
|
asset.mMorphAnimationBuffer.mNumMorphWeights
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bone animation
|
// dynamic bone animations
|
||||||
AnimationStatus boneAnimation = asset.mAnimations[asset.mAnimations.size() - 1];
|
AnimationStatus boneAnimation = asset.mAnimations[1];
|
||||||
if(boneAnimation.mAnimating) {
|
if(boneAnimation.mActive) {
|
||||||
auto elapsed = float(
|
auto elapsed = float(
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
now - boneAnimation.mStart
|
now - boneAnimation.mStart
|
||||||
@@ -324,11 +320,10 @@ void AssetManager::updateAnimations() {
|
|||||||
asset.mBoneAnimationBuffer.mFrameLengthInMs
|
asset.mBoneAnimationBuffer.mFrameLengthInMs
|
||||||
);
|
);
|
||||||
|
|
||||||
// if more time has elapsed than the animation duration && not looping
|
// if more time has elapsed than the animation duration and we are not looping, mark the animation as complete
|
||||||
// mark the animation as complete
|
|
||||||
if(elapsed >= boneAnimation.mDuration && !boneAnimation.mLoop) {
|
if(elapsed >= boneAnimation.mDuration && !boneAnimation.mLoop) {
|
||||||
boneAnimation.mStart = time_point_t::max();
|
boneAnimation.mStart = time_point_t::max();
|
||||||
boneAnimation.mAnimating = false;
|
boneAnimation.mActive = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
asset.mAnimating = true;
|
asset.mAnimating = true;
|
||||||
@@ -347,7 +342,6 @@ void AssetManager::updateAnimations() {
|
|||||||
asset.mAnimator->updateBoneMatrices();
|
asset.mAnimator->updateBoneMatrices();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::setBoneTransform(SceneAsset& asset, int frameNumber) {
|
void AssetManager::setBoneTransform(SceneAsset& asset, int frameNumber) {
|
||||||
@@ -482,15 +476,11 @@ bool AssetManager::setMorphAnimationBuffer(
|
|||||||
asset.mMorphAnimationBuffer.mFrameLengthInMs = frameLengthInMs;
|
asset.mMorphAnimationBuffer.mFrameLengthInMs = frameLengthInMs;
|
||||||
asset.mMorphAnimationBuffer.mNumMorphWeights = numMorphWeights;
|
asset.mMorphAnimationBuffer.mNumMorphWeights = numMorphWeights;
|
||||||
|
|
||||||
AnimationStatus& animation = asset.mAnimations[asset.mAnimations.size() - 2];
|
AnimationStatus& animation = asset.mAnimations[0];
|
||||||
animation.mDuration = (frameLengthInMs * numFrames) / 1000.0f;
|
animation.mDuration = (frameLengthInMs * numFrames) / 1000.0f;
|
||||||
animation.mStart = high_resolution_clock::now();
|
animation.mStart = high_resolution_clock::now();
|
||||||
animation.mAnimating = true;
|
animation.mActive = true;
|
||||||
asset.mAnimating = true;
|
asset.mAnimating = true;
|
||||||
Log("set start to %d, dur is %f",
|
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(animation.mStart.time_since_epoch()).count(),
|
|
||||||
animation.mDuration
|
|
||||||
);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,8 +494,6 @@ bool AssetManager::setBoneAnimationBuffer(
|
|||||||
int numMeshTargets,
|
int numMeshTargets,
|
||||||
float frameLengthInMs) {
|
float frameLengthInMs) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const auto& pos = _entityIdLookup.find(entityId);
|
const auto& pos = _entityIdLookup.find(entityId);
|
||||||
if(pos == _entityIdLookup.end()) {
|
if(pos == _entityIdLookup.end()) {
|
||||||
Log("ERROR: asset not found for entity.");
|
Log("ERROR: asset not found for entity.");
|
||||||
@@ -585,9 +573,9 @@ bool AssetManager::setBoneAnimationBuffer(
|
|||||||
animationBuffer.mMeshTargets.push_back(entity);
|
animationBuffer.mMeshTargets.push_back(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& animation = asset.mAnimations[asset.mAnimations.size() - 1];
|
auto& animation = asset.mAnimations[1];
|
||||||
animation.mStart = std::chrono::high_resolution_clock::now();
|
animation.mStart = std::chrono::high_resolution_clock::now();
|
||||||
animation.mAnimating = true;
|
animation.mActive = true;
|
||||||
animation.mReverse = false;
|
animation.mReverse = false;
|
||||||
animation.mDuration = (frameLengthInMs * numFrames) / 1000.0f;
|
animation.mDuration = (frameLengthInMs * numFrames) / 1000.0f;
|
||||||
asset.mAnimating = true;
|
asset.mAnimating = true;
|
||||||
@@ -596,21 +584,31 @@ bool AssetManager::setBoneAnimationBuffer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AssetManager::playAnimation(EntityId e, int index, bool loop, bool reverse, float crossfade) {
|
||||||
void AssetManager::playAnimation(EntityId e, int index, bool loop, bool reverse) {
|
|
||||||
const auto& pos = _entityIdLookup.find(e);
|
const auto& pos = _entityIdLookup.find(e);
|
||||||
if(pos == _entityIdLookup.end()) {
|
if(pos == _entityIdLookup.end()) {
|
||||||
Log("ERROR: asset not found for entity.");
|
Log("ERROR: asset not found for entity.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& asset = _assets[pos->second];
|
auto& asset = _assets[pos->second];
|
||||||
Log("Playing animation at %d", index);
|
|
||||||
|
if(asset.gltfAnimationIndex != -1) {
|
||||||
asset.mAnimations[index].mStart = std::chrono::high_resolution_clock::now();
|
asset.fadeGltfAnimationIndex = asset.gltfAnimationIndex;
|
||||||
asset.mAnimations[index].mLoop = loop;
|
asset.fadeDuration = crossfade;
|
||||||
asset.mAnimations[index].mReverse = reverse;
|
auto now = high_resolution_clock::now();
|
||||||
asset.mAnimations[index].mAnimating = true;
|
auto elapsed = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - asset.mAnimations[2].mStart).count()) / 1000.0f;
|
||||||
// Log("new start %d, dur is %f", std::chrono::duration_cast<std::chrono::milliseconds>(asset.mAnimations[index+2].mStart.time_since_epoch()).count(), asset.mAnimations[index+2].mDuration);
|
asset.fadeOutAnimationStart = elapsed;
|
||||||
|
} else {
|
||||||
|
asset.fadeGltfAnimationIndex = -1;
|
||||||
|
asset.fadeDuration = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
asset.gltfAnimationIndex = index;
|
||||||
|
asset.mAnimations[2].mStart = std::chrono::high_resolution_clock::now();
|
||||||
|
asset.mAnimations[2].mLoop = loop;
|
||||||
|
asset.mAnimations[2].mReverse = reverse;
|
||||||
|
asset.mAnimations[2].mActive = true;
|
||||||
|
asset.mAnimations[2].mDuration = asset.mAnimator->getAnimationDuration(index);
|
||||||
asset.mAnimating = true;
|
asset.mAnimating = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,7 +619,12 @@ void AssetManager::stopAnimation(EntityId entityId, int index) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& asset = _assets[pos->second];
|
auto& asset = _assets[pos->second];
|
||||||
asset.mAnimations[index].mStart = time_point_t::max();
|
if(asset.gltfAnimationIndex != index) {
|
||||||
|
// ignore?
|
||||||
|
} else {
|
||||||
|
asset.mAnimations[2].mStart = time_point_t::max();
|
||||||
|
asset.mAnimations[2].mActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::loadTexture(EntityId entity, const char* resourcePath, int renderableIndex) {
|
void AssetManager::loadTexture(EntityId entity, const char* resourcePath, int renderableIndex) {
|
||||||
@@ -898,4 +901,4 @@ size_t AssetManager::getLightEntityCount(EntityId entity) const noexcept {
|
|||||||
// Log("%f %f %f %f", localTransform[0][1], localTransform[1][1], localTransform[2][1], localTransform[3][1] ) ;
|
// Log("%f %f %f %f", localTransform[0][1], localTransform[1][1], localTransform[2][1], localTransform[3][1] ) ;
|
||||||
// Log("%f %f %f %f", localTransform[0][2], localTransform[1][2], localTransform[2][2], localTransform[3][2] ) ;
|
// Log("%f %f %f %f", localTransform[0][2], localTransform[1][2], localTransform[2][2], localTransform[3][2] ) ;
|
||||||
// Log("%f %f %f %f", localTransform[0][3], localTransform[1][3], localTransform[2][3], localTransform[3][3] ) ;
|
// Log("%f %f %f %f", localTransform[0][3], localTransform[1][3], localTransform[2][3], localTransform[3][3] ) ;
|
||||||
// transformManager.getTransform(jointInstance);
|
// transformManager.getTransform(jointInstance);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ static constexpr float4 sFullScreenTriangleVertices[3] = {
|
|||||||
|
|
||||||
static const uint16_t sFullScreenTriangleIndices[3] = {0, 1, 2};
|
static const uint16_t sFullScreenTriangleIndices[3] = {0, 1, 2};
|
||||||
|
|
||||||
FilamentViewer::FilamentViewer(void* context, ResourceLoaderWrapper* resourceLoaderWrapper)
|
FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper* const resourceLoaderWrapper)
|
||||||
: _resourceLoaderWrapper(resourceLoaderWrapper) {
|
: _resourceLoaderWrapper(resourceLoaderWrapper) {
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
@@ -137,13 +137,14 @@ FilamentViewer::FilamentViewer(void* context, ResourceLoaderWrapper* resourceLoa
|
|||||||
_view = _engine->createView();
|
_view = _engine->createView();
|
||||||
|
|
||||||
decltype(_view->getBloomOptions()) opts;
|
decltype(_view->getBloomOptions()) opts;
|
||||||
opts.enabled = false;//true;
|
opts.enabled = true;
|
||||||
// opts.strength = 0.6f;
|
opts.strength = 0.6f;
|
||||||
_view->setBloomOptions(opts);
|
_view->setBloomOptions(opts);
|
||||||
|
|
||||||
_view->setScene(_scene);
|
_view->setScene(_scene);
|
||||||
_view->setCamera(_mainCamera);
|
_view->setCamera(_mainCamera);
|
||||||
|
|
||||||
|
// ToneMapper *tm = new ACESToneMapper();
|
||||||
ToneMapper *tm = new LinearToneMapper();
|
ToneMapper *tm = new LinearToneMapper();
|
||||||
colorGrading = ColorGrading::Builder().toneMapper(tm).build(*_engine);
|
colorGrading = ColorGrading::Builder().toneMapper(tm).build(*_engine);
|
||||||
delete tm;
|
delete tm;
|
||||||
@@ -168,8 +169,7 @@ FilamentViewer::FilamentViewer(void* context, ResourceLoaderWrapper* resourceLoa
|
|||||||
// options.minScale = filament::math::float2{ minScale };
|
// options.minScale = filament::math::float2{ minScale };
|
||||||
// options.maxScale = filament::math::float2{ maxScale };
|
// options.maxScale = filament::math::float2{ maxScale };
|
||||||
// options.sharpness = sharpness;
|
// options.sharpness = sharpness;
|
||||||
options.quality = View::QualityLevel::ULTRA;
|
// options.quality = View::QualityLevel::ULTRA;
|
||||||
|
|
||||||
_view->setDynamicResolutionOptions(options);
|
_view->setDynamicResolutionOptions(options);
|
||||||
|
|
||||||
View::MultiSampleAntiAliasingOptions multiSampleAntiAliasingOptions;
|
View::MultiSampleAntiAliasingOptions multiSampleAntiAliasingOptions;
|
||||||
@@ -206,7 +206,7 @@ FilamentViewer::FilamentViewer(void* context, ResourceLoaderWrapper* resourceLoa
|
|||||||
.package(IMAGE_PACKAGE, IMAGE_IMAGE_SIZE)
|
.package(IMAGE_PACKAGE, IMAGE_IMAGE_SIZE)
|
||||||
.build(*_engine);
|
.build(*_engine);
|
||||||
_imageMaterial->setDefaultParameter("showImage",0);
|
_imageMaterial->setDefaultParameter("showImage",0);
|
||||||
_imageMaterial->setDefaultParameter("backgroundColor", RgbType::sRGB, float3(0.f));
|
_imageMaterial->setDefaultParameter("backgroundColor", RgbaType::sRGB, float4(0.5f, 0.5f, 0.5f, 1.0f));
|
||||||
_imageMaterial->setDefaultParameter("image", _imageTexture, _imageSampler);
|
_imageMaterial->setDefaultParameter("image", _imageTexture, _imageSampler);
|
||||||
_imageScale = mat4f { 1.0f , 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
|
_imageScale = mat4f { 1.0f , 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
|
|
||||||
@@ -251,7 +251,6 @@ void FilamentViewer::setFrameInterval(float frameInterval) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t FilamentViewer::addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows) {
|
int32_t FilamentViewer::addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows) {
|
||||||
Log("Adding light of type %d with colour %f intensity %f at (%f, %f, %f) with direction (%f, %f, %f) with shadows %d", t, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, shadows);
|
|
||||||
auto light = EntityManager::get().create();
|
auto light = EntityManager::get().create();
|
||||||
LightManager::Builder(t)
|
LightManager::Builder(t)
|
||||||
.color(Color::cct(colour))
|
.color(Color::cct(colour))
|
||||||
@@ -262,14 +261,22 @@ int32_t FilamentViewer::addLight(LightManager::Type t, float colour, float inten
|
|||||||
.build(*_engine, light);
|
.build(*_engine, light);
|
||||||
_scene->addEntity(light);
|
_scene->addEntity(light);
|
||||||
_lights.push_back(light);
|
_lights.push_back(light);
|
||||||
return Entity::smuggle(light);
|
auto entityId = Entity::smuggle(light);
|
||||||
|
Log("Added light under entity ID %d of type %d with colour %f intensity %f at (%f, %f, %f) with direction (%f, %f, %f) with shadows %d", entityId, t, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, shadows);
|
||||||
|
return entityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::removeLight(int32_t id) {
|
void FilamentViewer::removeLight(EntityId entityId) {
|
||||||
Log("Removing light with entity ID %d", id);
|
Log("Removing light with entity ID %d", entityId);
|
||||||
auto e = utils::Entity::import(id);
|
auto entity = utils::Entity::import(entityId);
|
||||||
_scene->removeEntities(&e, 1);
|
if(entity.isNull()) {
|
||||||
EntityManager::get().destroy(1, &e);
|
Log("Error: light entity not found under ID %d", entityId);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
remove(_lights.begin(), _lights.end(), entity);
|
||||||
|
_scene->remove(entity);
|
||||||
|
EntityManager::get().destroy(1, &entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::clearLights() {
|
void FilamentViewer::clearLights() {
|
||||||
@@ -388,7 +395,6 @@ void FilamentViewer::setBackgroundColor(const float r, const float g, const floa
|
|||||||
_imageMaterial->setDefaultParameter("showImage", 0);
|
_imageMaterial->setDefaultParameter("showImage", 0);
|
||||||
_imageMaterial->setDefaultParameter("backgroundColor", RgbaType::sRGB, float4(r, g, b, a));
|
_imageMaterial->setDefaultParameter("backgroundColor", RgbaType::sRGB, float4(r, g, b, a));
|
||||||
const Viewport& vp = _view->getViewport();
|
const Viewport& vp = _view->getViewport();
|
||||||
Log("Image width %d height %d vp width %d height %d", _imageWidth, _imageHeight, vp.width, vp.height);
|
|
||||||
_imageMaterial->setDefaultParameter("transform", _imageScale);
|
_imageMaterial->setDefaultParameter("transform", _imageScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,9 +528,9 @@ FilamentViewer::~FilamentViewer() {
|
|||||||
|
|
||||||
Renderer *FilamentViewer::getRenderer() { return _renderer; }
|
Renderer *FilamentViewer::getRenderer() { return _renderer; }
|
||||||
|
|
||||||
void FilamentViewer::createSwapChain(void *surface, uint32_t width, uint32_t height) {
|
void FilamentViewer::createSwapChain(const void *surface, uint32_t width, uint32_t height) {
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
_swapChain = _engine->createSwapChain(surface, filament::backend::SWAP_CHAIN_CONFIG_APPLE_CVPIXELBUFFER);
|
_swapChain = _engine->createSwapChain((void*)surface, filament::backend::SWAP_CHAIN_CONFIG_APPLE_CVPIXELBUFFER);
|
||||||
#else
|
#else
|
||||||
if(surface) {
|
if(surface) {
|
||||||
_swapChain = _engine->createSwapChain(surface);
|
_swapChain = _engine->createSwapChain(surface);
|
||||||
|
|||||||
@@ -12,310 +12,158 @@ using namespace polyvox;
|
|||||||
|
|
||||||
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
|
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// static ThreadPool* _tp;
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
#include "PolyvoxFilamentApi.h"
|
#include "PolyvoxFilamentApi.h"
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void* create_filament_viewer(void* context, ResourceLoaderWrapper* loader) {
|
FLUTTER_PLUGIN_EXPORT const void* create_filament_viewer(const void* context, const ResourceLoaderWrapper* const loader) {
|
||||||
// if(!_tp) {
|
|
||||||
// _tp = new ThreadPool();
|
|
||||||
// }
|
|
||||||
// //std::packaged_task<void*()> lambda([=]() mutable {
|
|
||||||
return (void*) new FilamentViewer(context, loader);
|
return (void*) new FilamentViewer(context, loader);
|
||||||
// });
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
// //return fut.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT ResourceLoaderWrapper* make_resource_loader(LoadResourceFromOwner loadFn, FreeResourceFromOwner freeFn, void* const owner) {
|
FLUTTER_PLUGIN_EXPORT ResourceLoaderWrapper* make_resource_loader(LoadResourceFromOwner loadFn, FreeResourceFromOwner freeFn, void* const owner) {
|
||||||
return new ResourceLoaderWrapper(loadFn, freeFn, owner);
|
return new ResourceLoaderWrapper(loadFn, freeFn, owner);
|
||||||
// ResourceLoaderWrapper* lod(loadFn, freeFn, owner);
|
|
||||||
// return &lod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void create_render_target(void* viewer, uint32_t textureId, uint32_t width, uint32_t height) {
|
FLUTTER_PLUGIN_EXPORT void create_render_target(const void* const viewer, uint32_t textureId, uint32_t width, uint32_t height) {
|
||||||
// //std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->createRenderTarget(textureId, width, height);
|
((FilamentViewer*)viewer)->createRenderTarget(textureId, width, height);
|
||||||
// });
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void delete_filament_viewer(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void delete_filament_viewer(const void* const viewer) {
|
||||||
delete((FilamentViewer*)viewer);
|
delete((FilamentViewer*)viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_background_color(void* viewer, const float r, const float g, const float b, const float a) {
|
FLUTTER_PLUGIN_EXPORT void set_background_color(const void* const viewer, const float r, const float g, const float b, const float a) {
|
||||||
// //std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->setBackgroundColor(r, g, b, a);
|
((FilamentViewer*)viewer)->setBackgroundColor(r, g, b, a);
|
||||||
// });
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void clear_background_image(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void clear_background_image(const void* const viewer) {
|
||||||
// //std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->clearBackgroundImage();
|
((FilamentViewer*)viewer)->clearBackgroundImage();
|
||||||
// });
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_background_image(void* viewer, const char* path) {
|
FLUTTER_PLUGIN_EXPORT void set_background_image(const void* const viewer, const char* path) {
|
||||||
// //std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->setBackgroundImage(path);
|
((FilamentViewer*)viewer)->setBackgroundImage(path);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_background_image_position(void* viewer, float x, float y, bool clamp) {
|
FLUTTER_PLUGIN_EXPORT void set_background_image_position(const void* const viewer, float x, float y, bool clamp) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->setBackgroundImagePosition(x, y, clamp);
|
((FilamentViewer*)viewer)->setBackgroundImagePosition(x, y, clamp);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void load_skybox(void* viewer, const char* skyboxPath) {
|
FLUTTER_PLUGIN_EXPORT void load_skybox(const void* const viewer, const char* skyboxPath) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->loadSkybox(skyboxPath);
|
((FilamentViewer*)viewer)->loadSkybox(skyboxPath);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void load_ibl(void* viewer, const char* iblPath, float intensity) {
|
FLUTTER_PLUGIN_EXPORT void load_ibl(const void* const viewer, const char* iblPath, float intensity) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->loadIbl(iblPath, intensity);
|
((FilamentViewer*)viewer)->loadIbl(iblPath, intensity);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void remove_skybox(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void remove_skybox(const void* const viewer) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->removeSkybox();
|
((FilamentViewer*)viewer)->removeSkybox();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void remove_ibl(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void remove_ibl(const void* const viewer) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->removeIbl();
|
((FilamentViewer*)viewer)->removeIbl();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT EntityId add_light(void* viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows) {
|
FLUTTER_PLUGIN_EXPORT EntityId add_light(const void* const viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows) {
|
||||||
//std::packaged_task<EntityId()> lambda([=]() mutable {
|
|
||||||
return ((FilamentViewer*)viewer)->addLight((LightManager::Type)type, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, shadows);
|
return ((FilamentViewer*)viewer)->addLight((LightManager::Type)type, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, shadows);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
//return fut.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void remove_light(void* viewer, int32_t entityId) {
|
FLUTTER_PLUGIN_EXPORT void remove_light(const void* const viewer, int32_t entityId) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->removeLight(entityId);
|
((FilamentViewer*)viewer)->removeLight(entityId);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void clear_lights(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void clear_lights(const void* const viewer) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->clearLights();
|
((FilamentViewer*)viewer)->clearLights();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT EntityId load_glb(void* assetManager, const char* assetPath, bool unlit) {
|
FLUTTER_PLUGIN_EXPORT EntityId load_glb(void* assetManager, const char* assetPath, bool unlit) {
|
||||||
//std::packaged_task<EntityId()> lambda([=]() mutable {
|
|
||||||
return ((AssetManager*)assetManager)->loadGlb(assetPath, unlit);
|
return ((AssetManager*)assetManager)->loadGlb(assetPath, unlit);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
//return fut.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT EntityId load_gltf(void* assetManager, const char* assetPath, const char* relativePath) {
|
FLUTTER_PLUGIN_EXPORT EntityId load_gltf(void* assetManager, const char* assetPath, const char* relativePath) {
|
||||||
//std::packaged_task<EntityId()> lambda([=]() mutable {
|
|
||||||
return ((AssetManager*)assetManager)->loadGltf(assetPath, relativePath);
|
return ((AssetManager*)assetManager)->loadGltf(assetPath, relativePath);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
//return fut.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT bool set_camera(void* viewer, EntityId asset, const char* nodeName) {
|
FLUTTER_PLUGIN_EXPORT bool set_camera(const void* const viewer, EntityId asset, const char* nodeName) {
|
||||||
//std::packaged_task<bool()> lambda([=]() mutable {
|
|
||||||
return ((FilamentViewer*)viewer)->setCamera(asset, nodeName);
|
return ((FilamentViewer*)viewer)->setCamera(asset, nodeName);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
//return fut.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_camera_exposure(void* viewer, float aperture, float shutterSpeed, float sensitivity) {
|
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float distance) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
((FilamentViewer*)viewer)->setCameraFocusDistance(distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
FLUTTER_PLUGIN_EXPORT void set_camera_exposure(const void* const viewer, float aperture, float shutterSpeed, float sensitivity) {
|
||||||
((FilamentViewer*)viewer)->setCameraExposure(aperture, shutterSpeed, sensitivity);
|
((FilamentViewer*)viewer)->setCameraExposure(aperture, shutterSpeed, sensitivity);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_camera_position(void* viewer, float x, float y, float z) {
|
FLUTTER_PLUGIN_EXPORT void set_camera_position(const void* const viewer, float x, float y, float z) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->setCameraPosition(x, y, z);
|
((FilamentViewer*)viewer)->setCameraPosition(x, y, z);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_camera_rotation(void* viewer, float rads, float x, float y, float z) {
|
FLUTTER_PLUGIN_EXPORT void set_camera_rotation(const void* const viewer, float rads, float x, float y, float z) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
|
((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(void* viewer, const float* const matrix) {
|
FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void* const viewer, const float* const matrix) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->setCameraModelMatrix(matrix);
|
((FilamentViewer*)viewer)->setCameraModelMatrix(matrix);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_camera_focal_length(void* viewer, float focalLength) {
|
FLUTTER_PLUGIN_EXPORT void set_camera_focal_length(const void* const viewer, float focalLength) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->setCameraFocalLength(focalLength);
|
((FilamentViewer*)viewer)->setCameraFocalLength(focalLength);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void render(
|
FLUTTER_PLUGIN_EXPORT void render(
|
||||||
void* viewer,
|
const void* const viewer,
|
||||||
uint64_t frameTimeInNanos
|
uint64_t frameTimeInNanos
|
||||||
) {
|
) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->render(frameTimeInNanos);
|
((FilamentViewer*)viewer)->render(frameTimeInNanos);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_frame_interval(
|
FLUTTER_PLUGIN_EXPORT void set_frame_interval(
|
||||||
void* viewer,
|
const void* const viewer,
|
||||||
float frameInterval
|
float frameInterval
|
||||||
) {
|
) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->setFrameInterval(frameInterval);
|
((FilamentViewer*)viewer)->setFrameInterval(frameInterval);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain(const void* const viewer) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->destroySwapChain();
|
((FilamentViewer*)viewer)->destroySwapChain();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain(void* viewer, void* surface=nullptr, uint32_t width=0, uint32_t height=0) {
|
FLUTTER_PLUGIN_EXPORT void create_swap_chain(const void* const viewer, const void* const surface=nullptr, uint32_t width=0, uint32_t height=0) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->createSwapChain(surface, width, height);
|
((FilamentViewer*)viewer)->createSwapChain(surface, width, height);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void* get_renderer(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection(const void* const viewer, int width, int height, float scaleFactor) {
|
||||||
//std::packaged_task<void*()> lambda([=]() mutable {
|
|
||||||
return ((FilamentViewer*)viewer)->getRenderer();
|
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
//return fut.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection(void* viewer, int width, int height, float scaleFactor) {
|
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
return ((FilamentViewer*)viewer)->updateViewportAndCameraProjection(width, height, scaleFactor);
|
return ((FilamentViewer*)viewer)->updateViewportAndCameraProjection(width, height, scaleFactor);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void scroll_update(void* viewer, float x, float y, float delta) {
|
FLUTTER_PLUGIN_EXPORT void scroll_update(const void* const viewer, float x, float y, float delta) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->scrollUpdate(x, y, delta);
|
((FilamentViewer*)viewer)->scrollUpdate(x, y, delta);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void scroll_begin(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void scroll_begin(const void* const viewer) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->scrollBegin();
|
((FilamentViewer*)viewer)->scrollBegin();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void scroll_end(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void scroll_end(const void* const viewer) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->scrollEnd();
|
((FilamentViewer*)viewer)->scrollEnd();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void grab_begin(void* viewer, float x, float y, bool pan) {
|
FLUTTER_PLUGIN_EXPORT void grab_begin(const void* const viewer, float x, float y, bool pan) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->grabBegin(x, y, pan);
|
((FilamentViewer*)viewer)->grabBegin(x, y, pan);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void grab_update(void* viewer, float x, float y) {
|
FLUTTER_PLUGIN_EXPORT void grab_update(const void* const viewer, float x, float y) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->grabUpdate(x, y);
|
((FilamentViewer*)viewer)->grabUpdate(x, y);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void grab_end(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void grab_end(const void* const viewer) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->grabEnd();
|
((FilamentViewer*)viewer)->grabEnd();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void* get_asset_manager(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void* get_asset_manager(const void* const viewer) {
|
||||||
//std::packaged_task<void*()> lambda([=]() mutable {
|
|
||||||
return (void*)((FilamentViewer*)viewer)->getAssetManager();
|
return (void*)((FilamentViewer*)viewer)->getAssetManager();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
//return fut.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void apply_weights(
|
FLUTTER_PLUGIN_EXPORT void apply_weights(
|
||||||
@@ -324,11 +172,7 @@ extern "C" {
|
|||||||
const char* const entityName,
|
const char* const entityName,
|
||||||
float* const weights,
|
float* const weights,
|
||||||
int count) {
|
int count) {
|
||||||
// //std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
// ((AssetManager*)assetManager)->setMorphTargetWeights(asset, entityName, weights, count);
|
// ((AssetManager*)assetManager)->setMorphTargetWeights(asset, entityName, weights, count);
|
||||||
// });
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights(
|
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights(
|
||||||
@@ -339,16 +183,12 @@ extern "C" {
|
|||||||
const int numWeights
|
const int numWeights
|
||||||
) {
|
) {
|
||||||
|
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
return ((AssetManager*)assetManager)->setMorphTargetWeights(
|
return ((AssetManager*)assetManager)->setMorphTargetWeights(
|
||||||
asset,
|
asset,
|
||||||
entityName,
|
entityName,
|
||||||
weights,
|
weights,
|
||||||
numWeights
|
numWeights
|
||||||
);
|
);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT bool set_morph_animation(
|
FLUTTER_PLUGIN_EXPORT bool set_morph_animation(
|
||||||
@@ -360,7 +200,6 @@ extern "C" {
|
|||||||
int numFrames,
|
int numFrames,
|
||||||
float frameLengthInMs) {
|
float frameLengthInMs) {
|
||||||
|
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
return ((AssetManager*)assetManager)->setMorphAnimationBuffer(
|
return ((AssetManager*)assetManager)->setMorphAnimationBuffer(
|
||||||
asset,
|
asset,
|
||||||
entityName,
|
entityName,
|
||||||
@@ -369,9 +208,6 @@ extern "C" {
|
|||||||
numFrames,
|
numFrames,
|
||||||
frameLengthInMs
|
frameLengthInMs
|
||||||
);
|
);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_bone_animation(
|
FLUTTER_PLUGIN_EXPORT void set_bone_animation(
|
||||||
@@ -384,7 +220,6 @@ extern "C" {
|
|||||||
const char** const meshNames,
|
const char** const meshNames,
|
||||||
int numMeshTargets,
|
int numMeshTargets,
|
||||||
float frameLengthInMs) {
|
float frameLengthInMs) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((AssetManager*)assetManager)->setBoneAnimationBuffer(
|
((AssetManager*)assetManager)->setBoneAnimationBuffer(
|
||||||
asset,
|
asset,
|
||||||
frameData,
|
frameData,
|
||||||
@@ -395,10 +230,7 @@ extern "C" {
|
|||||||
numMeshTargets,
|
numMeshTargets,
|
||||||
frameLengthInMs
|
frameLengthInMs
|
||||||
);
|
);
|
||||||
//});
|
}
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -435,13 +267,9 @@ extern "C" {
|
|||||||
EntityId asset,
|
EntityId asset,
|
||||||
int index,
|
int index,
|
||||||
bool loop,
|
bool loop,
|
||||||
bool reverse) {
|
bool reverse,
|
||||||
|
float crossfade) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
((AssetManager*)assetManager)->playAnimation(asset, index, loop, reverse, crossfade);
|
||||||
((AssetManager*)assetManager)->playAnimation(asset, index, loop, reverse);
|
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_animation_frame(
|
FLUTTER_PLUGIN_EXPORT void set_animation_frame(
|
||||||
@@ -449,11 +277,7 @@ extern "C" {
|
|||||||
EntityId asset,
|
EntityId asset,
|
||||||
int animationIndex,
|
int animationIndex,
|
||||||
int animationFrame) {
|
int animationFrame) {
|
||||||
// //std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
// ((AssetManager*)assetManager)->setAnimationFrame(asset, animationIndex, animationFrame);
|
// ((AssetManager*)assetManager)->setAnimationFrame(asset, animationIndex, animationFrame);
|
||||||
// });
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT int get_animation_count(
|
FLUTTER_PLUGIN_EXPORT int get_animation_count(
|
||||||
@@ -462,9 +286,8 @@ extern "C" {
|
|||||||
//std::packaged_task<int()> lambda([=]() mutable {
|
//std::packaged_task<int()> lambda([=]() mutable {
|
||||||
auto names = ((AssetManager*)assetManager)->getAnimationNames(asset);
|
auto names = ((AssetManager*)assetManager)->getAnimationNames(asset);
|
||||||
return names->size();
|
return names->size();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
//return fut.get();
|
//return fut.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,49 +297,32 @@ extern "C" {
|
|||||||
char* const outPtr,
|
char* const outPtr,
|
||||||
int index
|
int index
|
||||||
) {
|
) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
auto names = ((AssetManager*)assetManager)->getAnimationNames(asset);
|
auto names = ((AssetManager*)assetManager)->getAnimationNames(asset);
|
||||||
string name = names->at(index);
|
string name = names->at(index);
|
||||||
strcpy(outPtr, name.c_str());
|
strcpy(outPtr, name.c_str());
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count(void* assetManager, EntityId asset, const char* meshName) {
|
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count(void* assetManager, EntityId asset, const char* meshName) {
|
||||||
//std::packaged_task<int()> lambda([=]() mutable {
|
//std::packaged_task<int()> lambda([=]() mutable {
|
||||||
unique_ptr<vector<string>> names = ((AssetManager*)assetManager)->getMorphTargetNames(asset, meshName);
|
unique_ptr<vector<string>> names = ((AssetManager*)assetManager)->getMorphTargetNames(asset, meshName);
|
||||||
return names->size();
|
return names->size();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
//return fut.get();
|
//return fut.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void get_morph_target_name(void* assetManager, EntityId asset, const char* meshName, char* const outPtr, int index ) {
|
FLUTTER_PLUGIN_EXPORT void get_morph_target_name(void* assetManager, EntityId asset, const char* meshName, char* const outPtr, int index ) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
unique_ptr<vector<string>> names = ((AssetManager*)assetManager)->getMorphTargetNames(asset, meshName);
|
unique_ptr<vector<string>> names = ((AssetManager*)assetManager)->getMorphTargetNames(asset, meshName);
|
||||||
string name = names->at(index);
|
string name = names->at(index);
|
||||||
strcpy(outPtr, name.c_str());
|
strcpy(outPtr, name.c_str());
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void remove_asset(void* viewer, EntityId asset) {
|
FLUTTER_PLUGIN_EXPORT void remove_asset(const void* const viewer, EntityId asset) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->removeAsset(asset);
|
((FilamentViewer*)viewer)->removeAsset(asset);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void clear_assets(void* viewer) {
|
FLUTTER_PLUGIN_EXPORT void clear_assets(const void* const viewer) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((FilamentViewer*)viewer)->clearAssets();
|
((FilamentViewer*)viewer)->clearAssets();
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void load_texture(void* assetManager, EntityId asset, const char* assetPath, int renderableIndex) {
|
FLUTTER_PLUGIN_EXPORT void load_texture(void* assetManager, EntityId asset, const char* assetPath, int renderableIndex) {
|
||||||
@@ -528,59 +334,31 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void* assetManager, EntityId asset) {
|
FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void* assetManager, EntityId asset) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((AssetManager*)assetManager)->transformToUnitCube(asset);
|
((AssetManager*)assetManager)->transformToUnitCube(asset);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_position(void* assetManager, EntityId asset, float x, float y, float z) {
|
FLUTTER_PLUGIN_EXPORT void set_position(void* assetManager, EntityId asset, float x, float y, float z) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((AssetManager*)assetManager)->setPosition(asset, x, y, z);
|
((AssetManager*)assetManager)->setPosition(asset, x, y, z);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z) {
|
FLUTTER_PLUGIN_EXPORT void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((AssetManager*)assetManager)->setRotation(asset, rads, x, y, z);
|
((AssetManager*)assetManager)->setRotation(asset, rads, x, y, z);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_scale(void* assetManager, EntityId asset, float scale) {
|
FLUTTER_PLUGIN_EXPORT void set_scale(void* assetManager, EntityId asset, float scale) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((AssetManager*)assetManager)->setScale(asset, scale);
|
((AssetManager*)assetManager)->setScale(asset, scale);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void stop_animation(void* assetManager, EntityId asset, int index) {
|
FLUTTER_PLUGIN_EXPORT void stop_animation(void* assetManager, EntityId asset, int index) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
((AssetManager*)assetManager)->stopAnimation(asset, index);
|
((AssetManager*)assetManager)->stopAnimation(asset, index);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
return ((AssetManager*)assetManager)->hide(asset, meshName);
|
return ((AssetManager*)assetManager)->hide(asset, meshName);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT int reveal_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
FLUTTER_PLUGIN_EXPORT int reveal_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
||||||
//std::packaged_task<void()> lambda([=]() mutable {
|
|
||||||
return ((AssetManager*)assetManager)->reveal(asset, meshName);
|
return ((AssetManager*)assetManager)->reveal(asset, meshName);
|
||||||
//});
|
|
||||||
// auto fut = _tp->add_task(lambda);
|
|
||||||
// fut.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void ios_dummy() {
|
FLUTTER_PLUGIN_EXPORT void ios_dummy() {
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ class AnimationBuilder {
|
|||||||
required this.meshName,
|
required this.meshName,
|
||||||
required int framerate}) {
|
required int framerate}) {
|
||||||
_frameLengthInMs = 1000 / framerate;
|
_frameLengthInMs = 1000 / framerate;
|
||||||
morphNames = controller.getMorphTargetNames(asset, meshName);
|
controller.getMorphTargetNames(asset, meshName).then((value) {
|
||||||
|
morphNames = value;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void set() {
|
void set() {
|
||||||
|
|||||||
@@ -1,20 +1,15 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:isolate';
|
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:flutter/animation.dart';
|
|
||||||
import 'package:flutter/scheduler.dart';
|
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:polyvox_filament/animations/bone_animation_data.dart';
|
import 'package:polyvox_filament/animations/bone_animation_data.dart';
|
||||||
import 'package:polyvox_filament/animations/morph_animation_data.dart';
|
import 'package:polyvox_filament/animations/morph_animation_data.dart';
|
||||||
import 'package:polyvox_filament/generated_bindings.dart';
|
|
||||||
|
|
||||||
typedef AssetManager = Pointer<Void>;
|
typedef AssetManager = int;
|
||||||
typedef FilamentViewer = Pointer<Void>;
|
|
||||||
typedef FilamentEntity = int;
|
typedef FilamentEntity = int;
|
||||||
const FilamentEntity FILAMENT_ASSET_ERROR = 0;
|
const FilamentEntity FILAMENT_ASSET_ERROR = 0;
|
||||||
|
|
||||||
@@ -34,23 +29,13 @@ class FilamentController {
|
|||||||
final _initialized = Completer();
|
final _initialized = Completer();
|
||||||
Future get initialized => _initialized.future;
|
Future get initialized => _initialized.future;
|
||||||
|
|
||||||
late NativeLibrary _nativeLibrary;
|
|
||||||
|
|
||||||
late FilamentViewer _viewer;
|
|
||||||
late AssetManager _assetManager;
|
late AssetManager _assetManager;
|
||||||
|
|
||||||
bool _rendering = false;
|
|
||||||
|
|
||||||
final TickerProvider _tickerProvider;
|
|
||||||
Ticker? _ticker;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// This now uses an FFI implementation.
|
/// This controller uses platform channels to bridge Dart with the C/C++ code for the Filament API.
|
||||||
/// Platform channels are only used to setup the context/texture (since this is platform-specific) and the render ticker.
|
/// Setting up the context/texture (since this is platform-specific) and the render ticker are platform-specific; all other methods are passed through by the platform channel to the methods specified in PolyvoxFilamentApi.h.
|
||||||
/// All other methods directly invoke the FFI functions defined in PolyvoxFilamentApi.cpp,
|
|
||||||
/// which itself uses a threadpool so that calls are run on a separate thread.
|
|
||||||
///
|
///
|
||||||
FilamentController(this._tickerProvider) {
|
FilamentController() {
|
||||||
_channel.setMethodCallHandler((call) async {
|
_channel.setMethodCallHandler((call) async {
|
||||||
throw Exception("Unknown method channel invocation ${call.method}");
|
throw Exception("Unknown method channel invocation ${call.method}");
|
||||||
});
|
});
|
||||||
@@ -58,10 +43,6 @@ class FilamentController {
|
|||||||
_textureIdController.onListen = () {
|
_textureIdController.onListen = () {
|
||||||
_textureIdController.add(_textureId);
|
_textureIdController.add(_textureId);
|
||||||
};
|
};
|
||||||
|
|
||||||
_nativeLibrary = NativeLibrary(Platform.isAndroid || Platform.isLinux
|
|
||||||
? DynamicLibrary.open("libpolyvox_filament_plugin.so")
|
|
||||||
: DynamicLibrary.process());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future initialize() async {
|
Future initialize() async {
|
||||||
@@ -70,126 +51,106 @@ class FilamentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future setRendering(bool render) async {
|
Future setRendering(bool render) async {
|
||||||
_rendering = render;
|
_channel.invokeMethod("setRendering", render);
|
||||||
}
|
}
|
||||||
|
|
||||||
void render() {
|
void render() {
|
||||||
_nativeLibrary.render(_viewer, 0);
|
_channel.invokeMethod("render");
|
||||||
}
|
}
|
||||||
|
|
||||||
int _frameLengthInMicroseconds = 1000000 ~/ 60;
|
|
||||||
|
|
||||||
Future setFrameRate(int framerate) async {
|
Future setFrameRate(int framerate) async {
|
||||||
_frameLengthInMicroseconds = 1000000 ~/ framerate;
|
_channel.invokeMethod("setFrameInterval", 1000.0 / framerate);
|
||||||
_nativeLibrary.set_frame_interval(_viewer, 1 / framerate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPixelRatio(double ratio) {
|
void setPixelRatio(double ratio) {
|
||||||
_pixelRatio = ratio;
|
_pixelRatio = ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _last = 0;
|
|
||||||
|
|
||||||
Future createViewer(int width, int height) async {
|
Future createViewer(int width, int height) async {
|
||||||
size = ui.Size(width * _pixelRatio, height * _pixelRatio);
|
size = ui.Size(width * _pixelRatio, height * _pixelRatio);
|
||||||
_textureId =
|
_textureId =
|
||||||
await _channel.invokeMethod("createTexture", [size.width, size.height]);
|
await _channel.invokeMethod("createTexture", [size.width, size.height]);
|
||||||
_textureIdController.add(_textureId);
|
_textureIdController.add(_textureId);
|
||||||
|
|
||||||
var glContext =
|
await _channel
|
||||||
Pointer<Void>.fromAddress(await _channel.invokeMethod("getContext"));
|
.invokeMethod("createFilamentViewer", [size.width, size.height]);
|
||||||
final resourceLoader = Pointer<ResourceLoaderWrapper>.fromAddress(
|
|
||||||
await _channel.invokeMethod("getResourceLoader"));
|
|
||||||
|
|
||||||
_viewer = _nativeLibrary.create_filament_viewer(glContext, resourceLoader);
|
// if (Platform.isLinux) {
|
||||||
if (Platform.isLinux) {
|
// // don't pass a surface to the SwapChain as we are effectively creating a headless SwapChain that will render into a RenderTarget associated with a texture
|
||||||
// don't pass a surface to the SwapChain as we are effectively creating a headless SwapChain that will render into a RenderTarget associated with a texture
|
// _nativeLibrary.create_swap_chain(
|
||||||
_nativeLibrary.create_swap_chain(
|
// nullptr, size.width.toInt(), size.height.toInt());
|
||||||
_viewer, nullptr, size.width.toInt(), size.height.toInt());
|
|
||||||
|
|
||||||
var glTextureId = await _channel.invokeMethod("getGlTextureId");
|
// var glTextureId = await _channel.invokeMethod("getGlTextureId");
|
||||||
|
|
||||||
_nativeLibrary.create_render_target(
|
// await _channel.invokeMethod("create_render_target(
|
||||||
_viewer, glTextureId, size.width.toInt(), size.height.toInt());
|
// glTextureId, size.width.toInt(), size.height.toInt());
|
||||||
} else {
|
// } else {
|
||||||
var surface =
|
|
||||||
Pointer<Void>.fromAddress(await _channel.invokeMethod("getSurface"));
|
|
||||||
_nativeLibrary.create_swap_chain(
|
|
||||||
_viewer, surface, size.width.toInt(), size.height.toInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
_nativeLibrary.update_viewport_and_camera_projection(
|
// }
|
||||||
_viewer, size.width.toInt(), size.height.toInt(), 1.0);
|
|
||||||
|
await _channel.invokeMethod("updateViewportAndCameraProjection",
|
||||||
|
[size.width.toInt(), size.height.toInt(), 1.0]);
|
||||||
|
|
||||||
_initialized.complete(true);
|
_initialized.complete(true);
|
||||||
_assetManager = _nativeLibrary.get_asset_manager(_viewer);
|
_assetManager = await _channel.invokeMethod("getAssetManager");
|
||||||
|
|
||||||
_ticker = _tickerProvider.createTicker((Duration elapsed) async {
|
|
||||||
if (elapsed.inMicroseconds - _last > _frameLengthInMicroseconds) {
|
|
||||||
render();
|
|
||||||
_last = elapsed.inMicroseconds;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
_ticker!.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future resize(int width, int height,
|
Future resize(int width, int height,
|
||||||
{double contentScaleFactor = 1.0}) async {
|
{double contentScaleFactor = 1.0}) async {
|
||||||
// await setRendering(false);
|
// await setRendering(false);
|
||||||
// _textureIdController.add(null);
|
// _textureIdController.add(null);
|
||||||
// _nativeLibrary.destroy_swap_chain(_viewer);
|
// await _channel.invokeMethod("destroy_swap_chain(_viewer);
|
||||||
// size = ui.Size(width * _pixelRatio, height * _pixelRatio);
|
// size = ui.Size(width * _pixelRatio, height * _pixelRatio);
|
||||||
|
|
||||||
// _textureId = await _channel.invokeMethod("resize",
|
// _textureId = await _channel.invokeMethod("resize",
|
||||||
// [width * _pixelRatio, height * _pixelRatio, contentScaleFactor]);
|
// [width * _pixelRatio, height * _pixelRatio, contentScaleFactor]);
|
||||||
|
|
||||||
// _textureIdController.add(_textureId);
|
// _textureIdController.add(_textureId);
|
||||||
// _nativeLibrary.create_swap_chain(_viewer, nullptr, width, height);
|
// await _channel.invokeMethod("create_swap_chain( nullptr, width, height);
|
||||||
// _nativeLibrary.create_render_target(
|
// await _channel.invokeMethod("create_render_target(
|
||||||
// _viewer, await _channel.invokeMethod("getGlTextureId"), width, height);
|
// await _channel.invokeMethod("getGlTextureId"), width, height);
|
||||||
// _nativeLibrary.update_viewport_and_camera_projection(
|
// await _channel.invokeMethod("update_viewport_and_camera_projection(
|
||||||
// _viewer, width, height, contentScaleFactor);
|
// width, height, contentScaleFactor);
|
||||||
// await setRendering(true);
|
// await setRendering(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearBackgroundImage() async {
|
void clearBackgroundImage() async {
|
||||||
_nativeLibrary.clear_background_image(_viewer);
|
await _channel.invokeMethod("clearBackgroundImage");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBackgroundImage(String path) async {
|
void setBackgroundImage(String path) async {
|
||||||
_nativeLibrary.set_background_image(
|
await _channel.invokeMethod("setBackgroundImage", path);
|
||||||
_viewer, path.toNativeUtf8().cast<Char>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBackgroundColor(Color color) async {
|
void setBackgroundColor(Color color) async {
|
||||||
_nativeLibrary.set_background_color(
|
await _channel.invokeMethod("setBackgroundColor", [
|
||||||
_viewer,
|
color.red.toDouble() / 255.0,
|
||||||
color.red.toDouble() / 255.0,
|
color.green.toDouble() / 255.0,
|
||||||
color.green.toDouble() / 255.0,
|
color.blue.toDouble() / 255.0,
|
||||||
color.blue.toDouble() / 255.0,
|
color.alpha.toDouble() / 255.0
|
||||||
color.alpha.toDouble() / 255.0);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBackgroundImagePosition(double x, double y,
|
void setBackgroundImagePosition(double x, double y,
|
||||||
{bool clamp = false}) async {
|
{bool clamp = false}) async {
|
||||||
_nativeLibrary.set_background_image_position(_viewer, x, y, clamp ? 1 : 0);
|
await _channel
|
||||||
|
.invokeMethod("setBackgroundImagePosition", [x, y, clamp ? 1 : 0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadSkybox(String skyboxPath) async {
|
void loadSkybox(String skyboxPath) async {
|
||||||
_nativeLibrary.load_skybox(_viewer, skyboxPath.toNativeUtf8().cast<Char>());
|
await _channel.invokeMethod("loadSkybox", skyboxPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadIbl(String lightingPath, {double intensity = 30000}) async {
|
void loadIbl(String lightingPath, {double intensity = 30000}) async {
|
||||||
_nativeLibrary.load_ibl(
|
await _channel.invokeMethod("loadIbl", [lightingPath, intensity]);
|
||||||
_viewer, lightingPath.toNativeUtf8().cast<Char>(), intensity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeSkybox() async {
|
void removeSkybox() async {
|
||||||
_nativeLibrary.remove_skybox(_viewer);
|
await _channel.invokeMethod("removeSkybox");
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeIbl() async {
|
void removeIbl() async {
|
||||||
_nativeLibrary.remove_ibl(_viewer);
|
await _channel.invokeMethod("removeIbl");
|
||||||
}
|
}
|
||||||
|
|
||||||
// copied from LightManager.h
|
// copied from LightManager.h
|
||||||
@@ -200,8 +161,7 @@ class FilamentController {
|
|||||||
// FOCUSED_SPOT, //!< Physically correct spot light.
|
// FOCUSED_SPOT, //!< Physically correct spot light.
|
||||||
// SPOT, //!< Spot light with coupling of outer cone and illumination disabled.
|
// SPOT, //!< Spot light with coupling of outer cone and illumination disabled.
|
||||||
// };
|
// };
|
||||||
|
Future<FilamentEntity> addLight(
|
||||||
FilamentEntity addLight(
|
|
||||||
int type,
|
int type,
|
||||||
double colour,
|
double colour,
|
||||||
double intensity,
|
double intensity,
|
||||||
@@ -211,94 +171,97 @@ class FilamentController {
|
|||||||
double dirX,
|
double dirX,
|
||||||
double dirY,
|
double dirY,
|
||||||
double dirZ,
|
double dirZ,
|
||||||
bool castShadows) {
|
bool castShadows) async {
|
||||||
return _nativeLibrary.add_light(_viewer, type, colour, intensity, posX,
|
var entity = await _channel.invokeMethod("addLight", [
|
||||||
posY, posZ, dirX, dirY, dirZ, castShadows ? 1 : 0);
|
type,
|
||||||
|
colour,
|
||||||
|
intensity,
|
||||||
|
posX,
|
||||||
|
posY,
|
||||||
|
posZ,
|
||||||
|
dirX,
|
||||||
|
dirY,
|
||||||
|
dirZ,
|
||||||
|
castShadows ? 1 : 0
|
||||||
|
]);
|
||||||
|
return entity as FilamentEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeLight(FilamentEntity light) async {
|
void removeLight(FilamentEntity light) async {
|
||||||
_nativeLibrary.remove_light(_viewer, light);
|
await _channel.invokeMethod("removeLight", light);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearLights() async {
|
void clearLights() async {
|
||||||
_nativeLibrary.clear_lights(_viewer);
|
await _channel.invokeMethod("clearLights");
|
||||||
}
|
}
|
||||||
|
|
||||||
FilamentEntity loadGlb(String path, {bool unlit = false}) {
|
Future<FilamentEntity> loadGlb(String path, {bool unlit = false}) async {
|
||||||
var asset = _nativeLibrary.load_glb(
|
var asset = await _channel
|
||||||
_assetManager, path.toNativeUtf8().cast<Char>(), unlit ? 1 : 0);
|
.invokeMethod("loadGlb", [_assetManager, path, unlit ? 1 : 0]);
|
||||||
if (asset == FILAMENT_ASSET_ERROR) {
|
if (asset == FILAMENT_ASSET_ERROR) {
|
||||||
throw Exception("An error occurred loading the asset at $path");
|
throw Exception("An error occurred loading the asset at $path");
|
||||||
}
|
}
|
||||||
return asset;
|
return asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilamentEntity loadGltf(String path, String relativeResourcePath) {
|
Future<FilamentEntity> loadGltf(
|
||||||
return _nativeLibrary.load_gltf(
|
String path, String relativeResourcePath) async {
|
||||||
_assetManager,
|
var entity = await _channel
|
||||||
path.toNativeUtf8().cast<Char>(),
|
.invokeMethod("loadGltf", [_assetManager, path, relativeResourcePath]);
|
||||||
relativeResourcePath.toNativeUtf8().cast<Char>());
|
return entity as FilamentEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void panStart(double x, double y) async {
|
void panStart(double x, double y) async {
|
||||||
_nativeLibrary.grab_begin(_viewer, x * _pixelRatio, y * _pixelRatio, 1);
|
await _channel
|
||||||
|
.invokeMethod("grabBegin", [x * _pixelRatio, y * _pixelRatio, 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void panUpdate(double x, double y) async {
|
void panUpdate(double x, double y) async {
|
||||||
_nativeLibrary.grab_update(_viewer, x * _pixelRatio, y * _pixelRatio);
|
await _channel
|
||||||
|
.invokeMethod("grabUpdate", [x * _pixelRatio, y * _pixelRatio]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void panEnd() async {
|
void panEnd() async {
|
||||||
_nativeLibrary.grab_end(_viewer);
|
await _channel.invokeMethod("grabEnd");
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotateStart(double x, double y) async {
|
void rotateStart(double x, double y) async {
|
||||||
_nativeLibrary.grab_begin(_viewer, x * _pixelRatio, y * _pixelRatio, 0);
|
await _channel
|
||||||
|
.invokeMethod("grabBegin", [x * _pixelRatio, y * _pixelRatio, 0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotateUpdate(double x, double y) async {
|
void rotateUpdate(double x, double y) async {
|
||||||
_nativeLibrary.grab_update(_viewer, x * _pixelRatio, y * _pixelRatio);
|
await _channel
|
||||||
|
.invokeMethod("grabUpdate", [x * _pixelRatio, y * _pixelRatio]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotateEnd() async {
|
void rotateEnd() async {
|
||||||
_nativeLibrary.grab_end(_viewer);
|
await _channel.invokeMethod("grabEnd");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMorphTargetWeights(
|
void setMorphTargetWeights(
|
||||||
FilamentEntity asset, String meshName, List<double> weights) {
|
FilamentEntity asset, String meshName, List<double> weights) async {
|
||||||
var weightPtr = calloc<Float>(weights.length);
|
var weightPtr = calloc<Float>(weights.length);
|
||||||
for (int i = 0; i < weights.length; i++) {
|
for (int i = 0; i < weights.length; i++) {
|
||||||
weightPtr[i] = weights[i];
|
weightPtr[i] = weights[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
_nativeLibrary.set_morph_target_weights(_assetManager, asset,
|
await _channel.invokeMethod("setMorphTargetWeights",
|
||||||
meshName.toNativeUtf8().cast<Char>(), weightPtr, weights.length);
|
[_assetManager, asset, meshName, weightPtr, weights.length]);
|
||||||
calloc.free(weightPtr);
|
calloc.free(weightPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> getMorphTargetNames(FilamentEntity asset, String meshName) {
|
Future<List<String>> getMorphTargetNames(
|
||||||
var meshNamePtr = meshName.toNativeUtf8().cast<Char>();
|
FilamentEntity asset, String meshName) async {
|
||||||
var count = _nativeLibrary.get_morph_target_name_count(
|
var names = await _channel
|
||||||
_assetManager, asset, meshNamePtr);
|
.invokeMethod("getMorphTargetNames", [_assetManager, asset, meshName]);
|
||||||
var names = <String>[];
|
return names.cast<String>();
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
var outPtr = calloc<Char>(255);
|
|
||||||
_nativeLibrary.get_morph_target_name(
|
|
||||||
_assetManager, asset, meshNamePtr, outPtr, i);
|
|
||||||
names.add(outPtr.cast<Utf8>().toDartString());
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> getAnimationNames(FilamentEntity asset) {
|
Future<List<String>> getAnimationNames(FilamentEntity asset) async {
|
||||||
var count = _nativeLibrary.get_animation_count(_assetManager, asset);
|
var names = await _channel
|
||||||
var names = <String>[];
|
.invokeMethod("getAnimationNames", [_assetManager, asset]);
|
||||||
for (int i = 0; i < count; i++) {
|
return names.cast<String>();
|
||||||
var outPtr = calloc<Char>(255);
|
|
||||||
_nativeLibrary.get_animation_name(_assetManager, asset, outPtr, i);
|
|
||||||
names.add(outPtr.cast<Utf8>().toDartString());
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -312,14 +275,15 @@ class FilamentController {
|
|||||||
for (int i = 0; i < animation.data.length; i++) {
|
for (int i = 0; i < animation.data.length; i++) {
|
||||||
data.elementAt(i).value = animation.data[i];
|
data.elementAt(i).value = animation.data[i];
|
||||||
}
|
}
|
||||||
_nativeLibrary.set_morph_animation(
|
await _channel.invokeMethod("setMorphAnimation", [
|
||||||
_assetManager,
|
_assetManager,
|
||||||
asset,
|
asset,
|
||||||
animation.meshName.toNativeUtf8().cast<Char>(),
|
animation.meshName,
|
||||||
data,
|
data,
|
||||||
animation.numMorphWeights,
|
animation.numMorphWeights,
|
||||||
animation.numFrames,
|
animation.numFrames,
|
||||||
animation.frameLengthInMs);
|
animation.frameLengthInMs
|
||||||
|
]);
|
||||||
calloc.free(data);
|
calloc.free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,84 +313,89 @@ class FilamentController {
|
|||||||
offset += 1;
|
offset += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_nativeLibrary.set_bone_animation(
|
await _channel.invokeMethod("setBoneAnimation", [
|
||||||
_assetManager,
|
_assetManager,
|
||||||
asset,
|
asset,
|
||||||
data,
|
data,
|
||||||
numFrames,
|
numFrames,
|
||||||
1,
|
1,
|
||||||
boneNames,
|
boneNames,
|
||||||
meshNames,
|
meshNames,
|
||||||
animation.meshNames.length,
|
animation.meshNames.length,
|
||||||
animation.frameLengthInMs);
|
animation.frameLengthInMs
|
||||||
|
]);
|
||||||
calloc.free(data);
|
calloc.free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeAsset(FilamentEntity asset) async {
|
void removeAsset(FilamentEntity asset) async {
|
||||||
_nativeLibrary.remove_asset(_viewer, asset);
|
await _channel.invokeMethod("removeAsset", asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearAssets() async {
|
void clearAssets() async {
|
||||||
_nativeLibrary.clear_assets(_viewer);
|
await _channel.invokeMethod("clearAssets");
|
||||||
}
|
}
|
||||||
|
|
||||||
void zoomBegin() async {
|
void zoomBegin() async {
|
||||||
_nativeLibrary.scroll_begin(_viewer);
|
await _channel.invokeMethod("scrollBegin");
|
||||||
}
|
}
|
||||||
|
|
||||||
void zoomUpdate(double z) async {
|
void zoomUpdate(double z) async {
|
||||||
_nativeLibrary.scroll_update(_viewer, 0.0, 0.0, z);
|
await _channel.invokeMethod("scrollUpdate", [0.0, 0.0, z]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void zoomEnd() async {
|
void zoomEnd() async {
|
||||||
_nativeLibrary.scroll_end(_viewer);
|
await _channel.invokeMethod("scrollEnd");
|
||||||
}
|
}
|
||||||
|
|
||||||
void playAnimation(FilamentEntity asset, int index,
|
void playAnimation(FilamentEntity asset, int index,
|
||||||
{bool loop = false, bool reverse = false}) async {
|
{bool loop = false, bool reverse = false, double crossfade = 0.0}) async {
|
||||||
_nativeLibrary.play_animation(
|
await _channel.invokeMethod("playAnimation", [
|
||||||
_assetManager, asset, index, loop ? 1 : 0, reverse ? 1 : 0);
|
_assetManager,
|
||||||
|
asset,
|
||||||
|
index,
|
||||||
|
loop ? 1 : 0,
|
||||||
|
reverse ? 1 : 0,
|
||||||
|
crossfade
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAnimationFrame(
|
void setAnimationFrame(
|
||||||
FilamentEntity asset, int index, int animationFrame) async {
|
FilamentEntity asset, int index, int animationFrame) async {
|
||||||
_nativeLibrary.set_animation_frame(
|
await _channel.invokeMethod(
|
||||||
_assetManager, asset, index, animationFrame);
|
"setAnimationFrame", [_assetManager, asset, index, animationFrame]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopAnimation(FilamentEntity asset, int animationIndex) async {
|
void stopAnimation(FilamentEntity asset, int animationIndex) async {
|
||||||
_nativeLibrary.stop_animation(_assetManager, asset, animationIndex);
|
await _channel
|
||||||
|
.invokeMethod("stopAnimation", [_assetManager, asset, animationIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCamera(FilamentEntity asset, String? name) async {
|
void setCamera(FilamentEntity asset, String? name) async {
|
||||||
if (_nativeLibrary.set_camera(
|
if (await _channel.invokeMethod("setCamera", [asset, name]) != 1) {
|
||||||
_viewer, asset, name?.toNativeUtf8()?.cast<Char>() ?? nullptr) !=
|
|
||||||
1) {
|
|
||||||
throw Exception("Failed to set camera");
|
throw Exception("Failed to set camera");
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCameraFocalLength(double focalLength) async {
|
void setCameraFocalLength(double focalLength) async {
|
||||||
_nativeLibrary.set_camera_focal_length(_viewer, focalLength);
|
await _channel.invokeMethod("setCameraFocalLength", focalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCameraFocusDistance(double focusDistance) async {
|
void setCameraFocusDistance(double focusDistance) async {
|
||||||
_nativeLibrary.set_camera_focus_distance(_viewer, focusDistance);
|
await _channel.invokeMethod("setCameraFocusDistance", focusDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCameraPosition(double x, double y, double z) async {
|
void setCameraPosition(double x, double y, double z) async {
|
||||||
_nativeLibrary.set_camera_position(_viewer, x, y, z);
|
await _channel.invokeMethod("setCameraPosition", [x, y, z]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCameraExposure(
|
void setCameraExposure(
|
||||||
double aperture, double shutterSpeed, double sensitivity) async {
|
double aperture, double shutterSpeed, double sensitivity) async {
|
||||||
_nativeLibrary.set_camera_exposure(
|
await _channel.invokeMethod(
|
||||||
_viewer, aperture, shutterSpeed, sensitivity);
|
"setCameraExposure", [aperture, shutterSpeed, sensitivity]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCameraRotation(double rads, double x, double y, double z) async {
|
void setCameraRotation(double rads, double x, double y, double z) async {
|
||||||
_nativeLibrary.set_camera_rotation(_viewer, rads, x, y, z);
|
await _channel.invokeMethod("setCameraRotation", [rads, x, y, z]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCameraModelMatrix(List<double> matrix) async {
|
void setCameraModelMatrix(List<double> matrix) async {
|
||||||
@@ -435,42 +404,43 @@ class FilamentController {
|
|||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ptr.elementAt(i).value = matrix[i];
|
ptr.elementAt(i).value = matrix[i];
|
||||||
}
|
}
|
||||||
_nativeLibrary.set_camera_model_matrix(_viewer, ptr);
|
await _channel.invokeMethod("setCameraModelMatrix", [ptr]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTexture(FilamentEntity asset, String assetPath,
|
void setTexture(FilamentEntity asset, String assetPath,
|
||||||
{int renderableIndex = 0}) async {
|
{int renderableIndex = 0}) async {
|
||||||
_nativeLibrary.set_texture(_assetManager, asset);
|
await _channel.invokeMethod("setTexture", [_assetManager, asset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void transformToUnitCube(FilamentEntity asset) async {
|
void transformToUnitCube(FilamentEntity asset) async {
|
||||||
_nativeLibrary.transform_to_unit_cube(_assetManager, asset);
|
await _channel.invokeMethod("transformToUnitCube", [_assetManager, asset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPosition(FilamentEntity asset, double x, double y, double z) async {
|
void setPosition(FilamentEntity asset, double x, double y, double z) async {
|
||||||
_nativeLibrary.set_position(_assetManager, asset, x, y, z);
|
await _channel.invokeMethod("setPosition", [_assetManager, asset, x, y, z]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setScale(FilamentEntity asset, double scale) async {
|
void setScale(FilamentEntity asset, double scale) async {
|
||||||
_nativeLibrary.set_scale(_assetManager, asset, scale);
|
await _channel.invokeMethod("setScale", [_assetManager, asset, scale]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRotation(
|
void setRotation(
|
||||||
FilamentEntity asset, double rads, double x, double y, double z) async {
|
FilamentEntity asset, double rads, double x, double y, double z) async {
|
||||||
_nativeLibrary.set_rotation(_assetManager, asset, rads, x, y, z);
|
await _channel
|
||||||
|
.invokeMethod("setRotation", [_assetManager, asset, rads, x, y, z]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hide(FilamentEntity asset, String meshName) {
|
void hide(FilamentEntity asset, String meshName) async {
|
||||||
if (_nativeLibrary.hide_mesh(
|
if (await _channel
|
||||||
_assetManager, asset, meshName.toNativeUtf8().cast<Char>()) !=
|
.invokeMethod("hideMesh", [_assetManager, asset, meshName]) !=
|
||||||
1) {
|
1) {
|
||||||
throw Exception("Failed to hide mesh $meshName");
|
throw Exception("Failed to hide mesh $meshName");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reveal(FilamentEntity asset, String meshName) {
|
void reveal(FilamentEntity asset, String meshName) async {
|
||||||
if (_nativeLibrary.reveal_mesh(
|
if (await _channel
|
||||||
_assetManager, asset, meshName.toNativeUtf8().cast<Char>()) !=
|
.invokeMethod("revealMesh", [_assetManager, asset, meshName]) !=
|
||||||
1) {
|
1) {
|
||||||
throw Exception("Failed to reveal mesh $meshName");
|
throw Exception("Failed to reveal mesh $meshName");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
|
|||||||
onPointerDown: !widget.enableControls
|
onPointerDown: !widget.enableControls
|
||||||
? null
|
? null
|
||||||
: (d) async {
|
: (d) async {
|
||||||
print("a");
|
|
||||||
// if (d.buttons == kTertiaryButton || _rotating) {
|
// if (d.buttons == kTertiaryButton || _rotating) {
|
||||||
// widget.controller
|
// widget.controller
|
||||||
// .rotateStart(d.localPosition.dx, d.localPosition.dy);
|
// .rotateStart(d.localPosition.dx, d.localPosition.dy);
|
||||||
|
|||||||
@@ -735,6 +735,7 @@ class NativeLibrary {
|
|||||||
int index,
|
int index,
|
||||||
int loop,
|
int loop,
|
||||||
int reverse,
|
int reverse,
|
||||||
|
double crossfade,
|
||||||
) {
|
) {
|
||||||
return _play_animation(
|
return _play_animation(
|
||||||
assetManager,
|
assetManager,
|
||||||
@@ -742,15 +743,16 @@ class NativeLibrary {
|
|||||||
index,
|
index,
|
||||||
loop,
|
loop,
|
||||||
reverse,
|
reverse,
|
||||||
|
crossfade,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
late final _play_animationPtr = _lookup<
|
late final _play_animationPtr = _lookup<
|
||||||
ffi.NativeFunction<
|
ffi.NativeFunction<
|
||||||
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId, ffi.Int, ffi.Int,
|
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId, ffi.Int, ffi.Int,
|
||||||
ffi.Int)>>('play_animation');
|
ffi.Int, ffi.Float)>>('play_animation');
|
||||||
late final _play_animation = _play_animationPtr
|
late final _play_animation = _play_animationPtr.asFunction<
|
||||||
.asFunction<void Function(ffi.Pointer<ffi.Void>, int, int, int, int)>();
|
void Function(ffi.Pointer<ffi.Void>, int, int, int, int, double)>();
|
||||||
|
|
||||||
void set_animation_frame(
|
void set_animation_frame(
|
||||||
ffi.Pointer<ffi.Void> assetManager,
|
ffi.Pointer<ffi.Void> assetManager,
|
||||||
@@ -1193,7 +1195,7 @@ class NativeLibrary {
|
|||||||
late final _ios_dummy = _ios_dummyPtr.asFunction<void Function()>();
|
late final _ios_dummy = _ios_dummyPtr.asFunction<void Function()>();
|
||||||
}
|
}
|
||||||
|
|
||||||
class __mbstate_t extends ffi.Union {
|
final class __mbstate_t extends ffi.Union {
|
||||||
@ffi.Array.multi([128])
|
@ffi.Array.multi([128])
|
||||||
external ffi.Array<ffi.Char> __mbstate8;
|
external ffi.Array<ffi.Char> __mbstate8;
|
||||||
|
|
||||||
@@ -1201,7 +1203,7 @@ class __mbstate_t extends ffi.Union {
|
|||||||
external int _mbstateL;
|
external int _mbstateL;
|
||||||
}
|
}
|
||||||
|
|
||||||
class __darwin_pthread_handler_rec extends ffi.Struct {
|
final class __darwin_pthread_handler_rec extends ffi.Struct {
|
||||||
external ffi
|
external ffi
|
||||||
.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>
|
.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>
|
||||||
__routine;
|
__routine;
|
||||||
@@ -1211,7 +1213,7 @@ class __darwin_pthread_handler_rec extends ffi.Struct {
|
|||||||
external ffi.Pointer<__darwin_pthread_handler_rec> __next;
|
external ffi.Pointer<__darwin_pthread_handler_rec> __next;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _opaque_pthread_attr_t extends ffi.Struct {
|
final class _opaque_pthread_attr_t extends ffi.Struct {
|
||||||
@ffi.Long()
|
@ffi.Long()
|
||||||
external int __sig;
|
external int __sig;
|
||||||
|
|
||||||
@@ -1219,7 +1221,7 @@ class _opaque_pthread_attr_t extends ffi.Struct {
|
|||||||
external ffi.Array<ffi.Char> __opaque;
|
external ffi.Array<ffi.Char> __opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _opaque_pthread_cond_t extends ffi.Struct {
|
final class _opaque_pthread_cond_t extends ffi.Struct {
|
||||||
@ffi.Long()
|
@ffi.Long()
|
||||||
external int __sig;
|
external int __sig;
|
||||||
|
|
||||||
@@ -1227,7 +1229,7 @@ class _opaque_pthread_cond_t extends ffi.Struct {
|
|||||||
external ffi.Array<ffi.Char> __opaque;
|
external ffi.Array<ffi.Char> __opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _opaque_pthread_condattr_t extends ffi.Struct {
|
final class _opaque_pthread_condattr_t extends ffi.Struct {
|
||||||
@ffi.Long()
|
@ffi.Long()
|
||||||
external int __sig;
|
external int __sig;
|
||||||
|
|
||||||
@@ -1235,7 +1237,7 @@ class _opaque_pthread_condattr_t extends ffi.Struct {
|
|||||||
external ffi.Array<ffi.Char> __opaque;
|
external ffi.Array<ffi.Char> __opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _opaque_pthread_mutex_t extends ffi.Struct {
|
final class _opaque_pthread_mutex_t extends ffi.Struct {
|
||||||
@ffi.Long()
|
@ffi.Long()
|
||||||
external int __sig;
|
external int __sig;
|
||||||
|
|
||||||
@@ -1243,7 +1245,7 @@ class _opaque_pthread_mutex_t extends ffi.Struct {
|
|||||||
external ffi.Array<ffi.Char> __opaque;
|
external ffi.Array<ffi.Char> __opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _opaque_pthread_mutexattr_t extends ffi.Struct {
|
final class _opaque_pthread_mutexattr_t extends ffi.Struct {
|
||||||
@ffi.Long()
|
@ffi.Long()
|
||||||
external int __sig;
|
external int __sig;
|
||||||
|
|
||||||
@@ -1251,7 +1253,7 @@ class _opaque_pthread_mutexattr_t extends ffi.Struct {
|
|||||||
external ffi.Array<ffi.Char> __opaque;
|
external ffi.Array<ffi.Char> __opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _opaque_pthread_once_t extends ffi.Struct {
|
final class _opaque_pthread_once_t extends ffi.Struct {
|
||||||
@ffi.Long()
|
@ffi.Long()
|
||||||
external int __sig;
|
external int __sig;
|
||||||
|
|
||||||
@@ -1259,7 +1261,7 @@ class _opaque_pthread_once_t extends ffi.Struct {
|
|||||||
external ffi.Array<ffi.Char> __opaque;
|
external ffi.Array<ffi.Char> __opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _opaque_pthread_rwlock_t extends ffi.Struct {
|
final class _opaque_pthread_rwlock_t extends ffi.Struct {
|
||||||
@ffi.Long()
|
@ffi.Long()
|
||||||
external int __sig;
|
external int __sig;
|
||||||
|
|
||||||
@@ -1267,7 +1269,7 @@ class _opaque_pthread_rwlock_t extends ffi.Struct {
|
|||||||
external ffi.Array<ffi.Char> __opaque;
|
external ffi.Array<ffi.Char> __opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _opaque_pthread_rwlockattr_t extends ffi.Struct {
|
final class _opaque_pthread_rwlockattr_t extends ffi.Struct {
|
||||||
@ffi.Long()
|
@ffi.Long()
|
||||||
external int __sig;
|
external int __sig;
|
||||||
|
|
||||||
@@ -1275,7 +1277,7 @@ class _opaque_pthread_rwlockattr_t extends ffi.Struct {
|
|||||||
external ffi.Array<ffi.Char> __opaque;
|
external ffi.Array<ffi.Char> __opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _opaque_pthread_t extends ffi.Struct {
|
final class _opaque_pthread_t extends ffi.Struct {
|
||||||
@ffi.Long()
|
@ffi.Long()
|
||||||
external int __sig;
|
external int __sig;
|
||||||
|
|
||||||
@@ -1285,7 +1287,7 @@ class _opaque_pthread_t extends ffi.Struct {
|
|||||||
external ffi.Array<ffi.Char> __opaque;
|
external ffi.Array<ffi.Char> __opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ResourceBuffer extends ffi.Struct {
|
final class ResourceBuffer extends ffi.Struct {
|
||||||
external ffi.Pointer<ffi.Void> data;
|
external ffi.Pointer<ffi.Void> data;
|
||||||
|
|
||||||
@ffi.Uint32()
|
@ffi.Uint32()
|
||||||
@@ -1295,7 +1297,7 @@ class ResourceBuffer extends ffi.Struct {
|
|||||||
external int id;
|
external int id;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ResourceLoaderWrapper extends ffi.Struct {
|
final class ResourceLoaderWrapper extends ffi.Struct {
|
||||||
external LoadResource mLoadResource;
|
external LoadResource mLoadResource;
|
||||||
|
|
||||||
external FreeResource mFreeResource;
|
external FreeResource mFreeResource;
|
||||||
@@ -1484,13 +1486,3 @@ const int WINT_MAX = 2147483647;
|
|||||||
const int SIG_ATOMIC_MIN = -2147483648;
|
const int SIG_ATOMIC_MIN = -2147483648;
|
||||||
|
|
||||||
const int SIG_ATOMIC_MAX = 2147483647;
|
const int SIG_ATOMIC_MAX = 2147483647;
|
||||||
|
|
||||||
const int __DARWIN_WCHAR_MAX = 2147483647;
|
|
||||||
|
|
||||||
const int __DARWIN_WCHAR_MIN = -2147483648;
|
|
||||||
|
|
||||||
const int __DARWIN_WEOF = -1;
|
|
||||||
|
|
||||||
const int _FORTIFY_SOURCE = 2;
|
|
||||||
|
|
||||||
const int NULL = 0;
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ version: 0.0.1
|
|||||||
homepage:
|
homepage:
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.17.1 <3.0.0"
|
sdk: ">=3.0.0 <3.11.0"
|
||||||
flutter: ">=1.20.0"
|
flutter: ">=1.20.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
Reference in New Issue
Block a user