Skip to content

Commit 9cef5e7

Browse files
committed
chore(example): change eye color on btn press
1 parent 660c08b commit 9cef5e7

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

package/example/src/ChangeMaterials.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22
import { useEffect, useRef } from 'react'
33

4-
import { Platform, StyleSheet, View } from 'react-native'
4+
import { Button, Platform, StyleSheet, View } from 'react-native'
55
import { Filament, useEngine, Float3, useRenderCallback, useAsset, useModel, useRenderableManager } from 'react-native-filament'
66

77
const penguModelPath = Platform.select({
@@ -40,7 +40,7 @@ export function ChangeMaterials() {
4040
const blueRightEyeBuffer = useAsset({ path: rightEyeTexturePath })
4141

4242
const penguAsset = pengu.state === 'loaded' ? pengu.asset : undefined
43-
useEffect(() => {
43+
const changeEyes = React.useCallback(() => {
4444
if (penguAsset == null || blueLeftEyeBuffer == null || blueRightEyeBuffer == null) return
4545

4646
const leftEye = penguAsset.getFirstEntityByName('Brown Dark Stylised.003')
@@ -58,7 +58,7 @@ export function ChangeMaterials() {
5858

5959
renderableManager.changeMaterialTextureMap(leftEye, 'Eye_Left.001', blueLeftEyeBuffer, 'sRGB')
6060
renderableManager.changeMaterialTextureMap(rightEye, 'Eye_Right.002', blueRightEyeBuffer, 'sRGB')
61-
}, [blueLeftEyeBuffer, blueRightEyeBuffer, engine, penguAsset, renderableManager])
61+
}, [blueLeftEyeBuffer, blueRightEyeBuffer, penguAsset, renderableManager])
6262

6363
const light = useAsset({ path: indirectLightPath })
6464
useEffect(() => {
@@ -91,6 +91,7 @@ export function ChangeMaterials() {
9191
return (
9292
<View style={styles.container}>
9393
<Filament style={styles.filamentView} engine={engine} />
94+
<Button title="Change Eyes" onPress={changeEyes} />
9495
</View>
9596
)
9697
}
@@ -103,10 +104,4 @@ const styles = StyleSheet.create({
103104
flex: 1,
104105
backgroundColor: 'lightblue',
105106
},
106-
btnContainer: {
107-
height: 200,
108-
width: '100%',
109-
position: 'absolute',
110-
bottom: 0,
111-
},
112107
})

0 commit comments

Comments
 (0)