Jump to content

Need a Typescript compatible way to add a property to Mesh


JCPalmer
 Share

Recommended Posts

I need to store a boolean property in a BABYLON.Mesh that is not defined in it, for cloning purposes.  This is no problem for javascript:

meshVar.castShadows = true;

Tower of Babel generates both a .js and .ts.  The above line will not compile.  Was looking @ .bind, but this seems to be for functions.  Anyone know the way to do this?  A related question is how would you then access it later?

Link to comment
Share on other sites

Works.  Also, am generating this module function to access castShadows, for anyone searching in future:

    function freshenShadowRenderLists(scene) {        if (!BABYLON.Engine.Version || Number(BABYLON.Engine.Version.substr(0, BABYLON.Engine.Version.lastIndexOf("."))) < 2.0) throw "Babylon version too old";        BABYLON.Tools.Log('In freshenShadowRenderLists');        var renderList = [];        for (var i = 0; i < scene.meshes.length; i++){            if (scene.meshes[i]["castShadows"])                renderList.push(scene.meshes[i]);        }        for (var i = 0; i < scene.lights.length; i++){            if (scene.lights[i]._shadowGenerator)                scene.lights[i]._shadowGenerator.getShadowMap().renderList = renderList;        }    }    module_name.freshenShadowRenderLists = freshenShadowRenderLists;

Am in testing phase for TOB 2.0.  Have modified the first test to do mesh factory cloning. 

https://googledrive.com/host/0B6-s6ZjHyEwUUW9HX1lqbnFLRzA

 

Looking at console: 

  1. Gus mesh requested: Gus mesh & children meshes instanced
  2. ShadowGenerator built with embedded freshenShadowRenderLists() call.
  3. Gus mesh requested: Gus mesh & children meshes cloned

Since Cloned after freshenShadowRenderLists(), no shadow for it.

First Click "Orphan - Conceive" toggle to see shadows of kids with parent

Click "Refresh Shadows" to get clone shadowed

 

The reason I am publishing this is I have changed to a spot light, which handles shadows in BJS 2.0.  There is a minor problem though.  If the very center of the spot is in shadow, the diffuse light still comes through.  Looks like Gus has a bullet hole.

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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