merge moveCameraToAsset changes
This commit is contained in:
@@ -34,6 +34,8 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
var uriString = String(cString:uri!)
|
||||
|
||||
var path:String? = nil
|
||||
|
||||
print("Received request to load \(uriString)")
|
||||
|
||||
if(uriString.hasPrefix("file://")) {
|
||||
path = String(uriString.dropFirst(7))
|
||||
@@ -47,12 +49,13 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
|
||||
if(path != nil) {
|
||||
do {
|
||||
print("Attempting to load file at path \(path!)")
|
||||
print("Loading file at path \(path!)")
|
||||
let data = try Data(contentsOf: URL(fileURLWithPath:path!))
|
||||
let nsData = data as NSData
|
||||
let resId = UInt32(instance.resources.count)
|
||||
instance.resources[resId] = nsData
|
||||
let length = nsData.length
|
||||
print("Got file of length \(length)")
|
||||
return ResourceBuffer(data:nsData.bytes, size:UInt32(nsData.count), id:UInt32(resId))
|
||||
} catch {
|
||||
print("ERROR LOADING RESOURCE")
|
||||
@@ -613,7 +616,12 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
}
|
||||
let success = set_camera(viewer, asset, nodeName)
|
||||
result(success)
|
||||
|
||||
case "moveCameraToAsset":
|
||||
move_camera_to_asset(viewer, call.arguments as! EntityId)
|
||||
result(true)
|
||||
case "setViewFrustumCulling":
|
||||
set_view_frustum_culling(viewer, call.arguments as! Bool)
|
||||
result(true)
|
||||
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))
|
||||
|
||||
@@ -81,6 +81,8 @@ namespace polyvox {
|
||||
void setBackgroundImage(const char* resourcePath);
|
||||
void clearBackgroundImage();
|
||||
void setBackgroundImagePosition(float x, float y, bool clamp);
|
||||
void moveCameraToAsset(EntityId entityId);
|
||||
void setViewFrustumCulling(bool enabled);
|
||||
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
|
||||
void setCameraPosition(float x, float y, float z);
|
||||
void setCameraRotation(float rads, float x, float y, float z);
|
||||
|
||||
@@ -89,6 +89,8 @@ void transform_to_unit_cube(void* assetManager, EntityId asset);
|
||||
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_scale(void* assetManager, EntityId asset, float scale);
|
||||
void move_camera_to_asset(const void* const viewer, EntityId asset);
|
||||
void set_view_frustum_culling(const void* const viewer, bool enabled);
|
||||
void set_camera_exposure(const void* const viewer, float aperture, float shutterSpeed, float sensitivity);
|
||||
void set_camera_position(const void* const viewer, float x, float y, float z);
|
||||
void set_camera_rotation(const void* const viewer, float rads, float x, float y, float z);
|
||||
|
||||
@@ -51,19 +51,16 @@ _scene(scene) {
|
||||
|
||||
_gltfResourceLoader = new ResourceLoader({.engine = _engine,
|
||||
.normalizeSkinningWeights = true });
|
||||
sdfsdfds
|
||||
auto uberdata = resourceLoaderWrapper->load("packages/polyvox_filament/assets/default.uberz");
|
||||
_ubershaderProvider = gltfio::createUbershaderProvider(
|
||||
_engine, uberdata.data, uberdata.size);
|
||||
_engine, UBERARCHIVE_DEFAULT_DATA, UBERARCHIVE_DEFAULT_SIZE);
|
||||
|
||||
|
||||
|
||||
// _ubershaderProvider = gltfio::createJitShaderProvider(_engine, true);
|
||||
// _ubershaderProvider = new StandardMaterialProvider(_engine);
|
||||
EntityManager &em = EntityManager::get();
|
||||
|
||||
//_unlitProvider = new UnlitMaterialProvider(_engine);
|
||||
|
||||
// auto rb = _resourceLoaderWrapper->load("file:///mnt/hdd_2tb/home/hydroxide/projects/polyvox/flutter/polyvox_filament/materials/toon.filamat");
|
||||
// auto toonProvider = new FileMaterialProvider(_engine, rb.data, (size_t) rb.size);
|
||||
|
||||
|
||||
_assetLoader = AssetLoader::create({_engine, _ubershaderProvider, _ncm, &em });
|
||||
_gltfResourceLoader->addTextureProvider("image/ktx2", _ktxDecoder);
|
||||
@@ -74,7 +71,6 @@ sdfsdfds
|
||||
AssetManager::~AssetManager() {
|
||||
_gltfResourceLoader->asyncCancelLoad();
|
||||
_ubershaderProvider->destroyMaterials();
|
||||
//_unlitProvider->destroyMaterials();
|
||||
destroyAll();
|
||||
AssetLoader::destroy(&_assetLoader);
|
||||
|
||||
|
||||
@@ -861,6 +861,27 @@ void FilamentViewer::updateViewportAndCameraProjection(
|
||||
contentScaleFactor);
|
||||
}
|
||||
|
||||
void FilamentViewer::moveCameraToAsset(EntityId entityId) {
|
||||
|
||||
auto asset = _assetManager->getAssetByEntityId(entityId);
|
||||
if(!asset) {
|
||||
Log("Failed to find asset attached to specified entity id.");
|
||||
return;
|
||||
}
|
||||
|
||||
const filament::Aabb bb = asset->getBoundingBox();
|
||||
auto corners = bb.getCorners();
|
||||
Camera& cam =_view->getCamera();
|
||||
auto eye = corners.vertices[0] * 1.5;
|
||||
auto lookAt = corners.vertices[7];
|
||||
cam.lookAt(eye, lookAt);
|
||||
Log("Moved camera to %f %f %f, lookAt %f %f %f, near %f far %f", eye[0], eye[1], eye[2], lookAt[0], lookAt[1], lookAt[2], cam.getNear(), cam.getCullingFar());
|
||||
}
|
||||
|
||||
void FilamentViewer::setViewFrustumCulling(bool enabled) {
|
||||
_view->setFrustumCullingEnabled(enabled);
|
||||
}
|
||||
|
||||
void FilamentViewer::setCameraPosition(float x, float y, float z) {
|
||||
Camera& cam =_view->getCamera();
|
||||
|
||||
@@ -915,7 +936,7 @@ void FilamentViewer::grabUpdate(float x, float y) {
|
||||
return;
|
||||
}
|
||||
Camera& cam =_view->getCamera();
|
||||
auto eye = cam.getPosition();// math::float3 {0.0f, 0.5f, 50.0f } ;// ; //
|
||||
auto eye = cam.getPosition();
|
||||
auto target = eye + cam.getForwardVector();
|
||||
auto upward = cam.getUpVector();
|
||||
Viewport const& vp = _view->getViewport();
|
||||
@@ -924,9 +945,7 @@ void FilamentViewer::grabUpdate(float x, float y) {
|
||||
cam.setModelMatrix(trans);
|
||||
} else {
|
||||
auto trans = cam.getModelMatrix() * mat4::rotation(
|
||||
|
||||
0.01,
|
||||
// math::float3 { 0.0f, 1.0f, 0.0f });
|
||||
0.02,
|
||||
math::float3 { (y - _startY) / vp.height, (x - _startX) / vp.width, 0.0f });
|
||||
cam.setModelMatrix(trans);
|
||||
}
|
||||
|
||||
@@ -97,6 +97,14 @@ extern "C" {
|
||||
return ((FilamentViewer*)viewer)->setCamera(asset, nodeName);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void move_camera_to_asset(const void* const viewer, EntityId asset) {
|
||||
((FilamentViewer*)viewer)->moveCameraToAsset(asset);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void* const viewer, bool enabled) {
|
||||
((FilamentViewer*)viewer)->setViewFrustumCulling(enabled);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float distance) {
|
||||
((FilamentViewer*)viewer)->setCameraFocusDistance(distance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user