mapbox-maps-flutter icon indicating copy to clipboard operation
mapbox-maps-flutter copied to clipboard

This is not an issue! 3D Models in this version!

Open ezesoftchao opened this issue 2 years ago • 11 comments

@yunikkk

image

I'm thinking of doing a PR by adding ModelSource for the next version.

ezesoftchao avatar Sep 22 '23 17:09 ezesoftchao

any news thanks

fodedoumbouya avatar Nov 04 '23 21:11 fodedoumbouya

any update?

favazHF avatar Mar 13 '24 18:03 favazHF

you can use flutter_map and then The Marker.builder property will work with any widget Regardless of whether it's 2D or 3D. So anything inside the builder is out of scope of FM @favazHF

fodedoumbouya avatar Mar 14 '24 09:03 fodedoumbouya

@fodedoumbouya @favazHF

await mapController.style.addStyleSource(
          'test3d',
          jsonEncode(
            {
              'type': 'model',
              'models': {
                'defaultModel': {
                  'uri':
                      'https://github.com/ezesoftchao/soscuba/raw/main/confort_last.glb',
                  'orientation': [0.0, 0.0, 90.0],
                  'position': [
                    -82,
                    23,
                  ]
                }
              },
            },
          ),
        );
await mapController.style
            .styleLayerExists('test3d')
            .then((value) async {
          if (!value) {
            final layer = {
              'id': 'test3d',
              'source': 'test3d',
              'visibility': 'visible',
              'type': 'model'
            };
            await mapController.style
                .addPersistentStyleLayer(json.encode(layer), null);
            final properties = {
              'paint': {
                'model-rotation': [1.0, 1.0, bearing],
                'model-opacity': 1.0,
                'model-translation': [0.0, 0.0, 0.0],
                'model-scale': [
                  'interpolate',
                  ['exponential', 0.5],
                  ['zoom'],
                  12,
                  [
                    'literal',
                    [80, 80, 80]
                  ],
                  13,
                  [
                    'literal',
                    [60, 60, 60]
                  ],
                  14,
                  [
                    'literal',
                    [50, 50, 50]
                  ],
                  19,
                  [
                    'literal',
                    [3, 3, 3]
                  ],
                  22,
                  [
                    'literal',
                    [1, 1, 1]
                  ],
                  23,
                  [
                    'literal',
                    [0.2, 0.2, 0.2]
                  ]
                ],
                'model-type': 'common-3d'
              },
            };
            await mapController.style
                .styleLayerExists(
              'test3d',
            )
                .then((exist) async {
              if (exist) {
                try {
                  await mapController.style.setStyleLayerProperties(
                    'test3d',
                    json.encode(properties),
                  );
                } catch (e) {
                  if (kDebugMode) {
                    print(e);
                  }
                }
              }
            });
          }
        });

ezesoftchao avatar Jun 12 '24 20:06 ezesoftchao

thank you man @ezesoftchao

fodedoumbouya avatar Jun 13 '24 11:06 fodedoumbouya

thank you man @ezesoftchao

don't worry, you must test first with the glb example, later gltf

ezesoftchao avatar Jun 13 '24 13:06 ezesoftchao

@evil159 Hi bro! I've seen the new model layer. Could you add a model source object for 3D in future features, like the suggestion in this suggestion: https://github.com/mapbox/mapbox-maps-flutter/issues/243#issue-1909283287

ezesoftchao avatar Jun 13 '24 19:06 ezesoftchao

@fodedoumbouya @favazHF

await mapController.style.addStyleSource(
          'test3d',
          jsonEncode(
            {
              'type': 'model',
              'models': {
                'defaultModel': {
                  'uri':
                      'https://github.com/ezesoftchao/soscuba/raw/main/confort_last.glb',
                  'orientation': [0.0, 0.0, 90.0],
                  'position': [
                    -82,
                    23,
                  ]
                }
              },
            },
          ),
        );
await mapController.style
            .styleLayerExists('test3d')
            .then((value) async {
          if (!value) {
            final layer = {
              'id': 'test3d',
              'source': 'test3d',
              'visibility': 'visible',
              'type': 'model'
            };
            await mapController.style
                .addPersistentStyleLayer(json.encode(layer), null);
            final properties = {
              'paint': {
                'model-rotation': [1.0, 1.0, bearing],
                'model-opacity': 1.0,
                'model-translation': [0.0, 0.0, 0.0],
                'model-scale': [
                  'interpolate',
                  ['exponential', 0.5],
                  ['zoom'],
                  12,
                  [
                    'literal',
                    [80, 80, 80]
                  ],
                  13,
                  [
                    'literal',
                    [60, 60, 60]
                  ],
                  14,
                  [
                    'literal',
                    [50, 50, 50]
                  ],
                  19,
                  [
                    'literal',
                    [3, 3, 3]
                  ],
                  22,
                  [
                    'literal',
                    [1, 1, 1]
                  ],
                  23,
                  [
                    'literal',
                    [0.2, 0.2, 0.2]
                  ]
                ],
                'model-type': 'common-3d'
              },
            };
            await mapController.style
                .styleLayerExists(
              'test3d',
            )
                .then((exist) async {
              if (exist) {
                try {
                  await mapController.style.setStyleLayerProperties(
                    'test3d',
                    json.encode(properties),
                  );
                } catch (e) {
                  if (kDebugMode) {
                    print(e);
                  }
                }
              }
            });
          }
        });

