Aks*_*are 5 javascript android 3d-model reactjs react-native
我想在一个屏幕上同时使用react-native-gl-model-view 中的2 个“3d 对象模型” 。当我使用单个 3d 对象时,它工作正常,但一旦我使用两个或两个以上,每个 3d 对象模型就会开始闪烁,几秒钟后应用程序崩溃。
这是它如何处理多个 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',
},
});
Run Code Online (Sandbox Code Playgroud)
注意 1:要在 Android 上加载模型,您需要将模型放在android/app/src/main/assets文件夹中。如果尚不存在,则创建一个新文件夹。
如果您想尝试以下代码:
npm install react-native-gl-model-view --savenpm run android抱歉,我想向您展示 expo小吃中的代码,但它不起作用并显示以下错误:
requireNativeComponent: "RNGLModelView" was not found in the UIManager.
有时包未链接到项目或需要重新构建。如果您确定已完成添加该文件的所有步骤,请再次将该包链接到项目:
react-native link react-native-gl-model-view
Run Code Online (Sandbox Code Playgroud)
如果这不起作用,如果您有 android studio ,请在模拟器上重新安装该项目。
| 归档时间: |
|
| 查看次数: |
249 次 |
| 最近记录: |