Skip to content

Conversation

KevinRohn
Copy link

@KevinRohn KevinRohn commented Jan 10, 2021

I've implemented the ability to change the base color of the model.

There is a ModelViewerColorController which can be used to call the JavaScript function to change the base color of the model.
Currently it only supports the auto detected base color. As I understand the documentation, the auto detection selects the largest area of the model. So if there is just a simple model, you can change the color of the whole object. Otherwise the largest object will just be changed.

Example usage:

// ....
ModelViewerColorController _colorController;

// ....
@override
void initState() {
    super.initState();
    _colorController = ModelViewerColorController();
}

// ....
Future void changeColor() async {
    await _colorController.changeColor("0,1,1,1");
}

// ....
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("Model Viewer")),
        body: ModelViewer(
          src: 'https://modelviewer.dev/shared-assets/models/Astronaut.glb',
          enableColorChange: true,
          colorController: _colorController,
          alt: "A 3D model of an astronaut",
          ar: true,
          autoRotate: true,
          cameraControls: true,
        ),
      ),
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant