Lab texture and class instances

 
 
 
Posted by:havardsc
Data created:28 August 2013

Hi,

consider this image:

What I want to do is to create a texture inside an object that I can sample for each coordinate. This does not work now since a new instance of the class is created for every coordinate? (thus creating a new texture map inside the object for each instance). A workaround that I use now is to create a singleton texture map in the class (or a static list of texture maps), but this is not pretty at all.

Is there a better way to do this?

Can you please elaborate on what you mean by "create a texture inside an object"? What is the type of the "Create001" node?

"coordinate" input is what we refer to as a "thread-dependent" input, which means that the graph will be evaluated many times with this input changing. However, all other inputs and nodes within the graph that do not depend on the "coordinate" input should only be evaluated once, not created every time. If Create001 gets evaluated for every coordinate then it is a bug.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

The class creates an array of color4b values, and the getColor method is like this

public Color4b GetColor(float x, float y)
{
    return colormap[(int)(x * (size - 1)) + (int)(y * (size - 1)) * size];
}

where size is the width/height of the map. To debug I put a breakpoint on the constructor, and hooked the output from the GetColor method to the plugin output. The debugger stopped at the constructor several times so I assumed it was creating a new instance for every coordinate.

Ok, I will recreate this scenario and test it to make sure. Stay tuned.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

I tried reproducing this and failed. I used vector3 in place of your class and called its NearEqual method, to make things look as similar to the picture as possible.

The vector3 constructor gets called just once, and this is how it is intended to be. It's not wired to the graph inputs, so it does not change on each call, so its output remains valid and the same cached vector3 is returned each time.

Can you reproduce the problem with vector3 as well? Though probably it would be hard for you to debug it and see if gets called more than once.

Otherwise I'd have to ask you for your scene and the code of your class (or a stripped down version of it).

 

Ivan Kolev (Software Developer, EPHERE Inc.)

E-mail: ivan.kolev at ephere dot com

Discord: ikolev

Thanks for taking the time to look into it.

Not sure how I could reproduce it with vector3 since my issue happens when you connect the result it to the texture output node. 

Here is the code I am using http://pastebin.com/mHexqi01

I got it working if I use a static Create method , if I use the constructor like the image below it will create many instances of the class and hog all cpu:

But in the end I would like to specify the constructor arguments through lab and not make them predefined as they are now using the static constructor.

Just wanted to update you that we're investigating this issue and should have more info soon. Thanks again for providing the info,

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Fixed in next build

Marsel Khadiyev (Software Developer, EPHERE Inc.)