Page 43 of 67

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Thu Mar 04, 2021 8:35 pm
by TAO
B.Y.O.B. wrote: Thu Mar 04, 2021 7:42 pm The Blender addon does it single threaded too, and in Python on top of that.
It sounds to me like the algorithm to detect instances is very very complicated. How does it work, in detail? I would first check if there's a faster alternative before thinking about multithreading.
in 3dsmax we have reference and instance when an object is a reference it will point to all instance too, so if i have 12000 instances and 1 reference it will show all the instance as reference and instance, plus for the instance object, it will set all 12000 objects as a reference point again.
so i created a list of objects first
INodeTab& nodes
then for every single node, i check all nodes list to be sure it is the instance and not the reference.
The problem is just about the references and not instances. i don't know why but 3dsmax return reference as an identical instance with a different object Ids.

Code: Select all

long insNumber = IInstanceMgr::GetInstanceMgr()->GetInstances(*node, nodes);
This will return all instances and the reference nodes.

Code: Select all

node->GetObjectRef() == nodes[j]->GetObjectRef()
return true for instance objects but also for reference objects too.
And for reference object will return all of the previews nodes too.

maybe i can explain that in a screenshot in next post.

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Thu Mar 04, 2021 8:48 pm
by TAO
Screenshot 2021-03-04 213955.jpg
1 source
2-3 instance
4 reference
5 clone

Code: Select all

long insNumber = IInstanceMgr::GetInstanceMgr()->GetInstances(*node, nodes);
will return 4 and will set the "nodes" to 4 reference and instance objects

Code: Select all

if (node->GetObjectRef() == nodes[j]->GetObjectRef())
return true for instance objects works fine until the 4th object, it will return true for all of instance objects as instance again.

Code: Select all

long insNumber = IInstanceMgr::GetInstanceMgr()->GetInstances(*node, nodes);
if (insNumber > 0)
     for (int j = 0; j < insNumber; j++)
	if (node->GetObjectRef() == nodes[j]->GetObjectRef())
	    return true;
So i will repeat this process for all the objects one by one (in this case five objects - 1 = 16 time).
I tried to create a list of previews duplicated objects so i check if the object previously duplicated and not repeated the process for it, that makes the process faster but still not enough.

Code: Select all

for (int i = 0; i < wasInstance.Count(); i++)
    if (node->GetObjectRef() == wasInstance[i]->GetObjectRef())
	return true;
it is an extensive process and I'm working on it to make it faster.
I will be grateful for any suggestions here.

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Thu Mar 04, 2021 9:25 pm
by B.Y.O.B.
TAO wrote: Thu Mar 04, 2021 8:35 pm for every single node, i check all nodes list to be sure it is the instance and not the reference.
This is probably the main cause of the slowness.
You could try to use a key/value mapping datastructure instead (aka dictionary, hashmap) for faster lookups.

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Thu Mar 04, 2021 9:33 pm
by TAO
B.Y.O.B. wrote: Thu Mar 04, 2021 9:25 pm
TAO wrote: Thu Mar 04, 2021 8:35 pm for every single node, i check all nodes list to be sure it is the instance and not the reference.
This is probably the main cause of the slowness.
You could try to use a key/value mapping datastructure instead (aka dictionary, hashmap) for faster lookups.
I'll try it, meanwhile, is there any way for multiple DefineMesh at the same time?
Because that part is taking too much time, aslo.

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Thu Mar 04, 2021 10:46 pm
by Dade
B.Y.O.B. wrote: Thu Mar 04, 2021 9:25 pm
TAO wrote: Thu Mar 04, 2021 8:35 pm for every single node, i check all nodes list to be sure it is the instance and not the reference.
This is probably the main cause of the slowness.
You could try to use a key/value mapping datastructure instead (aka dictionary, hashmap) for faster lookups.
From the original description, it sounds like an O(n^2) algorithm (i.e. impractical fo any significative amount of "n"). You can use boost::unordered_map (aka hash table) or something similar to have constant time access.

It will transform stuff like:

Code: Select all

     for (int j = 0; j < insNumber; j++)
	if (node->GetObjectRef() == nodes[j]->GetObjectRef())
	    return true;
from O(n) in O(1).

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Fri Mar 05, 2021 1:00 am
by TAO
Dade wrote: Thu Mar 04, 2021 10:46 pm
B.Y.O.B. wrote: Thu Mar 04, 2021 9:25 pm
TAO wrote: Thu Mar 04, 2021 8:35 pm for every single node, i check all nodes list to be sure it is the instance and not the reference.
This is probably the main cause of the slowness.
You could try to use a key/value mapping datastructure instead (aka dictionary, hashmap) for faster lookups.
From the original description, it sounds like an O(n^2) algorithm (i.e. impractical fo any significative amount of "n"). You can use boost::unordered_map (aka hash table) or something similar to have constant time access.

It will transform stuff like:

Code: Select all

     for (int j = 0; j < insNumber; j++)
	if (node->GetObjectRef() == nodes[j]->GetObjectRef())
	    return true;
from O(n) in O(1).

using key-value pair and then find-key as B.O.B.Y suggested and with a little bit of optimization of code, make the process almost twice faster in less than 9 seconds for 12000 teapots (more than 50000 triangles each).

And by using unordered_map as Dade suggested.
by using std unordered_map give me the result around 4 seconds (using nodes)
std::unordered_map<Node,int> unmap;

by using the boost unordered_map it's now just taken almost 3 seconds (using hash key ref id as string)
boost::unordered::unordered_map<std::string,int> umap;

Thank you, guys.

I need to mention it is been a while that when there are too many objects close to each other there will be a dark area in the middle and I don't know where does this come from?
Screenshot 2021-03-05 013502.jpg
in past, i was thinking of something wrong with the mesh i designed but as I have seen this more and more i believe there is something not right and i have no idea about it.

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Fri Mar 05, 2021 9:05 am
by Dade
TAO wrote: Fri Mar 05, 2021 1:00 am I need to mention it is been a while that when there are too many objects close to each other there will be a dark area in the middle and I don't know where does this come from?
That is a self-shadowing problem due to numerical precision. You have to increase the value used for min. epsilon from the default 1e-5f to something like 0.01.

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Fri Mar 05, 2021 2:01 pm
by TAO
Dade wrote: Fri Mar 05, 2021 9:05 am
TAO wrote: Fri Mar 05, 2021 1:00 am I need to mention it is been a while that when there are too many objects close to each other there will be a dark area in the middle and I don't know where does this come from?
That is a self-shadowing problem due to numerical precision. You have to increase the value used for min. epsilon from the default 1e-5f to something like 0.01.
That's fixed the problem, how epsilon will affect translation and render time?
004.jpg

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Fri Mar 05, 2021 2:15 pm
by patro
TAO wrote: Fri Mar 05, 2021 2:01 pm 004.jpg
:D a bit scary to look at such impressive army of tea pots :D
congratulation for this milestone in maxtolux development.

Re: MaxToLux - 3ds Max Integration for LuxCoreRender

Posted: Fri Mar 05, 2021 3:50 pm
by Dade
TAO wrote: Fri Mar 05, 2021 2:01 pm That's fixed the problem, how epsilon will affect translation and render time?
None.