Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide more details on usage #44

Open
jayzyaj opened this issue Jun 5, 2020 · 3 comments
Open

Provide more details on usage #44

jayzyaj opened this issue Jun 5, 2020 · 3 comments

Comments

@jayzyaj
Copy link

jayzyaj commented Jun 5, 2020

image

Please provide more details on the usage part especially on iOS. Where do we put it in Xcode?

Can we place it somewhere else in the src folder and import it like a static image using the require function?

Can we import it dynamically?

@kartiknegandhi
Copy link

In Xcode ,click the icon in the top left corner, (which says Show the project navigator),you have your project name out there, add the files in that(select copy files if needed option) and run it.

@jwrubel
Copy link

jwrubel commented Jun 23, 2020

Also you can use the expo-asset and expo-file-system libraries to load model and texture data through require. I quickly extracted this from a project - hopefully you can modify it for your scenario so you don't need to involve XCode:

import React, { useEffect, useState } from 'react';
import ModelView from 'react-native-gl-model-view';
import { Asset } from 'expo-asset';
import { EncodingType, readAsStringAsync } from 'expo-file-system';

const model = Asset.fromModule(require('./assets/3d/model.obj'));
const skin = Asset.fromModule(require('./assets/3d/skin.png'));

const App = () => {
  const [asset, setAsset] = useState({model: '', texture: ''});
  useEffect(() => {
    const loadModels = async () => {
      await model.downloadAsync();
      await skin.downloadAsync();
      const rawModelStr = await readAsStringAsync(model.localUri, {encoding: EncodingType.Base64});
      const modelWithHeader = `data:geometry/model;base64,${rawModelStr}`;
      const rawTextureStr = await readAsStringAsync(skin.localUri, {encoding: EncodingType.Base64});
      const textureWithHeader = `data:image/png;base64,${rawTextureStr}`;
      setAsset({model: modelWithHeader, texture: textureWithHeader})
    }
    loadModels();
  }, []);  
  return (
        <ModelView
          model={{
            uri: asset.model,
          }}
          texture={{
            uri: asset.texture,
          }}

          scale={0.001}
          translateZ={-1}
          rotateZ={0}
          style={{flex: 1, backgroundColor: 'transparent'}}
        />
  )
}

Note that if you use this option you'll need to add the file extensions for your models to the assetExts array in metro.config.js as well.

@ghost
Copy link

ghost commented Jan 5, 2021

hi @jwrubel ,
I download obj model file store in "DocumentDir" and use "path to file" as uri to display model. In iOS, it's OK but Android is empty. After that I try parse it to base64 as
const modelWithHeader = 'data:geometry/model;base64,${rawModelStr}';
And display this obj model file. I �get the same Android issue.
Did you occur this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants