BabylonJS / BabylonReactNative

Build React Native applications with the power of Babylon Native
MIT License
381 stars 61 forks source link

Unable to render a model with @babylonjs/react-native 0.4.0-alpha.37 or newer #312

Closed chun-baoluo closed 2 years ago

chun-baoluo commented 2 years ago

Describe the bug Managed to find another bug (for both iOS and Android) with new versions of @babylonjs/react-native. If I try to open certain model with @babylonjs/react-native@0.4.0-alpha.37 or newer, the app won't render anything. It just shows black screen. I tested @babylonjs/react-native@0.4.0-alpha.29 out of curiosity and everything worked. It seems like something broke in newer versions. The only error I see in terminal window of my test app is "TypeError: undefined is not an object (evaluating '_native.NativeDataStream.VALIDATION_ENABLED')".

The only difference between my old models and new model is that later was exported using Cinema 4D glTF Exporter instead of Khronos glTF Blender plugin. However, both models display correctly on https://sandbox.babylonjs.com.

To Reproduce Steps to reproduce the behavior:

  1. Build and open latest commit of my sample app: https://github.com/star-collector/babylon-playground
  2. Everything renders black, message TypeError: undefined is not an object (evaluating '_native.NativeDataStream.VALIDATION_ENABLED') appears in the terminal window
  3. Rollback babylon package to @babylonjs/react-native@0.4.0-alpha.29 in package.json file
  4. Everything renders as it should

Expected behavior Everything renders correctly

Screenshots How app looks like with @babylonjs/react-native@0.4.0-alpha.29:

photo_2021-11-16_12-17-23

How app looks like with @babylonjs/react-native@0.4.0-alpha.37 or older:

photo_2021-11-16_12-17-23 (2)

Other

ryantrem commented 2 years ago

Will you please try @babylonjs/react-native@0.4.0-alpha.43 with @babylonjs/core@5.0.0-alpha.60 and @babylonjs/loaders@5.0.0-alpha.60?

chun-baoluo commented 2 years ago

Will you please try @babylonjs/react-native@0.4.0-alpha.43 with @babylonjs/core@5.0.0-alpha.60 and @babylonjs/loaders@5.0.0-alpha.60?

No, the app still doesn't render anything. However, the behaviour is somewhat different. If alpha.37 just rendered black screen, alpha.43 renders standard babylonjs-playground background . It seems like the app just froze at some point, FPS is stuck at 11 on my phone, but nothing is rendering and the app does not seem to respond (or at least babylonjs part doesn't respond). Also, no other meshes are being rendered as well, not just new character model. And there is no error message of any kind in the terminal window.

photo_2021-11-16_22-24-35

chun-baoluo commented 2 years ago

adb logcat also doesn't show anything interesting.

bghgary commented 2 years ago

This is due to the model having morph targets which tries to create a 2d texture array. This isn't hooked up. This is tracked by https://github.com/BabylonJS/BabylonNative/issues/923. There is however a workaround as noted in the issue. Put this somewhere before you load the model and it will disable texture arrays.

BABYLON.MorphTargetManager.EnableTextureStorage = false;

There is something else that is wrong though. The JavaScript should be throwing an error like:

Uncaught Error: Unable to get property 'TEXTURE_2D_ARRAY' of undefined or null reference

This is what happens in the Babylon Native Playground when loading this model. Something in Babylon React Native is eating this error. @ryantrem Any thoughts?

chun-baoluo commented 2 years ago

@bghgary Thanks, it solved my problem.