BeanstalkBlue Posted February 24, 2017 Share Posted February 24, 2017 let mat1 : BABYLON.StandardMaterial = new BABYLON.StandardMaterial("mat1", scene); let mesh1 = new BABYLON.Mesh("mesh1", scene); mesh1.material = mat1; mesh1.material.opacityTexture = null; // '<-- This is not allowed.' In this situation TypeScript complains that we can't set opacityTexture because mesh1.material is of type BABYLON.Material (not BABYLON.StandardMaterial). I could of course just do "mat1.opacityTexture = null", but what is the typical way to handle this type of situation in TypeScript if I really want to access the material via "mesh1.material"? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 24, 2017 Share Posted February 24, 2017 (<BABYLON.StandardMaterial> mesh1.material).opacityTexture = null; casting has no impact on generated javascript BeanstalkBlue 1 Quote Link to comment Share on other sites More sharing options...
inteja Posted February 24, 2017 Share Posted February 24, 2017 I'm a TS newbie as well but I read somewhere that the "as" syntax for casting is preferred e.g. mesh1.material as BABYLON.StandardMaterial Probably makes no difference though. Quote Link to comment Share on other sites More sharing options...
oxyflour Posted February 25, 2017 Share Posted February 25, 2017 // when creating the material let mesh1 = new BABYLON.Mesh("mesh1", scene); let mat1 = mesh1.material = new BABYLON.StandardMaterial("mat1", scene); mat1.opacityTexture = null; // when using the material let mat1 = mesh1.material as StandMaterial; mat1.opacityTexture = null; // in a single line (mesh1.material as StandMaterial).opacityTexture = null That's the ways I wrote in my project Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.