You need to enable JavaScript to run this app. 使用react-native-gl-model-view渲染多个3D模型时出现闪烁、应用崩溃问题
优惠活动
大模型
产品
解决方案
定价
更多

使用react-native-gl-model-view渲染多个3D模型时出现闪烁、应用崩溃问题

react-native-gl-model-view 多实例渲染异常问题

问题现象

  • 单3D模型使用时,库的渲染功能完全正常
  • 同一页面同时加载2个及以上3D模型时,所有模型画面开始闪烁,数秒后应用直接崩溃

可复现代码

import React, {Component} from 'react';
import {StyleSheet, View, Animated} from 'react-native';

import ModelView from 'react-native-gl-model-view';
const AnimatedModelView = Animated.createAnimatedComponent(ModelView);

export default class Multiple extends Component {
  constructor() {
    super();
    this.state = {
      rotateZ: new Animated.Value(0),
    };
  }

  componentDidMount() {
    this.animate(0);
  }

  animate(iteration) {
    Animated.timing(this.state.rotateZ, {
      toValue: ++iteration * 360,
      useNativeDriver: true,
      duration: 5000,
    }).start(this.animate.bind(this, iteration++));
  }

  renderModel() {
    return (
      <AnimatedModelView
        model={{
          uri: 'demon.obj',
        }}
        texture={{
          uri: 'demon.png',
        }}
        tint={{r: 1.0, g: 1.0, b: 1.0, a: 1.0}}
        animate
        scale={0.01}
        translateZ={-2.5}
        rotateX={270}
        rotateZ={Animated.add(this.state.rotateZ, Math.random() * 360)}
        style={styles.model}
      />
    );
  }

  render() {
    return (
      <View style={styles.container}>
        <View style={styles.row}>
          {this.renderModel()}
          {this.renderModel()}
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  row: {
    flex: 1,
    flexDirection: 'row',
  },
  model: {
    flex: 1,
    backgroundColor: 'transparent',
  },
});

资源配置说明

安卓端加载模型时,需要将模型文件放置在android/app/src/main/assets文件夹下,若该目录不存在请先自行创建。代码中使用的示例模型、贴图资源可从该库官方示例项目的对应assets目录获取。

复现操作步骤

  • 执行npm install react-native-gl-model-view --save安装依赖
  • 按照上述路径要求放置模型、贴图文件
  • 新建Multiple.js文件并粘贴上述可复现代码
  • 执行npm run android运行项目

补充说明

曾尝试在Expo Snack中演示该代码,但运行报错无法正常使用,报错信息为:requireNativeComponent: "RNGLModelView" was not found in the UIManager


内容的提问来源于stack exchange,提问作者Akshay Pagare

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.25 08:15:04