update materials_and_textures example

This commit is contained in:
Nick Fisher
2025-05-13 18:06:33 +08:00
parent cff0893d53
commit 62bf3876f8
4 changed files with 21 additions and 24 deletions

View File

@@ -54,8 +54,10 @@ class _MyHomePageState extends State<MyHomePage> {
_viewer = viewer;
await _viewer!.setPostProcessing(true);
_unlitMaterial = await _viewer!.createUnlitMaterialInstance();
_litMaterial = await _viewer!.createUbershaderMaterialInstance();
_unlitMaterial =
await FilamentApp.instance!.createUnlitMaterialInstance();
_litMaterial =
await FilamentApp.instance!.createUbershaderMaterialInstance();
await _viewer!.addDirectLight(
DirectLight.sun(
intensity: 50000,
@@ -81,7 +83,9 @@ class _MyHomePageState extends State<MyHomePage> {
materialInstances: [_unlitMaterial],
);
await _viewer!.setCameraPosition(0, 0, 5);
final view = await viewer.getActiveCamera();
await view.lookAt(Vector3(0, 0, 5));
await _viewer!.setRendering(true);
setState(() {});
});
@@ -95,18 +99,18 @@ class _MyHomePageState extends State<MyHomePage> {
await materialInstance.setParameterInt("baseColorIndex", 0);
var imageBuffer = await rootBundle.load("assets/background.png");
var imageData = imageBuffer.buffer.asUint8List(imageBuffer.offsetInBytes);
_image = await _viewer!.decodeImage(imageData);
_image = await FilamentApp.instance!.decodeImage(imageData);
var width = await _image!.getWidth();
var height = await _image!.getHeight();
_texture = await _viewer!.createTexture(width, height);
_texture = await FilamentApp.instance!.createTexture(width, height);
await _texture!.setLinearImage(
_image!,
PixelDataFormat.RGBA,
PixelDataType.FLOAT,
);
final textureSampler = await _viewer!.createTextureSampler();
final textureSampler = await FilamentApp.instance!.createTextureSampler();
await materialInstance.setParameterTexture(
"baseColorMap",
_texture!,
@@ -134,7 +138,7 @@ class _MyHomePageState extends State<MyHomePage> {
if (_viewer != null) ...[
Positioned.fill(
child: ThermionListenerWidget(
inputHandler: DelegateInputHandler.fixedOrbit(_viewer!),
inputHandler: DelegateInputHandler.fixedOrbit(_viewer!, sensitivity: InputSensitivityOptions(mouseSensitivity: 0.01)),
child: ThermionWidget(viewer: _viewer!),
),
),
@@ -156,9 +160,7 @@ class _MyHomePageState extends State<MyHomePage> {
ElevatedButton(
onPressed: () async {
unlit = !unlit;
setState(() {
});
setState(() {});
await _asset.setMaterialInstanceAt(
unlit ? _unlitMaterial : _litMaterial,
);
@@ -168,8 +170,8 @@ class _MyHomePageState extends State<MyHomePage> {
),
ElevatedButton(
onPressed: () async {
var materialInstance = await _viewer!
.getMaterialInstanceAt(_asset.entity, 0);
var materialInstance =
await _asset.getMaterialInstanceAt();
await _setMaterialTexture(materialInstance);
},
child: Text("Apply texture"),

View File

@@ -14,7 +14,7 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/thermion_flutter/macos
SPEC CHECKSUMS:
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1
thermion_flutter: debb51a861788780ce40e11e4400c2e5a8681fdf
PODFILE CHECKSUM: 1888651be91a8ad58692c1add9ce24279fd4e950

View File

@@ -558,7 +558,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
@@ -641,7 +641,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
@@ -691,7 +691,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;

View File

@@ -11,15 +11,8 @@ dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.8
thermion_dart:
path: ../../../thermion_dart
thermion_flutter:
path: ../../../thermion_flutter/thermion_flutter
thermion_flutter_method_channel:
path: ../../../thermion_flutter/thermion_flutter_method_channel
thermion_flutter_platform_interface:
path: ../../../thermion_flutter/thermion_flutter_platform_interface
dev_dependencies:
flutter_test:
sdk: flutter
@@ -35,6 +28,8 @@ dependency_overrides:
path: ../../../thermion_flutter/thermion_flutter_method_channel
thermion_flutter_platform_interface:
path: ../../../thermion_flutter/thermion_flutter_platform_interface
thermion_flutter_web:
path: ../../../thermion_flutter/thermion_flutter_web
flutter:
uses-material-design: true