Merge branch 'master' of github.com:nmfisher/polyvox_filament
This commit is contained in:
@@ -77,7 +77,6 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
|
|
||||||
if found != nil {
|
if found != nil {
|
||||||
path = found?.path
|
path = found?.path
|
||||||
print("FOUND \(found)")
|
|
||||||
} else {
|
} else {
|
||||||
if(uriString.hasPrefix("file://")) {
|
if(uriString.hasPrefix("file://")) {
|
||||||
path = String(uriString.dropFirst(7))
|
path = String(uriString.dropFirst(7))
|
||||||
@@ -237,12 +236,12 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
case "setAnimation":
|
case "setAnimation":
|
||||||
let args = call.arguments as! Array<Any?>
|
let args = call.arguments as! Array<Any?>
|
||||||
let assetPtr = UnsafeMutableRawPointer.init(bitPattern: args[0] as! Int)
|
let assetPtr = UnsafeMutableRawPointer.init(bitPattern: args[0] as! Int)
|
||||||
|
let entityName = args[1] as! String
|
||||||
|
let morphData = (args[2] as! FlutterStandardTypedData)
|
||||||
|
|
||||||
let morphData = (args[1] as! FlutterStandardTypedData)
|
let numMorphWeights = args[3] as! Int
|
||||||
|
|
||||||
let numMorphWeights = args[2] as! Int
|
let boneAnimations = args[4] as! Array<Array<Any?>>
|
||||||
|
|
||||||
let boneAnimations = args[3] as! Array<Array<Any?>>
|
|
||||||
let numBoneAnimations = boneAnimations.count
|
let numBoneAnimations = boneAnimations.count
|
||||||
|
|
||||||
var boneAnimStructs = UnsafeMutableBufferPointer<BoneAnimation>.allocate(capacity: numBoneAnimations)
|
var boneAnimStructs = UnsafeMutableBufferPointer<BoneAnimation>.allocate(capacity: numBoneAnimations)
|
||||||
@@ -281,11 +280,12 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let numFrames = args[4] as! Int
|
let numFrames = args[5] as! Int
|
||||||
let frameLenInMs = args[5] as! Double
|
let frameLenInMs = args[6] as! Double
|
||||||
morphData.data.withUnsafeBytes { (morphDataNative: UnsafePointer<Float>) in
|
morphData.data.withUnsafeBytes { (morphDataNative: UnsafePointer<Float>) in
|
||||||
set_animation(
|
set_animation(
|
||||||
assetPtr,
|
assetPtr,
|
||||||
|
entityName,
|
||||||
morphDataNative,
|
morphDataNative,
|
||||||
Int32(numMorphWeights),
|
Int32(numMorphWeights),
|
||||||
boneAnimStructs.baseAddress,
|
boneAnimStructs.baseAddress,
|
||||||
@@ -357,6 +357,13 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
let reverse = args[3] as! Bool;
|
let reverse = args[3] as! Bool;
|
||||||
play_animation(assetPtr, animationIndex, loop, reverse)
|
play_animation(assetPtr, animationIndex, loop, reverse)
|
||||||
result("OK");
|
result("OK");
|
||||||
|
case "setAnimationFrame":
|
||||||
|
let args = call.arguments as! Array<Any?>
|
||||||
|
let assetPtr = UnsafeMutableRawPointer.init(bitPattern: args[0] as! Int)
|
||||||
|
let animationIndex = args[1] as! Int32;
|
||||||
|
let animationFrame = args[2] as! Int32;
|
||||||
|
set_animation_frame(assetPtr, animationIndex, animationFrame)
|
||||||
|
result("OK");
|
||||||
case "stopAnimation":
|
case "stopAnimation":
|
||||||
let args = call.arguments as! Array<Any?>
|
let args = call.arguments as! Array<Any?>
|
||||||
let assetPtr = UnsafeMutableRawPointer.init(bitPattern: args[0] as! Int)
|
let assetPtr = UnsafeMutableRawPointer.init(bitPattern: args[0] as! Int)
|
||||||
@@ -390,9 +397,11 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
case "setMorphTargetWeights":
|
case "setMorphTargetWeights":
|
||||||
let args = call.arguments as! Array<Any?>
|
let args = call.arguments as! Array<Any?>
|
||||||
let assetPtr = UnsafeMutableRawPointer.init(bitPattern: args[0] as! Int)
|
let assetPtr = UnsafeMutableRawPointer.init(bitPattern: args[0] as! Int)
|
||||||
let weights = args[1] as! Array<Float>
|
let entityName = args[1] as! String
|
||||||
|
let weights = args[2] as! Array<Float>
|
||||||
|
let count = args[3] as! Int
|
||||||
weights.map { Float($0) }.withUnsafeBufferPointer {
|
weights.map { Float($0) }.withUnsafeBufferPointer {
|
||||||
apply_weights(assetPtr, UnsafeMutablePointer<Float>.init(mutating:$0.baseAddress), Int32(weights.count))
|
apply_weights(assetPtr, entityName, UnsafeMutablePointer<Float>.init(mutating:$0.baseAddress), Int32(count))
|
||||||
|
|
||||||
}
|
}
|
||||||
result("OK")
|
result("OK")
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ void set_animation(
|
|||||||
// );
|
// );
|
||||||
|
|
||||||
void play_animation(void* asset, int index, bool loop, bool reverse);
|
void play_animation(void* asset, int index, bool loop, bool reverse);
|
||||||
|
void set_animation_frame(void* asset, int animationIndex, int animationFrame);
|
||||||
void stop_animation(void* asset, int index);
|
void stop_animation(void* asset, int index);
|
||||||
|
|
||||||
int get_animation_count(void* asset);
|
int get_animation_count(void* asset);
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ namespace polyvox {
|
|||||||
///
|
///
|
||||||
void playAnimation(int index, bool loop, bool reverse);
|
void playAnimation(int index, bool loop, bool reverse);
|
||||||
|
|
||||||
|
void setAnimationFrame(int animationIndex, int animationFrame);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Set the weights for all [count] morph targets in this asset's entity named [inst] to [weights].
|
/// Set the weights for all [count] morph targets in this asset's entity named [inst] to [weights].
|
||||||
/// See [setAnimation] if you want to do the same across a number of frames (and extended to bone transforms).
|
/// See [setAnimation] if you want to do the same across a number of frames (and extended to bone transforms).
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#ifndef SwiftPolyvoxFilamentPlugin_Bridging_Header_h
|
#ifndef SwiftPolyvoxFilamentPlugin_Bridging_Header_h
|
||||||
#define SwiftPolyvoxFilamentPlugin_Bridging_Header_h
|
#define SwiftPolyvoxFilamentPlugin_Bridging_Header_h
|
||||||
|
|
||||||
// void* filament_viewer_new_ios(void* texture, void* loadResource, void* freeResource, void* resources);
|
|
||||||
|
|
||||||
#import "PolyvoxFilamentIOSApi.h"
|
#import "PolyvoxFilamentIOSApi.h"
|
||||||
#import "PolyvoxFilamentApi.h"
|
#import "PolyvoxFilamentApi.h"
|
||||||
|
|
||||||
|
|||||||
@@ -198,6 +198,10 @@ extern "C" {
|
|||||||
((SceneAsset*)asset)->playAnimation(index, loop, reverse);
|
((SceneAsset*)asset)->playAnimation(index, loop, reverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_animation_frame(void* asset, int animationIndex, int animationFrame) {
|
||||||
|
((SceneAsset*)asset)->setAnimationFrame(animationIndex, animationFrame);
|
||||||
|
}
|
||||||
|
|
||||||
int get_animation_count(void* asset) {
|
int get_animation_count(void* asset) {
|
||||||
auto names = ((SceneAsset*)asset)->getAnimationNames();
|
auto names = ((SceneAsset*)asset)->getAnimationNames();
|
||||||
return names->size();
|
return names->size();
|
||||||
|
|||||||
@@ -346,6 +346,12 @@ void SceneAsset::setTexture() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneAsset::setAnimationFrame(int animationIndex, int animationFrame) {
|
||||||
|
auto offset = 60 * animationFrame * 1000; // TODO - don't hardcore 60fps framerate
|
||||||
|
_animator->applyAnimation(animationIndex, offset);
|
||||||
|
_animator->updateBoneMatrices();
|
||||||
|
}
|
||||||
|
|
||||||
void SceneAsset::updateEmbeddedAnimations() {
|
void SceneAsset::updateEmbeddedAnimations() {
|
||||||
auto now = high_resolution_clock::now();
|
auto now = high_resolution_clock::now();
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ abstract class FilamentController {
|
|||||||
Future<List<String>> getAnimationNames(FilamentAsset asset);
|
Future<List<String>> getAnimationNames(FilamentAsset asset);
|
||||||
Future removeAsset(FilamentAsset asset);
|
Future removeAsset(FilamentAsset asset);
|
||||||
Future clearAssets();
|
Future clearAssets();
|
||||||
|
Future setAnimationFrame(
|
||||||
|
FilamentAsset asset, int animationIndex, int animationFrame);
|
||||||
Future playAnimation(FilamentAsset asset, int index,
|
Future playAnimation(FilamentAsset asset, int index,
|
||||||
{bool loop = false, bool reverse = false});
|
{bool loop = false, bool reverse = false});
|
||||||
Future playAnimations(FilamentAsset asset, List<int> indices,
|
Future playAnimations(FilamentAsset asset, List<int> indices,
|
||||||
@@ -333,6 +335,12 @@ class PolyvoxFilamentController extends FilamentController {
|
|||||||
await _channel.invokeMethod("playAnimation", [asset, index, loop, reverse]);
|
await _channel.invokeMethod("playAnimation", [asset, index, loop, reverse]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future setAnimationFrame(
|
||||||
|
FilamentAsset asset, int index, int animationFrame) async {
|
||||||
|
await _channel
|
||||||
|
.invokeMethod("setAnimationFrame", [asset, index, animationFrame]);
|
||||||
|
}
|
||||||
|
|
||||||
Future playAnimations(FilamentAsset asset, List<int> indices,
|
Future playAnimations(FilamentAsset asset, List<int> indices,
|
||||||
{bool loop = false, bool reverse = false}) async {
|
{bool loop = false, bool reverse = false}) async {
|
||||||
return Future.wait(indices.map((index) {
|
return Future.wait(indices.map((index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user