Compare commits

...

4 Commits

Author SHA1 Message Date
Nick Fisher
5dec13f00b chore(release): publish packages
- thermion_dart@0.1.1+5
 - thermion_flutter_web@0.0.1+9
 - thermion_flutter@0.1.1+10
 - thermion_flutter_platform_interface@0.1.0+9
 - thermion_flutter_ffi@0.1.0+9
2024-07-04 14:44:04 +08:00
Nick Fisher
7464c05483 Merge pull request #55 from nmfisher/develop
feat: shadows, web, docs, image material
2024-07-04 16:42:25 +10:00
Nick Fisher
7b97b2e6c3 save fetched resources to IndexedDB on web 2024-07-04 14:19:37 +08:00
Nick Fisher
168f46cf56 add shadow methods to wasm/js viewers 2024-07-04 14:19:04 +08:00
16 changed files with 218 additions and 78 deletions

View File

@@ -3,6 +3,40 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## 2024-07-04
### Changes
---
Packages with breaking changes:
- There are no breaking changes in this release.
Packages with other changes:
- [`thermion_dart` - `v0.1.1+5`](#thermion_dart---v0115)
- [`thermion_flutter_web` - `v0.0.1+9`](#thermion_flutter_web---v0019)
- [`thermion_flutter` - `v0.1.1+10`](#thermion_flutter---v01110)
- [`thermion_flutter_platform_interface` - `v0.1.0+9`](#thermion_flutter_platform_interface---v0109)
- [`thermion_flutter_ffi` - `v0.1.0+9`](#thermion_flutter_ffi---v0109)
Packages with dependency updates only:
> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project.
- `thermion_flutter_web` - `v0.0.1+9`
- `thermion_flutter` - `v0.1.1+10`
- `thermion_flutter_platform_interface` - `v0.1.0+9`
- `thermion_flutter_ffi` - `v0.1.0+9`
---
#### `thermion_dart` - `v0.1.1+5`
- Bump "thermion_dart" to `0.1.1+5`.
## 2024-07-02
### Changes

View File

@@ -1,3 +1,7 @@
## 0.1.1+5
- Bump "thermion_dart" to `0.1.1+5`.
## 0.1.1+4
- **FIX**: defer creating image entity/material/etc until actually requested.

View File

@@ -826,4 +826,19 @@ class ThermionViewerJS implements ThermionViewer {
void onDispose(Future Function() callback) {
_onDispose.add(callback);
}
@override
Future setShadowType(ShadowType shadowType) {
return _shim.setShadowType(shadowType).toDart;
}
@override
Future setShadowsEnabled(bool enabled) {
return _shim.setShadowsEnabled(enabled).toDart;
}
@override
Future setSoftShadowOptions(double penumbraScale, double penumbraRatioScale) {
return _shim.setSoftShadowOptions(penumbraScale, penumbraRatioScale).toDart;
}
}

View File

@@ -405,5 +405,17 @@ extension type ThermionViewerJSShim(JSObject _) implements JSObject {
@JS('setBoneTransform')
external JSPromise setBoneTransform(
ThermionEntity entity, int boneIndex, JSArray<JSNumber> transform, int skinIndex);
@JS('setShadowsEnabled')
external JSPromise setShadowsEnabled(
bool enabled);
@JS('setShadowType')
external JSPromise setShadowType(
ShadowType shadowType);
@JS('setSoftShadowOptions')
external JSPromise setSoftShadowOptions(
double penumbraScale, double penumbraRatioScale);
}

View File

@@ -631,8 +631,8 @@ class ThermionViewerWasm implements ThermionViewer {
final promise = _module.ccall(
"load_gltf",
"int",
["void*".toJS, "string".toJS, "string".toJS, "bool".toJS].toJS,
[_sceneManager!, path.toJS, relativeResourcePath.toJS, force.toJS].toJS,
["void*".toJS, "string".toJS, "string".toJS].toJS,
[_sceneManager!, path.toJS, relativeResourcePath.toJS].toJS,
{"async": true}.jsify()) as JSPromise<JSNumber>;
final entityId = (await promise.toDart).toDartInt;
if (entityId == -1) {
@@ -1847,4 +1847,34 @@ class ThermionViewerWasm implements ThermionViewer {
// TODO: implement zoomUpdate
throw UnimplementedError();
}
@override
Future setShadowType(ShadowType shadowType) async {
_module.ccall(
"set_shadow_type",
"void",
["void*".toJS, "int".toJS].toJS,
[_viewer!, shadowType.index.toJS].toJS,
null);
}
@override
Future setShadowsEnabled(bool enabled) async {
_module.ccall(
"set_shadows_enabled",
"void",
["void*".toJS, "bool".toJS].toJS,
[_viewer!, enabled.toJS].toJS,
null);
}
@override
Future setSoftShadowOptions(double penumbraScale, double penumbraRatioScale) async {
_module.ccall(
"set_soft_shadow_options",
"void",
["void*".toJS, "float".toJS, "float".toJS].toJS,
[_viewer!, penumbraScale.toJS, penumbraRatioScale.toJS].toJS,
null);
}
}

View File

@@ -19,7 +19,7 @@ set(EMCC_CFLAGS ${EMCC_CFLAGS} -sEXPORT_NAME=${MODULE_NAME})
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sINITIAL_MEMORY=512mb)
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sMODULARIZE)
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sERROR_ON_UNDEFINED_SYMBOLS=0 )
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sEXPORTED_RUNTIME_METHODS=wasmExports,wasmTable,addFunction,ccall,cwrap,allocate,intArrayFromString,intArrayToString,getValue,setValue,UTF8ToString,stringToUTF8,writeArrayToMemory,_free)
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sEXPORTED_RUNTIME_METHODS=wasmExports,wasmTable,addFunction,ccall,cwrap,allocate,intArrayFromString,intArrayToString,getValue,setValue,UTF8ToString,stringToUTF8,writeArrayToMemory)
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sEXPORTED_FUNCTIONS=_malloc,stackAlloc,_free)
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sFULL_ES3)
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sASSERTIONS)
@@ -35,10 +35,13 @@ set(EMCC_CFLAGS ${EMCC_CFLAGS} -sFETCH=1)
# set(EMCC_CFLAGS ${EMCC_CFLAGS} -sUSE_PTHREADS)
# set(EMCC_CFLAGS ${EMCC_CFLAGS} -sPROXY_TO_WORKER=1)
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sSHARED_MEMORY=0)
set(EMCC_CFLAGS ${EMCC_CFLAGS} -lidbfs.js)
set(EMCC_CFLAGS ${EMCC_CFLAGS} -sFORCE_FILESYSTEM=1)
# set(EMCC_CFLAGS ${EMCC_CFLAGS} -pie)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers -Wno-deprecated-literal-operator -stdlib=libc++ -std=c++17 -fPIC -O3 --no-entry")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers -Wno-deprecated-literal-operator -stdlib=libc++ -std=c++17 -fPIC -O3 --no-entry ")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -pie")
add_link_options(${EMCC_CFLAGS})

