brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
809 stars 102 forks source link

Standard Material diffuse texture no uoffset and uscale property #264

Closed jinincarnate closed 1 year ago

jinincarnate commented 1 year ago

how to set a textures uOffset or uScale property for tiling purpose

brianzinn commented 1 year ago

@jinincarnate How are you doing it now - ie: this does not work?

<texture
    url="assets/textures/diffuse.png"
    assignTo="diffuseTexture"
    uScale={textureUScale}
    uOffset={textureUOffset}
/>

ref: https://doc.babylonjs.com/typedoc/classes/BABYLON.Texture#uScale

jinincarnate commented 1 year ago

<standardMaterial name="media_material" roughness={1} emissiveColor={Color3.FromHexString('#000000')} specularColor={Color3.Black()} ref={mediaMaterialRef} />

`const [mediaMaterial, setMediaMaterial] = useState<StandardMaterial | null>( null );

const mediaMaterialRef = useCallback((node: any) => { if (node) { setMediaMaterial(node); } }, []);`

mediaMaterial.diffuseTexture. doesn't have uOffset

brianzinn commented 1 year ago

can you share a working codesandbox or babylonjs playground?

DefaultV commented 1 year ago

This is because the type for the diffuseTexture is BaseTexture, which doesn't have the property. If you cast it, you should get your available options: (material.diffuseTexture as Texture).uScale = 2

https://doc.babylonjs.com/typedoc/classes/BABYLON.BaseTexture

jinincarnate commented 1 year ago

Thank you so much that was the exact case

brianzinn commented 1 year ago

you should also be able to do:

<standardMaterial name="media_material" ,,, >
  <texture assignFrom='diffuseTexture' uScale={2} />
</standardMaterial>