feature!:
This is a breaking change needed to fully implement instancing and stencil highlighting.
Previously, users would work directly with entities (on the Dart side, ThermionEntity), e.g.
final entity = await viewer.loadGlb("some.glb");
However, Filament "entities" are a lower-level abstraction.
Loading a glTF file, for example, inserts multiple entities into the scene.
For example, each mesh, light, and camera within a glTF asset will be assigned an entity. A top-level (non-renderable) entity will also be created for the glTF asset, which can be used to transform the entire hierarchy.
"Asset" is a better representation for loading/inserting objects into the scene; think of this as a bundle of entities.
Unless you need to work directly with transforms, instancing, materials and renderables, you can work directly with ThermionAsset.
This commit is contained in:
@@ -35,6 +35,8 @@ class ThermionFlutterPlugin {
|
||||
_viewer =
|
||||
await ThermionFlutterPlatform.instance.createViewer(options: options);
|
||||
|
||||
await _viewer!.initialized;
|
||||
|
||||
var camera = await _viewer!.getActiveCamera();
|
||||
await camera.setLensProjection();
|
||||
|
||||
|
||||
@@ -82,9 +82,11 @@ class _ThermionListenerWidgetState extends State<ThermionListenerWidget> {
|
||||
|
||||
Widget _desktop(double pixelRatio) {
|
||||
return Listener(
|
||||
onPointerHover: (event) => widget.inputHandler.onPointerHover(
|
||||
event.localPosition.toVector2() * pixelRatio,
|
||||
event.delta.toVector2() * pixelRatio),
|
||||
onPointerHover: (event) {
|
||||
widget.inputHandler.onPointerHover(
|
||||
event.localPosition.toVector2() * pixelRatio,
|
||||
event.delta.toVector2() * pixelRatio);
|
||||
},
|
||||
onPointerSignal: (PointerSignalEvent pointerSignal) {
|
||||
if (pointerSignal is PointerScrollEvent) {
|
||||
widget.inputHandler.onPointerScroll(
|
||||
@@ -95,22 +97,26 @@ class _ThermionListenerWidgetState extends State<ThermionListenerWidget> {
|
||||
onPointerPanZoomStart: (pzs) {
|
||||
throw Exception("TODO - is this a pinch zoom on laptop trackpad?");
|
||||
},
|
||||
onPointerDown: (d) => widget.inputHandler.onPointerDown(
|
||||
d.localPosition.toVector2() * pixelRatio,
|
||||
d.buttons & kMiddleMouseButton != 0),
|
||||
onPointerMove: (d) => widget.inputHandler.onPointerMove(
|
||||
onPointerDown: (d) {
|
||||
widget.inputHandler.onPointerDown(
|
||||
d.localPosition.toVector2() * pixelRatio,
|
||||
d.buttons & kMiddleMouseButton != 0);
|
||||
},
|
||||
onPointerMove: (PointerMoveEvent d) => widget.inputHandler.onPointerMove(
|
||||
d.localPosition.toVector2() * pixelRatio,
|
||||
d.delta.toVector2() * pixelRatio,
|
||||
d.buttons & kMiddleMouseButton != 0),
|
||||
onPointerUp: (d) => widget.inputHandler
|
||||
.onPointerUp(d.buttons & kMiddleMouseButton != 0),
|
||||
onPointerUp: (d) =>
|
||||
widget.inputHandler.onPointerUp(d.buttons & kMiddleMouseButton != 0),
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _mobile(double pixelRatio) {
|
||||
return _MobileListenerWidget(
|
||||
inputHandler: widget.inputHandler, pixelRatio: pixelRatio, child:widget.child);
|
||||
inputHandler: widget.inputHandler,
|
||||
pixelRatio: pixelRatio,
|
||||
child: widget.child);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -138,7 +144,10 @@ class _MobileListenerWidget extends StatefulWidget {
|
||||
final Widget? child;
|
||||
|
||||
const _MobileListenerWidget(
|
||||
{Key? key, required this.inputHandler, required this.pixelRatio, this.child})
|
||||
{Key? key,
|
||||
required this.inputHandler,
|
||||
required this.pixelRatio,
|
||||
this.child})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@@ -165,7 +174,9 @@ class _MobileListenerWidgetState extends State<_MobileListenerWidget> {
|
||||
},
|
||||
onScaleStart: (details) async {
|
||||
await widget.inputHandler.onScaleStart(
|
||||
details.localFocalPoint.toVector2() * widget.pixelRatio, details.pointerCount, details.sourceTimeStamp);
|
||||
details.localFocalPoint.toVector2() * widget.pixelRatio,
|
||||
details.pointerCount,
|
||||
details.sourceTimeStamp);
|
||||
},
|
||||
onScaleUpdate: (ScaleUpdateDetails details) async {
|
||||
await widget.inputHandler.onScaleUpdate(
|
||||
@@ -179,7 +190,8 @@ class _MobileListenerWidgetState extends State<_MobileListenerWidget> {
|
||||
details.sourceTimeStamp);
|
||||
},
|
||||
onScaleEnd: (details) async {
|
||||
await widget.inputHandler.onScaleEnd(details.pointerCount, details.scaleVelocity);
|
||||
await widget.inputHandler
|
||||
.onScaleEnd(details.pointerCount, details.scaleVelocity);
|
||||
},
|
||||
child: widget.child);
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
LDFLAGS:=-lfilament -lbackend -lfilameshio -lviewer -lfilamat -lgeometry -lutils -lfilabridge -lgltfio_core -lfilament-iblprefilter -limage -limageio -ltinyexr -lgltfio_core -lfilaflat -ldracodec -libl -lktxreader -lpng -lz -lstb -luberzlib -lsmol-v -luberarchive -lzstd -lvkshaders -lbluegl -lbluevk -lbasis_transcoder -lmeshoptimizer -L../macos/lib -framework CoreFoundation -framework Foundation -framework CoreVideo -framework Metal -framework QuartzCore -framework Cocoa
|
||||
|
||||
clean:
|
||||
rm ./out/test
|
||||
run: build
|
||||
./out/test
|
||||
build: cpp/test.cpp
|
||||
mkdir -p out
|
||||
clang++ -I../ios/include/filament -I../ios/include/ cpp/test.cpp ../macos/src/SceneManager.cpp --std=c++17 $(LDFLAGS) -o out/test
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
|
||||
#include <filament/Engine.h>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "SceneManager.hpp"
|
||||
|
||||
#include "ResourceBuffer.hpp"
|
||||
|
||||
using namespace filament;
|
||||
using namespace thermion;
|
||||
using namespace std;
|
||||
|
||||
int _i = 0;
|
||||
|
||||
ResourceBuffer loadResource(const char* name) {
|
||||
|
||||
std::cout << "LOADING RESOURCE" << std::endl;
|
||||
|
||||
char cwd[PATH_MAX];
|
||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
std::cout << "Current working dir: " << cwd << std::endl;
|
||||
}
|
||||
|
||||
string name_str(name);
|
||||
auto id = _i++;
|
||||
|
||||
name_str = string(cwd) + string("/") + name_str;
|
||||
|
||||
std::cout << "Loading resource at " << name_str.c_str() << std::endl;
|
||||
|
||||
streampos length;
|
||||
ifstream is(name_str, ios::binary);
|
||||
ResourceBuffer rb { nullptr, -1, 0 };
|
||||
if(!is) {
|
||||
std::cout << "Failed to find resource at file path " << name_str.c_str() << std::endl;
|
||||
return rb;
|
||||
}
|
||||
is.seekg (0, ios::end);
|
||||
length = is.tellg();
|
||||
char * buffer;
|
||||
buffer = new char [length];
|
||||
is.seekg (0, ios::beg);
|
||||
is.read (buffer, length);
|
||||
is.close();
|
||||
return ResourceBuffer { buffer, static_cast<int32_t>(length), id };
|
||||
}
|
||||
|
||||
void freeResource(ResourceBuffer rb) {
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
auto engine = Engine::create();
|
||||
auto scene = engine->createScene();
|
||||
auto loader = ResourceLoaderWrapper(loadResource, freeResource);
|
||||
|
||||
auto sceneManager = SceneManager(&loader, engine, scene, nullptr);
|
||||
|
||||
auto shapes = sceneManager.loadGlb("../example/assets/shapes/shapes.glb", 2);
|
||||
|
||||
sceneManager.remove(shapes);
|
||||
|
||||
shapes = sceneManager.loadGlb("../example/assets/shapes/shapes.glb", 2);
|
||||
|
||||
auto instanceCount = sceneManager.getInstanceCount(shapes);
|
||||
assert(instanceCount == 2);
|
||||
|
||||
EntityId instances[instanceCount];
|
||||
|
||||
sceneManager.getInstances(shapes, instances);
|
||||
|
||||
sceneManager.transformToUnitCube(shapes);
|
||||
|
||||
auto morphTargetNames = sceneManager.getMorphTargetNames(shapes, "Cylinder");
|
||||
assert(morphTargetNames->size() == 4);
|
||||
|
||||
morphTargetNames = sceneManager.getMorphTargetNames(shapes, "Cube");
|
||||
assert(morphTargetNames->size() == 2);
|
||||
|
||||
morphTargetNames = sceneManager.getMorphTargetNames(shapes, "Cone");
|
||||
assert(morphTargetNames->size() == 8);
|
||||
math::mat4f boneTransform;
|
||||
sceneManager.setBoneTransform(shapes, "Cylinder", 0, "Bone", boneTransform);
|
||||
|
||||
|
||||
sceneManager.destroyAll();
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
void main() {
|
||||
test('Plane', () {
|
||||
var plane = Plane()..setFromComponents(1, 0, 0, 2);
|
||||
print(plane.distanceToVector3(Vector3(-1, 0, 0)));
|
||||
});
|
||||
|
||||
test('Check if point is inside frustum', () {
|
||||
var frustum = Frustum();
|
||||
frustum.plane0.setFromComponents(-0.868, 0, 0.49, 0);
|
||||
frustum.plane1.setFromComponents(0.868, 0, 0.49, 0);
|
||||
frustum.plane2.setFromComponents(0, -0.919, 0.39, 0);
|
||||
frustum.plane3.setFromComponents(0, 0.919, 0.39, 0);
|
||||
frustum.plane4.setFromComponents(0, 0, -1, -999.88);
|
||||
frustum.plane5.setFromComponents(0, 0, 1, 0.05);
|
||||
|
||||
var point = Vector3(0, 0, -1);
|
||||
|
||||
print(frustum.plane0.distanceToVector3(point));
|
||||
print(frustum.plane1.distanceToVector3(point));
|
||||
|
||||
print(frustum.plane2.distanceToVector3(point));
|
||||
|
||||
print(frustum.plane3.distanceToVector3(point));
|
||||
|
||||
print(frustum.plane4.distanceToVector3(point));
|
||||
|
||||
print(frustum.plane5.distanceToVector3(point));
|
||||
|
||||
print(frustum.containsVector3(point));
|
||||
});
|
||||
|
||||
test("Lukas test", () {
|
||||
final frustum = Frustum();
|
||||
//left
|
||||
frustum.plane0.setFromComponents(-1.0, 0, 0, 1);
|
||||
//right
|
||||
frustum.plane1.setFromComponents(1.0, 0, 0, 2.0);
|
||||
//bottom
|
||||
frustum.plane2.setFromComponents(0, -1, 0, 1);
|
||||
//top
|
||||
frustum.plane3.setFromComponents(0, 1, 0, 1);
|
||||
//far
|
||||
frustum.plane4.setFromComponents(0, 0, -1, 1);
|
||||
//near
|
||||
frustum.plane5.setFromComponents(0, 0, 1, 1);
|
||||
|
||||
// vector3
|
||||
final point = Vector3(-0.5, 0, 0);
|
||||
|
||||
print(frustum.plane0.distanceToVector3(point));
|
||||
print(frustum.plane1.distanceToVector3(point));
|
||||
|
||||
print(frustum.plane2.distanceToVector3(point));
|
||||
|
||||
print(frustum.plane3.distanceToVector3(point));
|
||||
|
||||
print(frustum.plane4.distanceToVector3(point));
|
||||
|
||||
print(frustum.plane5.distanceToVector3(point));
|
||||
|
||||
print(frustum.containsVector3(point));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user