add setExposure, forceRender and update hot reload asset check for iOS
This commit is contained in:
@@ -45,43 +45,56 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
let uriString = String(cString:uri.assumingMemoryBound(to: UInt8.self))
|
let uriString = String(cString:uri.assumingMemoryBound(to: UInt8.self))
|
||||||
|
|
||||||
var path:String? = nil
|
var path:String? = nil
|
||||||
|
|
||||||
let appFolder = Bundle.main.resourceURL
|
// check for hot-reloaded asset
|
||||||
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 found : URL? = nil
|
var found : URL? = nil
|
||||||
|
|
||||||
let orderedURLs = try? FileManager.default.enumerator(at: devFsPath, includingPropertiesForKeys: [ .pathKey, .creationDateKey], options: .skipsHiddenFiles)
|
if(uriString.hasPrefix("asset://")) {
|
||||||
for case let fileURL as URL in orderedURLs! {
|
let assetPath = String(uriString.dropFirst(8))
|
||||||
if !(fileURL.path.hasSuffix(uriString)) {
|
print("Searching for hot reloaded asset under path : \(assetPath)")
|
||||||
continue
|
let appFolder = Bundle.main.resourceURL
|
||||||
}
|
let dirPaths = NSSearchPathForDirectoriesInDomains(.applicationDirectory,
|
||||||
if found == nil {
|
.userDomainMask, true)
|
||||||
found = fileURL
|
let supportDirPaths = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory,
|
||||||
} else {
|
.userDomainMask, true)
|
||||||
do {
|
let devFsPath = URL(fileURLWithPath: supportDirPaths.first!, isDirectory:true).deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("tmp")
|
||||||
let c1 = try found!.resourceValues(forKeys: [.creationDateKey]).creationDate
|
|
||||||
let c2 = try fileURL.resourceValues(forKeys: [.creationDateKey]).creationDate
|
|
||||||
if c1! < c2! {
|
let orderedURLs = try? FileManager.default.enumerator(at: devFsPath, includingPropertiesForKeys: [ .pathKey, .creationDateKey], options: .skipsHiddenFiles)
|
||||||
found = fileURL
|
|
||||||
|
|
||||||
|
for case let fileURL as URL in orderedURLs! {
|
||||||
|
if !(fileURL.path.hasSuffix(assetPath)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
print("Found hot reloaded asset : \(fileURL)")
|
||||||
|
if found == nil {
|
||||||
|
found = fileURL
|
||||||
|
} else {
|
||||||
|
do {
|
||||||
|
let c1 = try found!.resourceValues(forKeys: [.creationDateKey]).creationDate
|
||||||
|
let c2 = try fileURL.resourceValues(forKeys: [.creationDateKey]).creationDate
|
||||||
|
if c1! < c2! {
|
||||||
|
found = fileURL
|
||||||
|
print("\(fileURL) is newer, replacing")
|
||||||
|
} else {
|
||||||
|
print("Ignoring older asset")
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if found != nil {
|
if found != nil {
|
||||||
|
print("Using hot reloaded asset : \(found)")
|
||||||
path = found?.path
|
path = found?.path
|
||||||
} else {
|
} else {
|
||||||
if(uriString.hasPrefix("file://")) {
|
if(uriString.hasPrefix("file://")) {
|
||||||
path = String(uriString.dropFirst(7))
|
path = String(uriString.dropFirst(7))
|
||||||
} else if(uriString.hasPrefix("asset://")) {
|
} else if(uriString.hasPrefix("asset://")) {
|
||||||
let key = instance.registrar.lookupKey(forAsset:String(uriString.dropFirst(6)))
|
let key = instance.registrar.lookupKey(forAsset:String(uriString.dropFirst(8)))
|
||||||
path = Bundle.main.path(forResource: key, ofType:nil)
|
path = Bundle.main.path(forResource: key, ofType:nil)
|
||||||
print("Found path \(path) for uri \(uriString)")
|
print("Found path \(path) for uri \(uriString)")
|
||||||
guard path != nil else {
|
guard path != nil else {
|
||||||
@@ -125,6 +138,14 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
render(viewer, 0)
|
render(viewer, 0)
|
||||||
self.registry.textureFrameAvailable(textureId)
|
self.registry.textureFrameAvailable(textureId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func forceRender() {
|
||||||
|
guard let textureId = self.textureId, let viewer = viewer else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
render(viewer, 0)
|
||||||
|
self.registry.textureFrameAvailable(textureId)
|
||||||
|
}
|
||||||
|
|
||||||
public func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
|
public func copyPixelBuffer() -> Unmanaged<CVPixelBuffer>? {
|
||||||
if(targetPixelBuffer == nil) {
|
if(targetPixelBuffer == nil) {
|
||||||
@@ -422,7 +443,7 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
remove_light(self.viewer,call.arguments as! Int32)
|
remove_light(self.viewer,call.arguments as! Int32)
|
||||||
result(true);
|
result(true);
|
||||||
case "render":
|
case "render":
|
||||||
doRender()
|
forceRender()
|
||||||
result("OK")
|
result("OK")
|
||||||
case "resize":
|
case "resize":
|
||||||
let args = call.arguments as! Array<Double>
|
let args = call.arguments as! Array<Double>
|
||||||
@@ -481,6 +502,10 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
set_camera_model_matrix(self.viewer, floatPtr)
|
set_camera_model_matrix(self.viewer, floatPtr)
|
||||||
}
|
}
|
||||||
result("OK")
|
result("OK")
|
||||||
|
case "setCameraExposure":
|
||||||
|
let args = call.arguments as! Array<Any>
|
||||||
|
set_camera_exposure(self.viewer, Float(args[0] as! Double), Float(args[1] as! Double),Float(args[2] as! Double))
|
||||||
|
result("OK");
|
||||||
case "setCameraFocalLength":
|
case "setCameraFocalLength":
|
||||||
set_camera_focal_length(self.viewer, Float(call.arguments as! Double))
|
set_camera_focal_length(self.viewer, Float(call.arguments as! Double))
|
||||||
result("OK");
|
result("OK");
|
||||||
|
|||||||
Reference in New Issue
Block a user