Closed MarlonJD closed 2 months ago
Hi! 👋
Yes, you can navigate to a MeshPrimitive
that has the Material
you wish to modify and change any properties:
final dashModel = await Node.fromAsset('build/models/dash.model');
final visibleNode = modelNode.getChildByNamePath(['DashArmature', 'Dash'])!;
final material = visibleNode.mesh!.primitives[0].material as PhysicallyBasedMaterial;
material.metallicRoughnessTexture = null;
material.metallicFactor = 0;
material.roughnessFactor = 0;
material.emissiveFactor = const Color.fromARGB(255, 100, 255, 0);
scene.add(modelNode);
Keep in mind that the same Material
instance may be referenced by many different meshes across the scene.
The "factor" parameters are multiplied with the corresponding texture channel(s). But if the texture is null
, then the factor directly/fully controls the property.
The alpha channel of the baseColorFactor
controls translucency:
material.baseColorFactor = material.baseColorFactor.withAlpha(100);
Textures are explicitly uploaded to the GPU, and there are a couple of helpers to create them from asset strings and ui.Images in package:flutter_scene/asset_helpers.dart
:
// Upload a texture directly from an image asset string.
material.baseColorTexture = await gpuTextureFromAsset('mytexture.png');
// Upload a texture from a ui.Image.
material.normalTexture = await gpuTextureFromImage(myimage);
Wow, it was so much detailed answer, thank you so much
Hey there 👋. Is there any way to change textures of the material and material's metallic, roughness, alpha values in runtime?