add dart cli/wasm example

This commit is contained in:
Nick Fisher committed 2024-05-17 14:41:37 +08:00
1 parent 5e576e00ba
commit deb0884109
11 files changed
+155 -112

No files matched your search

@@ -0,0 +1,16 @@
# Flight Helmet
## Screenshot
![screenshot](screenshot/screenshot.jpg)
## License Information
Donated by Microsoft for glTF testing
[![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/)
To the extent possible under law, Microsoft has waived all copyright and related or neighboring rights to this asset.
Draco compression was done via Cesium tools on 27-03-2020 as follows.
gltf-pipeline -i FlightHelmet.gltf -o FlightHelmet.gltf -d -s --keep-unused-elements
+1
View File
@@ -0,0 +1 @@
../../../../flutter_filament_federated/flutter_filament/example/assets
@@ -1,25 +0,0 @@
var dart_filament = (() => {
var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
if (typeof __filename != 'undefined') _scriptName ||= __filename;
return (
function(moduleArg = {}) {
var moduleRtn;
function GROWABLE_HEAP_I8(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAP8}function GROWABLE_HEAP_U8(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAPU8}function GROWABLE_HEAP_I16(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAP16}function GROWABLE_HEAP_U16(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAPU16}function GROWABLE_HEAP_I32(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAP32}function GROWABLE_HEAP_U32(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAPU32}function GROWABLE_HEAP_F32(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAPF32}function GROWABLE_HEAP_F64(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAPF64}var Module=Object.assign({},moduleArg);var readyPromiseResolve,readyPromiseReject;var readyPromise=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});["getExceptionMessage","$incrementExceptionRefcount","$decrementExceptionRefcount","___indirect_function_table","_create_filament_viewer","_create_render_target","_destroy_filament_viewer","_set_background_color","_clear_background_image","_set_background_image","_set_background_image_position","_set_tone_mapping","_set_bloom","_load_skybox","_load_ibl","_rotate_ibl","_remove_skybox","_remove_ibl","_add_light","_remove_light","_clear_lights","_load_glb","_load_glb_from_buffer","_create_instance","_get_instance_count","_get_instances","_load_gltf","_set_main_camera","_get_main_camera","_set_camera","_set_camera_fov","_get_camera_model_matrix","_get_camera_view_matrix","_get_camera_projection_matrix","_get_camera_culling_projection_matrix","_set_camera_projection_matrix","_set_camera_culling","_get_camera_culling_near","_get_camera_culling_far","_get_camera_frustum","_set_camera_manipulator_options","_set_view_frustum_culling","_move_camera_to_asset","_set_camera_focus_distance","_set_camera_exposure","_set_camera_position","_set_camera_rotation","_set_camera_model_matrix","_set_camera_focal_length","_render","_set_frame_interval","_destroy_swap_chain","_create_swap_chain","_update_viewport_and_camera_projection","_scroll_update","_scroll_begin","_scroll_end","_grab_begin","_grab_update","_grab_end","_get_scene_manager","_apply_weights","_set_morph_target_weights","_set_morph_animation","_reset_to_rest_pose","_add_bone_animation","_set_post_processing","_set_antialiasing","_set_bone_transform","_play_animation","_set_animation_frame","_get_animation_duration","_get_animation_count","_get_animation_name","_get_morph_target_name_count","_get_morph_target_name","_remove_entity","_clear_entities","_set_material_color","_transform_to_unit_cube","_set_position","_set_rotation","_set_scale","_queue_position_update","_queue_rotation_update","_stop_animation","_hide_mesh","_reveal_mesh","_filament_pick","_get_name_for_entity","_get_entity_count","_get_entities","_get_entity_name_at","_set_recording","_set_recording_output_directory","_ios_dummy","_flutter_filament_free","_add_collision_component","_remove_collision_component","_add_animation_component","_create_geometry","_find_child_entity_by_name","_set_parent","_test_collisions","_set_priority","_get_gizmo","_create_filament_viewer_ffi","_destroy_filament_viewer_ffi","_create_swap_chain_ffi","_destroy_swap_chain_ffi","_create_render_target_ffi","_update_viewport_and_camera_projection_ffi","_set_rendering_ffi","_set_frame_interval_ffi","_render_ffi","_set_background_color_ffi","_load_gltf_ffi","_load_glb_ffi","_load_glb_from_buffer_ffi","_clear_background_image_ffi","_set_background_image_ffi","_set_background_image_position_ffi","_set_tone_mapping_ffi","_set_bloom_ffi","_load_skybox_ffi","_load_ibl_ffi","_remove_skybox_ffi","_remove_ibl_ffi","_remove_light_ffi","_clear_lights_ffi","_remove_entity_ffi","_clear_entities_ffi","_set_camera_ffi","_get_morph_target_name_ffi","_get_morph_target_name_count_ffi","_play_animation_ffi","_set_animation_frame_ffi","_stop_animation_ffi","_get_animation_count_ffi","_get_animation_name_ffi","_set_post_processing_ffi","_get_name_for_entity_ffi","_set_bone_transform_ffi","_reset_to_rest_pose_ffi","_add_bone_animation_ffi","_ios_dummy_ffi","_create_geometry_ffi","_flutter_filament_web_create_gl_context","___original_main","_flutter_filament_web_load_resource_callback","_flutter_filament_web_set","_flutter_filament_web_set_float","_flutter_filament_web_get_float","_flutter_filament_web_get_double","_flutter_filament_web_set_double","_flutter_filament_web_get_int32","_flutter_filament_web_set_int32","_flutter_filament_web_set_pointer","_flutter_filament_web_get_pointer","_flutter_filament_web_get","_flutter_filament_web_allocate","_flutter_filament_web_get_address","_flutter_filament_web_free","_flutter_filament_web_get_resource_loader_wrapper","_main","onRuntimeInitialized"].forEach(prop=>{if(!Object.getOwnPropertyDescriptor(readyPromise,prop)){Object.defineProperty(readyPrLine truncated
return moduleRtn;
}
);
})();
if (typeof exports === 'object' && typeof module === 'object')
module.exports = dart_filament;
else if (typeof define === 'function' && define['amd'])
define([], () => dart_filament);
var isPthread = globalThis.self?.name === 'em-pthread';
var isNode = typeof globalThis.process?.versions?.node == 'string';
if (isNode) isPthread = require('worker_threads').workerData === 'em-pthread'
// When running as a pthread, construct a new instance on startup
isPthread && dart_filament();
+1
View File
@@ -0,0 +1 @@
../../../native/web/build/build/out/dart_filament.js
@@ -0,0 +1 @@
../../../native/web/build/build/out/dart_filament.wasm
@@ -1,4 +0,0 @@
// This file is no longer used by emscripten and has been created as a placeholder
// to allow build systems to transition away from depending on it.
//
// Future versions of emscripten will likely stop generating this file at all.
@@ -0,0 +1 @@
../../../native/web/build/build/out/dart_filament.worker.js
@@ -1,17 +1,54 @@
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import 'package:dart_filament/dart_filament/compatibility/compatibility.dart';
import 'package:dart_filament/dart_filament/filament_viewer_impl.dart';
import 'package:web/web.dart';
void main(List<String> arguments) async {
var fc = FooChar();
print("Started!");
final canvas = document.getElementById("canvas") as HTMLCanvasElement;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var resourceLoader = flutter_filament_web_get_resource_loader_wrapper();
print("Got resource loader!");
var viewer = FilamentViewer(resourceLoader: resourceLoader);
print("created viewer!");
var mousedown = (JSObject event) {
var x = event.getProperty("clientX".toJS) as JSNumber;
var y = event.getProperty("clientY".toJS) as JSNumber;
viewer.rotateStart(x.toDartDouble, y.toDartDouble);
};
canvas.addEventListener("mousedown", mousedown.toJS);
var mousemove = (JSObject event) {
var x = event.getProperty("clientX".toJS) as JSNumber;
var y = event.getProperty("clientY".toJS) as JSNumber;
viewer.rotateUpdate(x.toDartDouble, y.toDartDouble);
};
canvas.addEventListener("mousemove", mousemove.toJS);
var mouseup = (JSObject event) {
viewer.rotateEnd();
};
canvas.addEventListener("mouseup", mousedown.toJS);
await viewer.initialized;
var width = window.innerWidth;
var height = window.innerHeight;
await viewer.createSwapChain(width.toDouble(), height.toDouble());
await viewer.setBackgroundColor(0.0, 1.0, 1.0, 1.0);
await viewer.loadSkybox("assets/default_env_skybox.ktx");
await viewer.loadIbl("assets/default_env_ibl.ktx");
await viewer.loadGltf("assets/FlightHelmet.gltf", "assets");
await viewer.updateViewportAndCameraProjection(
width.toDouble(), height.toDouble());
await viewer.setPostProcessing(true);
await viewer.setRendering(true);
while (true) {
await Future.delayed(Duration(milliseconds: 16));
@@ -95,8 +95,24 @@ export const instantiate = async (modulePromise, importObjectPromise) => {
// Imports
const dart2wasm = {
_48: v => stringToDartString(v.toString()),
_64: () => {
_18: f => finalizeWrapper(f,x0 => dartInstance.exports._18(f,x0)),
_19: f => finalizeWrapper(f,x0 => dartInstance.exports._19(f,x0)),
_75: (x0,x1) => x0.getElementById(x1),
_76: f => finalizeWrapper(f,x0 => dartInstance.exports._76(f,x0)),
_77: (x0,x1,x2) => x0.addEventListener(x1,x2),
_78: f => finalizeWrapper(f,x0 => dartInstance.exports._78(f,x0)),
_79: f => finalizeWrapper(f,x0 => dartInstance.exports._79(f,x0)),
_1499: (x0,x1) => x0.width = x1,
_1501: (x0,x1) => x0.height = x1,
_1878: () => globalThis.window,
_1920: x0 => x0.innerWidth,
_1921: x0 => x0.innerHeight,
_6854: () => globalThis.document,
_12721: () => globalThis.createBoolCallback(),
_12722: () => globalThis.createVoidPointerCallback(),
_12723: () => globalThis.createVoidCallback(),
_12727: v => stringToDartString(v.toString()),
_12743: () => {
let stackString = new Error().stack.toString();
let frames = stackString.split('\n');
let drop = 2;
@@ -105,85 +121,87 @@ _64: () => {
}
return frames.slice(drop).join('\n');
},
_83: s => stringToDartString(JSON.stringify(stringFromDartString(s))),
_84: s => printToConsole(stringFromDartString(s)),
_98: (ms, c) =>
_12762: s => stringToDartString(JSON.stringify(stringFromDartString(s))),
_12763: s => printToConsole(stringFromDartString(s)),
_12777: (ms, c) =>
setTimeout(() => dartInstance.exports.$invokeCallback(c),ms),
_102: (c) =>
_12781: (c) =>
queueMicrotask(() => dartInstance.exports.$invokeCallback(c)),
_104: (a, i) => a.push(i),
_115: a => a.length,
_117: (a, i) => a[i],
_118: (a, i, v) => a[i] = v,
_120: a => a.join(''),
_130: (s, p, i) => s.indexOf(p, i),
_133: (o, start, length) => new Uint8Array(o.buffer, o.byteOffset + start, length),
_134: (o, start, length) => new Int8Array(o.buffer, o.byteOffset + start, length),
_135: (o, start, length) => new Uint8ClampedArray(o.buffer, o.byteOffset + start, length),
_136: (o, start, length) => new Uint16Array(o.buffer, o.byteOffset + start, length),
_137: (o, start, length) => new Int16Array(o.buffer, o.byteOffset + start, length),
_138: (o, start, length) => new Uint32Array(o.buffer, o.byteOffset + start, length),
_139: (o, start, length) => new Int32Array(o.buffer, o.byteOffset + start, length),
_142: (o, start, length) => new Float32Array(o.buffer, o.byteOffset + start, length),
_143: (o, start, length) => new Float64Array(o.buffer, o.byteOffset + start, length),
_148: (o) => new DataView(o.buffer, o.byteOffset, o.byteLength),
_152: Function.prototype.call.bind(Object.getOwnPropertyDescriptor(DataView.prototype, 'byteLength').get),
_153: (b, o) => new DataView(b, o),
_155: Function.prototype.call.bind(DataView.prototype.getUint8),
_157: Function.prototype.call.bind(DataView.prototype.getInt8),
_159: Function.prototype.call.bind(DataView.prototype.getUint16),
_161: Function.prototype.call.bind(DataView.prototype.getInt16),
_163: Function.prototype.call.bind(DataView.prototype.getUint32),
_165: Function.prototype.call.bind(DataView.prototype.getInt32),
_171: Function.prototype.call.bind(DataView.prototype.getFloat32),
_173: Function.prototype.call.bind(DataView.prototype.getFloat64),
_194: o => o === undefined,
_195: o => typeof o === 'boolean',
_196: o => typeof o === 'number',
_198: o => typeof o === 'string',
_201: o => o instanceof Int8Array,
_202: o => o instanceof Uint8Array,
_203: o => o instanceof Uint8ClampedArray,
_204: o => o instanceof Int16Array,
_205: o => o instanceof Uint16Array,
_206: o => o instanceof Int32Array,
_207: o => o instanceof Uint32Array,
_208: o => o instanceof Float32Array,
_209: o => o instanceof Float64Array,
_210: o => o instanceof ArrayBuffer,
_211: o => o instanceof DataView,
_212: o => o instanceof Array,
_213: o => typeof o === 'function' && o[jsWrappedDartFunctionSymbol] === true,
_217: (l, r) => l === r,
_218: o => o,
_219: o => o,
_220: o => o,
_221: b => !!b,
_222: o => o.length,
_225: (o, i) => o[i],
_226: f => f.dartFunction,
_227: l => arrayFromDartList(Int8Array, l),
_228: l => arrayFromDartList(Uint8Array, l),
_229: l => arrayFromDartList(Uint8ClampedArray, l),
_230: l => arrayFromDartList(Int16Array, l),
_231: l => arrayFromDartList(Uint16Array, l),
_232: l => arrayFromDartList(Int32Array, l),
_233: l => arrayFromDartList(Uint32Array, l),
_234: l => arrayFromDartList(Float32Array, l),
_235: l => arrayFromDartList(Float64Array, l),
_236: (data, length) => {
_12783: (a, i) => a.push(i),
_12794: a => a.length,
_12796: (a, i) => a[i],
_12797: (a, i, v) => a[i] = v,
_12799: a => a.join(''),
_12809: (s, p, i) => s.indexOf(p, i),
_12812: (o, start, length) => new Uint8Array(o.buffer, o.byteOffset + start, length),
_12813: (o, start, length) => new Int8Array(o.buffer, o.byteOffset + start, length),
_12814: (o, start, length) => new Uint8ClampedArray(o.buffer, o.byteOffset + start, length),
_12815: (o, start, length) => new Uint16Array(o.buffer, o.byteOffset + start, length),
_12816: (o, start, length) => new Int16Array(o.buffer, o.byteOffset + start, length),
_12817: (o, start, length) => new Uint32Array(o.buffer, o.byteOffset + start, length),
_12818: (o, start, length) => new Int32Array(o.buffer, o.byteOffset + start, length),
_12821: (o, start, length) => new Float32Array(o.buffer, o.byteOffset + start, length),
_12822: (o, start, length) => new Float64Array(o.buffer, o.byteOffset + start, length),
_12827: (o) => new DataView(o.buffer, o.byteOffset, o.byteLength),
_12831: Function.prototype.call.bind(Object.getOwnPropertyDescriptor(DataView.prototype, 'byteLength').get),
_12832: (b, o) => new DataView(b, o),
_12834: Function.prototype.call.bind(DataView.prototype.getUint8),
_12836: Function.prototype.call.bind(DataView.prototype.getInt8),
_12838: Function.prototype.call.bind(DataView.prototype.getUint16),
_12840: Function.prototype.call.bind(DataView.prototype.getInt16),
_12842: Function.prototype.call.bind(DataView.prototype.getUint32),
_12844: Function.prototype.call.bind(DataView.prototype.getInt32),
_12850: Function.prototype.call.bind(DataView.prototype.getFloat32),
_12852: Function.prototype.call.bind(DataView.prototype.getFloat64),
_12873: o => o === undefined,
_12874: o => typeof o === 'boolean',
_12875: o => typeof o === 'number',
_12877: o => typeof o === 'string',
_12880: o => o instanceof Int8Array,
_12881: o => o instanceof Uint8Array,
_12882: o => o instanceof Uint8ClampedArray,
_12883: o => o instanceof Int16Array,
_12884: o => o instanceof Uint16Array,
_12885: o => o instanceof Int32Array,
_12886: o => o instanceof Uint32Array,
_12887: o => o instanceof Float32Array,
_12888: o => o instanceof Float64Array,
_12889: o => o instanceof ArrayBuffer,
_12890: o => o instanceof DataView,
_12891: o => o instanceof Array,
_12892: o => typeof o === 'function' && o[jsWrappedDartFunctionSymbol] === true,
_12896: (l, r) => l === r,
_12897: o => o,
_12898: o => o,
_12899: o => o,
_12900: b => !!b,
_12901: o => o.length,
_12904: (o, i) => o[i],
_12905: f => f.dartFunction,
_12906: l => arrayFromDartList(Int8Array, l),
_12907: l => arrayFromDartList(Uint8Array, l),
_12908: l => arrayFromDartList(Uint8ClampedArray, l),
_12909: l => arrayFromDartList(Int16Array, l),
_12910: l => arrayFromDartList(Uint16Array, l),
_12911: l => arrayFromDartList(Int32Array, l),
_12912: l => arrayFromDartList(Uint32Array, l),
_12913: l => arrayFromDartList(Float32Array, l),
_12914: l => arrayFromDartList(Float64Array, l),
_12915: (data, length) => {
const view = new DataView(new ArrayBuffer(length));
for (let i = 0; i < length; i++) {
view.setUint8(i, dartInstance.exports.$byteDataGetUint8(data, i));
}
return view;
},
_237: l => arrayFromDartList(Array, l),
_238: stringFromDartString,
_239: stringToDartString,
_242: l => new Array(l),
_246: (o, p) => o[p],
_250: o => String(o)
_12916: l => arrayFromDartList(Array, l),
_12917: stringFromDartString,
_12918: stringToDartString,
_12921: l => new Array(l),
_12925: (o, p) => o[p],
_12929: o => String(o),
_12930: (p, s, f) => p.then(s, f),
_12949: (o, p) => o[p]
};
const baseImports = {
Binary file not shown.
@@ -1,3 +0,0 @@
int calculate() {
return 6 * 7;
}
+5 -4
View File
@@ -20,10 +20,11 @@ packages:
animation_tools_dart:
dependency: transitive
description:
name: animation_tools_dart
sha256: c4bc4096d43227b573345a3ea3cb26c3af47a70af31cd7d7d3a5b7c99e33d615
url: "https://pub.dev"
source: hosted
path: "."
ref: HEAD
resolved-ref: "1a5ffc8a58353d43ba1864c8676c47948ee9b5ce"
url: "git@github.com:nmfisher/animation_tools_dart.git"
source: git
version: "0.0.2"
args:
dependency: transitive