View File

@@ -64,57 +64,20 @@ extern "C"
((PendingCall*)context)->HandleResponse(data, length);
}
EMSCRIPTEN_KEEPALIVE void thermion_filament_web_set(char* ptr, int32_t offset, int32_t val) {
memset(ptr+offset, val, 1);
}
EMSCRIPTEN_KEEPALIVE void thermion_filament_web_set_float(float* ptr, int32_t offset, float val) {
ptr[offset] = val;
}
EMSCRIPTEN_KEEPALIVE float thermion_filament_web_get_float(float* ptr, int32_t offset) {
return ptr[offset];
}
EMSCRIPTEN_KEEPALIVE double thermion_filament_web_get_double(double* ptr, int32_t offset) {
return ptr[offset];
}
EMSCRIPTEN_KEEPALIVE void thermion_filament_web_set_double(double* ptr, int32_t offset, double value) {
ptr[offset] = value;
}
EMSCRIPTEN_KEEPALIVE int32_t thermion_filament_web_get_int32(int32_t* ptr, int32_t offset) {
return ptr[offset];
}
EMSCRIPTEN_KEEPALIVE void thermion_filament_web_set_int32(int32_t* ptr, int32_t offset, int32_t value) {
ptr[offset] = value;
}
EMSCRIPTEN_KEEPALIVE void thermion_filament_web_set_pointer(void** ptr, int32_t offset, void* val) {
ptr[offset] = val;
}
EMSCRIPTEN_KEEPALIVE void* thermion_filament_web_get_pointer(void** ptr, int32_t offset) {
return ptr[offset];
}
EMSCRIPTEN_KEEPALIVE char thermion_filament_web_get(char* ptr, int32_t offset) {
return ptr[offset];
}
EMSCRIPTEN_KEEPALIVE void* thermion_filament_web_allocate(int32_t size) {
void* allocated = (void*)calloc(size, 1);
return allocated;
}
EMSCRIPTEN_KEEPALIVE long thermion_filament_web_get_address(void** out) {
return (long)*out;
}
EMSCRIPTEN_KEEPALIVE EMSCRIPTEN_WEBGL_CONTEXT_HANDLE thermion_dart_web_create_gl_context() {
EM_ASM(
FS.mkdir('/indexed');
FS.mount(IDBFS, {}, '/indexed');
FS.syncfs(true, function (err) {
if (err) {
console.error('Error mounting IDBFS:', err);
} else {
console.log('IDBFS mounted successfully');
}
});
);
std::cout << "Creating WebGL context." << std::endl;
EmscriptenWebGLContextAttributes attr;
@@ -181,7 +144,7 @@ extern "C"
// const char* headers[] = {"Accept-Encoding", "gzip, deflate", NULL};
// attr.requestHeaders = headers;
auto pathString = std::string(path);
// auto pathString = std::string(path);
// if(pathString.rfind("/",0) != 0) {
// pathString = std::string("/") + pathString;
// }
@@ -197,18 +160,81 @@ extern "C"
// memcpy(data, request->data, request->numBytes);
// emscripten_fetch_close(request);
// return ResourceBuffer { data, (int32_t) request->numBytes, _lastResourceId } ;
auto pathString = std::string(path);
void* data = nullptr;
int32_t numBytes = 0;
void** pBuffer = (void**)malloc(sizeof(void*));
int* pNum = (int*) malloc(sizeof(int*));
int* pError = (int*)malloc(sizeof(int*));
emscripten_wget_data(pathString.c_str(), pBuffer, pNum, pError);
data = *pBuffer;
numBytes = *pNum;
free(pBuffer);
free(pNum);
free(pError);
// Check if the file exists in IndexedDB first
bool fileExists = EM_ASM_INT({
var filename = UTF8ToString($0);
try {
var stat = FS.stat('/indexed/' + filename);
return stat.size > 0;
} catch (e) {
return false;
}
}, pathString.c_str());
if (fileExists) {
// File exists in IndexedDB, read it
EM_ASM({
var filename = UTF8ToString($0);
var content = FS.readFile('/indexed/' + filename);
var numBytes = content.length;
var ptr = _malloc(numBytes);
HEAPU8.set(content, ptr);
setValue($1, ptr, 'i32');
setValue($2, numBytes, 'i32');
}, pathString.c_str(), &data, &numBytes);
} else {
void** pBuffer = (void**)malloc(sizeof(void*));
int* pNum = (int*) malloc(sizeof(int*));
int* pError = (int*)malloc(sizeof(int*));
emscripten_wget_data(pathString.c_str(), pBuffer, pNum, pError);
data = *pBuffer;
numBytes = *pNum;
// Save the file to IndexedDB filesystem
EM_ASM({
var filename = UTF8ToString($0);
var data = new Uint8Array(HEAPU8.subarray($1, $1 + $2));
console.log('Analyinzg /indexed');
// Ensure the '/indexed' directory exists
if (!FS.analyzePath('/indexed').exists) {
FS.mkdir('/indexed');
console.log('Made dir /indexed');
}
// Create all parent directories
var parts = filename.split('/');
var currentPath = '/indexed';
for (var i = 0; i < parts.length - 1; i++) {
currentPath += '/' + parts[i];
if (!FS.analyzePath(currentPath).exists) {
FS.mkdir(currentPath);
console.log("Made dir " + currentPath);
}
}
console.log('Writing file to /indexed/' + filename);
// Write the file
FS.writeFile('/indexed/' + filename, data);
console.log('File written, syncing');
FS.syncfs(false, function (err) {
if (err) {
console.error('Failed to save file to IndexedDB:', err);
} else {
console.log('File saved to IndexedDB successfully');
}
});
}, pathString.c_str(), data, numBytes);
free(pBuffer);
free(pNum);
free(pError);
}
return ResourceBuffer { data, numBytes, _lastResourceId } ;
}

