Since 6.4.0起iOS地图SDK支持3D模型(BMK3DModelOverlay)绘制,用于在地图上展示3D模型,目前支持.obj+.mtl文件格式和.gltf模型加载。Since 6.5.7起iOS地图SDK支持.gltf+.bin模型加载,并支持动画播放参数控制。
BMK3DModelOption *option = [[BMK3DModelOption alloc] init];option.modelName = @"among_us";option.scale = 1;option.modelPath = [NSString stringWithFormat:@"%@/Model3D", [NSBundle mainBundle].bundlePath];_modelOverlay = [BMK3DModelOverlay modelOverlayWithCenterCoordinate:CLLocationCoordinate2DMake(39.914838, 116.40299) option:option];BMK3DModelOption *option = [[BMK3DModelOption alloc] init];option.scale = 100;option.modelName = @"batman";option.zoomFixed = YES;option.modelPath = [NSString stringWithFormat:@"%@/Model3D", [NSBundle mainBundle].bundlePath];_modelBatManOverlay = [BMK3DModelOverlay modelOverlayWithCenterCoordinate:CLLocationCoordinate2DMake(39.914838, 116.40499) option:option];/**向地图View添加Overlay,需要实现BMKMapViewDelegate的-mapView:viewForOverlay:方法来生成标注对应的View@param overlay 要添加的overlay*/[_mapView addOverlays:@[self.modelOverlay, self.modelBatManOverlay]];
#pragma mark - BMKMapViewDelegate/**根据overlay生成对应的BMKOverlayView@param mapView 地图View@param overlay 指定的overlay@return 生成的覆盖物View*/- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay {if ([overlay isKindOfClass:[BMK3DModelOverlay class]]) {//初始化一个overlay并返回相应的BMK3DModelOverlayView的实例BMK3DModelOverlayView *modelOverlayView = [[BMK3DModelOverlayView alloc] initWith3DModelOverlay:overlay];return modelOverlayView;}return nil;}
/// 以下只支持带有animations标签的GLTF模型/// 模型动画是否可用,默认为NO:添加后不执行动画,值为YES时添加后立即按照配置参数执行动画,since 6.5.7@property (nonatomic, assign) BOOL animationIsEnable;/// 模型动画重复执行次数,默认0:动画将一直执行动画,since 6.5.7@property (nonatomic, assign) NSInteger animationRepeatCount;/// 当前模型动画索引值,since 6.5.7@property (nonatomic, assign) NSInteger animationIndex;/// 模型动画倍速,默认:1.0,since 6.5.7@property (nonatomic, assign) CGFloat animationSpeed;
BMK3DModelOption *option = [[BMK3DModelOption alloc] init];option.scale = 2;option.modelName = @"scenes";option.type = BMK3DModelTypeGLTF;option.zoomFixed = YES;option.rotateX = 90;option.animationIsEnable = YES;option.animationIndex = 0;option.animationSpeed = 1;option.animationRepeatCount = 0;option.modelPath = [NSString stringWithFormat:@"%@/Model3D", [NSBundle mainBundle].bundlePath];
效果如下:
上一篇
下一篇
本篇文章对您是否有帮助?