Jump to content

A newbie TypeScript question.


Recommended Posts

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"?

Link to comment
Share on other sites

// 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 :)

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...