View File

@@ -1,6 +1,6 @@
name: thermion_dart
description: 3D rendering toolkit for Dart.
version: 0.1.1+4
version: 0.1.1+5
homepage: https://thermion.dev
repository: https://github.com/nmfisher/thermion

View File

@@ -1,3 +1,7 @@
## 0.1.1+10
- Update a dependency to the latest release.
## 0.1.1+9
- Update a dependency to the latest release.

View File

@@ -1,6 +1,6 @@
name: thermion_flutter
description: Flutter plugin for 3D rendering with the Thermion toolkit.
version: 0.1.1+9
version: 0.1.1+10
homepage: https://thermion.dev
repository: https://github.com/nmfisher/thermion
@@ -17,10 +17,10 @@ dependencies:
plugin_platform_interface: ^2.0.0
ffi: ^2.1.2
animation_tools_dart: ^0.0.4
thermion_dart: ^0.1.1+4
thermion_flutter_platform_interface: ^0.1.0+8
thermion_flutter_ffi: ^0.1.0+8
thermion_flutter_web: ^0.0.1+8
thermion_dart: ^0.1.1+5
thermion_flutter_platform_interface: ^0.1.0+9
thermion_flutter_ffi: ^0.1.0+9
thermion_flutter_web: ^0.0.1+9
logging: ^1.2.0
dev_dependencies:

