Start a new topic
Answered

Converting instance to JsObject

Hello, I am trying to make shadows using Babylon and got stuck on pushing instance of Mesh into shadow generator's render list, which is defined as 


public List<AbstractMesh> renderList { get; set; }


Since it is defined as array, I can add meshes only by calling push, but when I try to call  

shadowGen.getShadowMap().renderList.push(mesh);

 

i get error 

cannot convert from 'BABYLON.Mesh' to 'DuoCode.Runtime.JsObject'


Is there any way to convert this or any other approach or is it problem in the Babylon plugin (that for example this array should be defined as some kind of List)?


Best Answer

I assume

public List<AbstractMesh> renderList { get; set; }

is a wrong definition.


It should be defined

public JsArray<AbstractMesh> renderList { get; set; }

instead.


Your line will be compiled easily

shadowGen.getShadowMap().renderList.push(mesh);


And one more tip:

Use As<T>() extension method (found in DuoCode.Runtime.RuntimeExtensions) for transparent casting to T, like this:

shadowGen.getShadowMap().renderList.As<JsArray<AbstractMesh>>().push(mesh);


Hopes this help,

Daniel


Answer

I assume

public List<AbstractMesh> renderList { get; set; }

is a wrong definition.


It should be defined

public JsArray<AbstractMesh> renderList { get; set; }

instead.


Your line will be compiled easily

shadowGen.getShadowMap().renderList.push(mesh);


And one more tip:

Use As<T>() extension method (found in DuoCode.Runtime.RuntimeExtensions) for transparent casting to T, like this:

shadowGen.getShadowMap().renderList.As<JsArray<AbstractMesh>>().push(mesh);


Hopes this help,

Daniel

Thank you, used the line from tip and it works well.

Login or Signup to post a comment