-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: allow 'assignTo' for textures to Scene
- Loading branch information
Showing
23 changed files
with
5,062 additions
and
2 deletions.
There are no files selected for viewing
Binary file added
BIN
+1.76 MB
devtool/loader/src/codesandbox-templates/ts/public/assets/kitti/000000.bin
Binary file not shown.
Binary file added
BIN
+215 KB
devtool/loader/src/codesandbox-templates/ts/public/assets/models/atom.glb
Binary file not shown.
4,916 changes: 4,916 additions & 0 deletions
4,916
devtool/loader/src/codesandbox-templates/ts/public/assets/textures/LateSunset.3dl
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+16 MB
devtool/loader/src/codesandbox-templates/ts/public/assets/textures/SpecularHDR.dds
Binary file not shown.
Binary file added
BIN
+642 KB
...der/src/codesandbox-templates/ts/public/assets/textures/TropicalSunnyDay_nx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+223 KB
...der/src/codesandbox-templates/ts/public/assets/textures/TropicalSunnyDay_ny.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+741 KB
...der/src/codesandbox-templates/ts/public/assets/textures/TropicalSunnyDay_nz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+615 KB
...der/src/codesandbox-templates/ts/public/assets/textures/TropicalSunnyDay_px.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+641 KB
...der/src/codesandbox-templates/ts/public/assets/textures/TropicalSunnyDay_py.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+662 KB
...der/src/codesandbox-templates/ts/public/assets/textures/TropicalSunnyDay_pz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+587 KB
devtool/loader/src/codesandbox-templates/ts/public/assets/textures/albedo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1 MB
devtool/loader/src/codesandbox-templates/ts/public/assets/textures/environment.dds
Binary file not shown.
Binary file added
BIN
+343 KB
devtool/loader/src/codesandbox-templates/ts/public/assets/textures/environment.env
Binary file not shown.
Binary file added
BIN
+619 KB
devtool/loader/src/codesandbox-templates/ts/public/assets/textures/grass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.4 KB
devtool/loader/src/codesandbox-templates/ts/public/assets/textures/mr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+94.2 KB
...ool/loader/src/codesandbox-templates/ts/public/assets/textures/reflectivity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/static/content/examples/basic/assign-to/AssignTo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Color3 } from '@babylonjs/core/Maths/math.color' | ||
import { Vector3 } from '@babylonjs/core/Maths/math.vector' | ||
import React from 'react' | ||
import { Engine, Scene } from 'react-babylonjs' | ||
|
||
export const FromInstance = () => ( | ||
<div className="App"> | ||
<Engine antialias adaptToDeviceRatio canvasId="babylon-js"> | ||
<Scene> | ||
<arcRotateCamera | ||
name="camera1" | ||
target={Vector3.Zero()} | ||
minZ={0.001} | ||
alpha={0} | ||
beta={Math.PI / 2} | ||
radius={5} | ||
lowerBetaLimit={2} | ||
upperRadiusLimit={5} | ||
/> | ||
<hemisphericLight name="light1" intensity={0.9} direction={Vector3.Down()} /> | ||
<sphere name="sphere1" segments={16} diameter={2}> | ||
<pbrMaterial | ||
name="pbr" | ||
albedoColor={new Color3(1, 0.766, 0.336)} | ||
metallic={1.0} | ||
roughness={1.0} | ||
useRoughnessFromMetallicTextureAlpha={false} | ||
useRoughnessFromMetallicTextureGreen | ||
useMetallnessFromMetallicTextureBlue | ||
> | ||
<texture url="../../assets/textures/mr.jpg" assignTo="metallicTexture" /> | ||
</pbrMaterial> | ||
</sphere> | ||
<cubeTexture | ||
level={0.5} | ||
assignTo="environmentTexture" | ||
rootUrl="../../assets/textures/environment.env" | ||
/> | ||
</Scene> | ||
</Engine> | ||
</div> | ||
) | ||
|
||
export default FromInstance |
59 changes: 59 additions & 0 deletions
59
packages/static/content/examples/basic/assign-to/EnvironmentTexture.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { CubeTexture } from '@babylonjs/core/Materials/Textures/cubeTexture' | ||
import { Color3 } from '@babylonjs/core/Maths/math.color' | ||
import { Vector3 } from '@babylonjs/core/Maths/math.vector' | ||
import React, { useEffect, useState, useRef } from 'react' | ||
import { Engine, Scene, useEngine } from 'react-babylonjs' | ||
|
||
const MyScene = () => { | ||
const engine = useEngine() | ||
const [_, setTextureReady] = useState(false) | ||
const cubeTextureRef = useRef<undefined | CubeTexture>() | ||
|
||
useEffect(() => { | ||
if (engine !== null) { | ||
console.log('engine', engine) | ||
cubeTextureRef.current = new CubeTexture('../../assets/textures/environment.env', engine) | ||
setTextureReady(true) // force a re-render to attach | ||
console.log('texture:', cubeTextureRef.current) | ||
} | ||
}, [engine]) | ||
|
||
return ( | ||
<Scene environmentTexture={cubeTextureRef.current}> | ||
<arcRotateCamera | ||
name="camera1" | ||
target={Vector3.Zero()} | ||
minZ={0.001} | ||
alpha={0} | ||
beta={Math.PI / 2} | ||
radius={5} | ||
lowerBetaLimit={2} | ||
upperRadiusLimit={5} | ||
/> | ||
<hemisphericLight name="light1" intensity={0.9} direction={Vector3.Down()} /> | ||
<sphere name="sphere1" segments={16} diameter={2}> | ||
<pbrMaterial | ||
name="pbr" | ||
albedoColor={new Color3(1, 0.766, 0.336)} | ||
metallic={1.0} | ||
roughness={1.0} | ||
useRoughnessFromMetallicTextureAlpha={false} | ||
useRoughnessFromMetallicTextureGreen | ||
useMetallnessFromMetallicTextureBlue | ||
> | ||
<texture url="../../assets/textures/mr.jpg" assignTo="metallicTexture" /> | ||
</pbrMaterial> | ||
</sphere> | ||
</Scene> | ||
) | ||
} | ||
|
||
export const FromInstance = () => ( | ||
<div className="App"> | ||
<Engine antialias adaptToDeviceRatio canvasId="babylon-js"> | ||
<MyScene /> | ||
</Engine> | ||
</div> | ||
) | ||
|
||
export default FromInstance |
30 changes: 30 additions & 0 deletions
30
packages/static/content/examples/basic/assign-to/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: 'assignTo' | ||
--- | ||
|
||
This is the example to show the custom property `assignTo`, although it is used | ||
in many examples it is provided here as a single concept. | ||
|
||
NOTE: you can use dots like "mesh.material" and it will follow the objects | ||
properties as long as they exist. | ||
|
||
```jsx | ||
<Scene> | ||
... | ||
<cubeTexture | ||
assignTo="environmentTexture" | ||
rootUrl={'/assets/environment.env'} | ||
/> | ||
</Scene> | ||
``` | ||
|
||
[devtool:AssignTo.tsx] | ||
|
||
The above was used to assign the `environmentTexture`, which is the same as | ||
providing a value to the prop as we do in the scene below: | ||
|
||
```jsx | ||
<Scene environmentTexture={cubeTextureInstance}>...</Scene> | ||
``` | ||
|
||
[devtool:EnvironmentTexture.tsx] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.