简体   繁体   中英

Getting a (THREE.js) 3D model from a webview to my Native-React (augmented reality) app

For the past couple of weeks i'm trying to figure out how to include an external web app that does 3d modelling(Through THREE.js) into a viro react app. I tried webview and that works, but i need the model to be imported into my Viro App. I tried the WebViewBridge module (which in theory could send the .obj file as a string to my app from the webview so i can show it in AR) But it doesn't seem to work on the Native react version that Viro uses.

            <View >
                <WebViewBridge                      
                    ref="webviewbridge"                 
                    source={{uri: 'http://www.google.com'}}>
                </WebViewBridge>
            </View>

When i change the "webviewbridge" for "webview" it works, it shows google in a new view if i press a button. My aim is to have the web app shown, and on a button click i can get the presented 3D model and show it in augmented reality (a feature of viro-react).

Technical info:

My bad, it uses "injectedJavaScript" prop now.

let jsCode = " document.querySelector('#myContent').style.backgroundColor = 'green';";

    return(
            <View style={localStyles.viroContainer}> //this just sets flex to 1


                <WebView
                    source={{ html: "<h1 id='myContent'>Hello</h1>" }}
                    style={{ flex: 1 }} 
                    ref={ webview => { this.webview = webview; }}
                    injectedJavaScript={jsCode}
                    javaScriptEnabled={true}>
                </WebView>

                <TouchableHighlight style={localStyles.overlayButton} 
                    onPress={this.sendMessageToWebView2} underlayColor='transparent'>
                        <Text>Send message to WebView</Text>
                </TouchableHighlight>

            </View>


        );
    }

I managed to get an alert with a string in my webview now on the buttonclick (sendmessagetowebview2), But i havent managed to change the injectedJavaScript yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM