update Dart cli_windows example
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:thermion_dart/src/utils/src/dart_resources.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_filament_app.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/thermion_viewer_ffi.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/thermion_dart.g.dart';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
@@ -13,29 +12,17 @@ import 'package:cli_windows/thermion_window.g.dart';
|
||||
void main(List<String> arguments) async {
|
||||
var hwnd = create_thermion_window(500, 500, 0, 0);
|
||||
update();
|
||||
|
||||
final resourceLoader = calloc<ResourceLoaderWrapper>(1);
|
||||
|
||||
var loadToOut = NativeCallable<
|
||||
Void Function(Pointer<Char>,
|
||||
Pointer<ResourceBuffer>)>.listener(DartResourceLoader.loadResource);
|
||||
|
||||
resourceLoader.ref.loadToOut = loadToOut.nativeFunction;
|
||||
var freeResource = NativeCallable<Void Function(ResourceBuffer)>.listener(
|
||||
DartResourceLoader.freeResource);
|
||||
resourceLoader.ref.freeResource = freeResource.nativeFunction;
|
||||
|
||||
var viewer = ThermionViewerFFI(
|
||||
resourceLoader: resourceLoader.cast<Void>());
|
||||
await FFIFilamentApp.create();
|
||||
var viewer = ThermionViewerFFI(
|
||||
loadAssetFromUri: (path) async => File(path.replaceAll("file://", "")).readAsBytesSync());
|
||||
|
||||
await viewer.initialized;
|
||||
var swapChain = await viewer.createHeadlessSwapChain(500,500);
|
||||
var view = await viewer.getViewAt(0);
|
||||
var swapChain = await FilamentApp.instance!.createSwapChain(Pointer<Void>.fromAddress(hwnd));
|
||||
var view = viewer.view;
|
||||
await view.setViewport(500, 500);
|
||||
var camera = await viewer.getMainCamera();
|
||||
var camera = await viewer.getActiveCamera();
|
||||
await camera.setLensProjection();
|
||||
|
||||
await view.setRenderable(true, swapChain);
|
||||
await FilamentApp.instance!.register(swapChain, view);
|
||||
|
||||
await viewer.setBackgroundColor(1.0, 0.0, 0.0, 1.0);
|
||||
|
||||
@@ -49,15 +36,15 @@ void main(List<String> arguments) async {
|
||||
|
||||
var last = 0;
|
||||
|
||||
await viewer.setCameraPosition(0, 0, 10);
|
||||
await camera.lookAt(Vector3(0, 0, 10));
|
||||
|
||||
while(true) {
|
||||
var angle = (stopwatch.elapsedMilliseconds / 1000) * 2 * pi;
|
||||
var rotation = Quaternion.axisAngle(Vector3(0,1,0), angle);
|
||||
var position = Vector3(10 * sin(angle), 0, 10 * cos(angle));
|
||||
var modelMatrix = Matrix4.compose(position, rotation, Vector3.all(1));
|
||||
await viewer.setCameraModelMatrix4(modelMatrix);
|
||||
await viewer.render();
|
||||
await camera.setModelMatrix(modelMatrix);
|
||||
await FilamentApp.instance!.requestFrame();
|
||||
update();
|
||||
await Future.delayed(Duration(milliseconds: 17));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:io';
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||
import 'package:native_toolchain_c/native_toolchain_c.dart';
|
||||
@@ -10,23 +8,22 @@ void main(List<String> args) async {
|
||||
..level = Level.ALL
|
||||
..onRecord.listen((record) => print(
|
||||
record.message + "\n"));
|
||||
|
||||
await build(args, (config, output) async {
|
||||
|
||||
await build(args, (input, output) async {
|
||||
final cbuilder = CBuilder.library(
|
||||
name: "thermion_window",
|
||||
name: input.packageName,
|
||||
language: Language.cpp,
|
||||
assetName: 'thermion_window.dart',
|
||||
assetName: 'cli_windows.dart',
|
||||
sources: ['native/thermion_window.cpp'],
|
||||
includes: ['native', '../../../thermion_dart/native/include'],
|
||||
defines: {"UNICODE":"1"},
|
||||
flags:[],
|
||||
dartBuildFiles: ['hook/build.dart'],
|
||||
|
||||
);
|
||||
|
||||
await cbuilder.run(
|
||||
buildConfig: config,
|
||||
buildOutput: output,
|
||||
input: input,
|
||||
output: output,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Generated by `package:ffigen`.
|
||||
// ignore_for_file: type=lint
|
||||
@ffi.DefaultAsset('package:cli_windows/thermion_window.dart')
|
||||
@ffi.DefaultAsset('package:cli_windows/cli_windows.dart')
|
||||
library;
|
||||
|
||||
import 'dart:ffi' as ffi;
|
||||
|
||||
@@ -1,42 +1,21 @@
|
||||
name: cli_windows
|
||||
description: A sample command-line application with basic argument parsing.
|
||||
version: 0.0.1
|
||||
# repository: https://github.com/my_org/my_repo
|
||||
|
||||
environment:
|
||||
sdk: ^3.6.0-326.0.dev
|
||||
|
||||
# Add regular dependencies here.
|
||||
dependencies:
|
||||
args: ^2.5.0
|
||||
thermion_dart:
|
||||
path: ../../../thermion_dart
|
||||
ffi: ^2.1.3
|
||||
vector_math: ^2.1.4
|
||||
native_toolchain_c: ^0.4.2
|
||||
native_assets_cli: ^0.6.1
|
||||
native_toolchain_c: ^0.9.0
|
||||
native_assets_cli: ^0.12.0
|
||||
|
||||
dev_dependencies:
|
||||
lints: ^5.0.0
|
||||
test: ^1.24.0
|
||||
ffigen: ^13.0.0
|
||||
ffigen:
|
||||
output: 'lib/thermion_window.g.dart'
|
||||
headers:
|
||||
entry-points:
|
||||
- 'native/thermion_window.h'
|
||||
include-directives:
|
||||
- 'native/thermion_window.h'
|
||||
ffi-native:
|
||||
assetId: package:cli_windows/thermion_window.dart
|
||||
ignore-source-errors: true
|
||||
llvm-path:
|
||||
- E:\clang+llvm-19.1.3-x86_64-pc-windows-msvc\bin
|
||||
- E:\clang+llvm-19.1.3-x86_64-pc-windows-msvc\
|
||||
- E:\clang+llvm-19.1.3-x86_64-pc-windows-msvc\lib
|
||||
functions:
|
||||
leaf:
|
||||
include:
|
||||
- '.*'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user