create examples folder

This commit is contained in:
Nick Fisher committed 2024-05-11 12:30:02 +08:00
1 parent 5493afbf67
commit 8781b67db0
26 files changed
+814 -4

No files matched your search

@@ -0,0 +1,25 @@
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();
@@ -0,0 +1,4 @@
// 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,20 @@
import 'package:dart_filament/dart_filament/compatibility/compatibility.dart';
import 'package:dart_filament/dart_filament/filament_viewer_impl.dart';
void main(List<String> arguments) async {
var fc = FooChar();
print("Started!");
var resourceLoader = flutter_filament_web_get_resource_loader_wrapper();
print("Got resource loader!");
var viewer = FilamentViewer(resourceLoader: resourceLoader);
print("created viewer!");
await viewer.initialized;
while (true) {
await Future.delayed(Duration(milliseconds: 16));
}
print("Finisehd!");
}
@@ -0,0 +1,231 @@
let buildArgsList;
// `modulePromise` is a promise to the `WebAssembly.module` object to be
// instantiated.
// `importObjectPromise` is a promise to an object that contains any additional
// imports needed by the module that aren't provided by the standard runtime.
// The fields on this object will be merged into the importObject with which
// the module will be instantiated.
// This function returns a promise to the instantiated module.
export const instantiate = async (modulePromise, importObjectPromise) => {
let dartInstance;
function stringFromDartString(string) {
const totalLength = dartInstance.exports.$stringLength(string);
let result = '';
let index = 0;
while (index < totalLength) {
let chunkLength = Math.min(totalLength - index, 0xFFFF);
const array = new Array(chunkLength);
for (let i = 0; i < chunkLength; i++) {
array[i] = dartInstance.exports.$stringRead(string, index++);
}
result += String.fromCharCode(...array);
}
return result;
}
function stringToDartString(string) {
const length = string.length;
let range = 0;
for (let i = 0; i < length; i++) {
range |= string.codePointAt(i);
}
if (range < 256) {
const dartString = dartInstance.exports.$stringAllocate1(length);
for (let i = 0; i < length; i++) {
dartInstance.exports.$stringWrite1(dartString, i, string.codePointAt(i));
}
return dartString;
} else {
const dartString = dartInstance.exports.$stringAllocate2(length);
for (let i = 0; i < length; i++) {
dartInstance.exports.$stringWrite2(dartString, i, string.charCodeAt(i));
}
return dartString;
}
}
// Prints to the console
function printToConsole(value) {
if (typeof dartPrint == "function") {
dartPrint(value);
return;
}
if (typeof console == "object" && typeof console.log != "undefined") {
console.log(value);
return;
}
if (typeof print == "function") {
print(value);
return;
}
throw "Unable to print message: " + js;
}
// Converts a Dart List to a JS array. Any Dart objects will be converted, but
// this will be cheap for JSValues.
function arrayFromDartList(constructor, list) {
const length = dartInstance.exports.$listLength(list);
const array = new constructor(length);
for (let i = 0; i < length; i++) {
array[i] = dartInstance.exports.$listRead(list, i);
}
return array;
}
buildArgsList = function(list) {
const dartList = dartInstance.exports.$makeStringList();
for (let i = 0; i < list.length; i++) {
dartInstance.exports.$listAdd(dartList, stringToDartString(list[i]));
}
return dartList;
}
// A special symbol attached to functions that wrap Dart functions.
const jsWrappedDartFunctionSymbol = Symbol("JSWrappedDartFunction");
function finalizeWrapper(dartFunction, wrapped) {
wrapped.dartFunction = dartFunction;
wrapped[jsWrappedDartFunctionSymbol] = true;
return wrapped;
}
// Imports
const dart2wasm = {
_48: v => stringToDartString(v.toString()),
_64: () => {
let stackString = new Error().stack.toString();
let frames = stackString.split('\n');
let drop = 2;
if (frames[0] === 'Error') {
drop += 1;
}
return frames.slice(drop).join('\n');
},
_83: s => stringToDartString(JSON.stringify(stringFromDartString(s))),
_84: s => printToConsole(stringFromDartString(s)),
_98: (ms, c) =>
setTimeout(() => dartInstance.exports.$invokeCallback(c),ms),
_102: (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) => {
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)
};
const baseImports = {
dart2wasm: dart2wasm,
Math: Math,
Date: Date,
Object: Object,
Array: Array,
Reflect: Reflect,
};
const jsStringPolyfill = {
"charCodeAt": (s, i) => s.charCodeAt(i),
"compare": (s1, s2) => {
if (s1 < s2) return -1;
if (s1 > s2) return 1;
return 0;
},
"concat": (s1, s2) => s1 + s2,
"equals": (s1, s2) => s1 === s2,
"fromCharCode": (i) => String.fromCharCode(i),
"length": (s) => s.length,
"substring": (s, a, b) => s.substring(a, b),
};
dartInstance = await WebAssembly.instantiate(await modulePromise, {
...baseImports,
...(await importObjectPromise),
"wasm:js-string": jsStringPolyfill,
});
return dartInstance;
}
// Call the main function for the instantiated module
// `moduleInstance` is the instantiated dart2wasm module
// `args` are any arguments that should be passed into the main function.
export const invoke = (moduleInstance, ...args) => {
const dartMain = moduleInstance.exports.$getMain();
const dartArgs = buildArgsList(args);
moduleInstance.exports.$invokeMain(dartMain, dartArgs);
}
Binary file not shown.
@@ -0,0 +1,27 @@
<html>
<script type="module">
import { dart_filament } from "./dart_filament.js";
let dart2wasm_runtime;
let moduleInstance;
const dartFilamentModulePromise = await WebAssembly.compileStreaming(fetch('dart_filament.wasm'));
var df = await dart_filament(dartFilamentModulePromise);
console.log(df);
const dartModulePromise = WebAssembly.compileStreaming(fetch('example_web.wasm'));
const imports = {"dart_filament":df};
dart2wasm_runtime = await import('./example_web.mjs');
moduleInstance = await dart2wasm_runtime.instantiate(dartModulePromise, imports);
if (moduleInstance) {
try {
await dart2wasm_runtime.invoke(moduleInstance);
} catch (exception) {
console.error(`Exception while invoking test: ${exception}`);
}
}
</script>
</html>