View File

@@ -1,3 +1,7 @@
## 0.1.0+9
- Update a dependency to the latest release.
## 0.1.0+8
- Update a dependency to the latest release.

View File

@@ -1,7 +1,7 @@
name: thermion_flutter_ffi
description: An FFI interface for the thermion_flutter plugin (all platforms except web).
repository: https://github.com/nmfisher/thermion_flutter/thermion_flutter
version: 0.1.0+8
version: 0.1.0+9
environment:
sdk: ">=3.3.0 <4.0.0"
@@ -22,8 +22,8 @@ dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.1.0
thermion_flutter_platform_interface: ^0.1.0+8
thermion_dart: ^0.1.1+4
thermion_flutter_platform_interface: ^0.1.0+9
thermion_dart: ^0.1.1+5
dev_dependencies:
flutter_test:

View File

@@ -1,3 +1,7 @@
## 0.1.0+9
- Update a dependency to the latest release.
## 0.1.0+8
- Update a dependency to the latest release.

View File

@@ -1,7 +1,7 @@
name: thermion_flutter_platform_interface
description: A common platform interface for the thermion_flutter plugin.
repository: https://github.com/nmfisher/thermion_flutter/thermion_flutter
version: 0.1.0+8
version: 0.1.0+9
environment:
sdk: ">=3.3.0 <4.0.0"
@@ -11,7 +11,7 @@ dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.1.0
thermion_dart: ^0.1.1+4
thermion_dart: ^0.1.1+5
dev_dependencies:
flutter_test:

View File

@@ -1,3 +1,7 @@
## 0.0.1+9
- Update a dependency to the latest release.
## 0.0.1+8
- Update a dependency to the latest release.

View File

@@ -1,7 +1,7 @@
name: thermion_flutter_web
description: A web platform interface for the thermion_flutter plugin.
repository: https://github.com/nmfisher/thermion_flutter/thermion_flutter
version: 0.0.1+8
version: 0.0.1+9
environment:
sdk: ">=3.3.0 <4.0.0"
@@ -20,8 +20,8 @@ dependencies:
sdk: flutter
plugin_platform_interface: ^2.1.0
web: ^0.5.1
thermion_dart: ^0.1.1+4
thermion_flutter_platform_interface: ^0.1.0+8
thermion_dart: ^0.1.1+5
thermion_flutter_platform_interface: ^0.1.0+9
flutter_web_plugins:
sdk: flutter