Thanks you @ezesoftchao it works like a charm !

I've some questions :

• Can I use a local asset ? • It works with the mapbox gltf model too : https://docs.mapbox.com/mapbox-gl-js/assets/34M_17/34M_17.gltf. But when I save this gltf and your glb exemple files on Firebase Storage nothing appear. Do you have an idea ? CORS problem ?

Regards,

MapleNoise avatar Jul 15 '24 15:07 MapleNoise

@fodedoumbouya @favazHF

await mapController.style.addStyleSource(
          'test3d',
          jsonEncode(
            {
              'type': 'model',
              'models': {
                'defaultModel': {
                  'uri':
                      'https://github.com/ezesoftchao/soscuba/raw/main/confort_last.glb',
                  'orientation': [0.0, 0.0, 90.0],
                  'position': [
                    -82,
                    23,
                  ]
                }
              },
            },
          ),
        );
await mapController.style
            .styleLayerExists('test3d')
            .then((value) async {
          if (!value) {
            final layer = {
              'id': 'test3d',
              'source': 'test3d',
              'visibility': 'visible',
              'type': 'model'
            };
            await mapController.style
                .addPersistentStyleLayer(json.encode(layer), null);
            final properties = {
              'paint': {
                'model-rotation': [1.0, 1.0, bearing],
                'model-opacity': 1.0,
                'model-translation': [0.0, 0.0, 0.0],
                'model-scale': [
                  'interpolate',
                  ['exponential', 0.5],
                  ['zoom'],
                  12,
                  [
                    'literal',
                    [80, 80, 80]
                  ],
                  13,
                  [
                    'literal',
                    [60, 60, 60]
                  ],
                  14,
                  [
                    'literal',
                    [50, 50, 50]
                  ],
                  19,
                  [
                    'literal',
                    [3, 3, 3]
                  ],
                  22,
                  [
                    'literal',
                    [1, 1, 1]
                  ],
                  23,
                  [
                    'literal',
                    [0.2, 0.2, 0.2]
                  ]
                ],
                'model-type': 'common-3d'
              },
            };
            await mapController.style
                .styleLayerExists(
              'test3d',
            )
                .then((exist) async {
              if (exist) {
                try {
                  await mapController.style.setStyleLayerProperties(
                    'test3d',
                    json.encode(properties),
                  );
                } catch (e) {
                  if (kDebugMode) {
                    print(e);
                  }
                }
              }
            });
          }
        });

Thanks you @ezesoftchao it works like a charm !

I've some questions :

• Can I use a local asset ? • It works with the mapbox gltf model too : https://docs.mapbox.com/mapbox-gl-js/assets/34M_17/34M_17.gltf. But when I save this gltf and your glb exemple files on Firebase Storage nothing appear. Do you have an idea ? CORS problem ?

Regards,

Possibly it's a CORS issue, I haven't actually tried with Firebase Storage.

ezesoftchao avatar Jul 15 '24 17:07 ezesoftchao

@evil159 Hi bro! I've seen the new model layer. Could you add a model source object for 3D in future features, like the suggestion in this suggestion: #243 (comment)

@ezesoftchao You can directly add model to the style and pass it to model layer: https://github.com/mapbox/mapbox-maps-flutter/blob/80d7b37cd9d04f40bd92adf9d6764f631b57c473/example/lib/model_layer.dart#L61-L64 https://github.com/mapbox/mapbox-maps-flutter/blob/80d7b37cd9d04f40bd92adf9d6764f631b57c473/example/lib/model_layer.dart#L73-L74

As for using local 3D assets for models, please note currently(as of 2.1.0) model paths are expected to be platform specific, we have addressed this issue in https://github.com/mapbox/mapbox-maps-flutter/pull/608, with introducing asset:// url scheme for 3D models, this change will be released in 2.2.0.

evil159 avatar Jul 17 '24 12:07 evil159

As for using local 3D assets for models, please note currently(as of 2.1.0) model paths are expected to be platform specific, we have addressed this issue in #608, with introducing asset:// url scheme for 3D models, this change will be released in 2.2.0.

Ohhhh, improvements I hadn't seen, sorry, it's just that I published the "issue" when that didn't exist yet, but I'm glad to know that there's full support now.

ezesoftchao avatar Jul 17 '24 13:07 ezesoftchao