Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting an array of class type? #35

Open
limefrogyank opened this issue Jan 30, 2021 · 3 comments
Open

Setting an array of class type? #35

limefrogyank opened this issue Jan 30, 2021 · 3 comments
Labels
feature New feature or request

Comments

@limefrogyank
Copy link

I'm at a loss as to how to add an array of a class type. For example, in RenderTargetTexture, you need to add any meshes that you want rendered into a property on the RenderTargetTexture object called renderList. This is a plain array of type AbstractMesh[]. The generator picks this up just fine. I try to use it like this:

_shadowRenderTarget.renderList = new AbstractMesh[] { _moleculeMesh };

However, when I later call render() on the RenderTargetTexture, BabylonJS spits out an error. The actual JS AbstractMesh object is the Cached version that has the ___guid. There doesn't seem to be a way to translate those C# objects to the javascript objects. I can't seem to find a way to manipulate arrays, so I'm not sure what to do next.

@limefrogyank
Copy link
Author

Looks like I might have to write a custom CachedEntityConverter

@limefrogyank
Copy link
Author

Wasn't sure how to do the CachedEntityConverter. Instead this javascript hack seems to work:

function pushClassToArray(root, identifier, ...args) {
    try {
        var arrayEntity = blazorInterop.cacheEntity(root, identifier);
        for (var i = 0; i < args.length; i++) {
            blazorInterop.call(arrayEntity, "push", args[i]);            
        }
    } catch (ex) {
        console.log("error", ex);
    }
}

used like this with a synchronous JSRuntime:

            Runtime.InvokeVoid("pushClassToArray", _shadowRenderTarget.___guid, "renderList", _moleculeMesh);

@canhorn
Copy link
Owner

canhorn commented Feb 3, 2021

This looks like a deficiency in the generator, I will look at getting this in.

@canhorn canhorn added the feature New feature or request label Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants