{"id":572,"date":"2015-12-19T12:47:14","date_gmt":"2015-12-19T11:47:14","guid":{"rendered":"http:\/\/www.lefx.de\/?p=572"},"modified":"2015-12-19T12:47:14","modified_gmt":"2015-12-19T11:47:14","slug":"workflow-tips-random-material-id","status":"publish","type":"post","link":"https:\/\/test.lefx.de\/en\/workflow-tips-random-material-id\/","title":{"rendered":"Workflow Tips | Random Material ID"},"content":{"rendered":"<p>[:de]Eines der Hauptprobleme der Wiedergabe ist ihre Perfektion. Baumobjekten, die aus vielen Blattelementen bestehen, auf die das gleiche Material aufgetragen wurde, fehlen oft die nat\u00fcrlichen Variationen, die der Betrachter erwarten w\u00fcrde. In unserem Produktionsablauf sind wir t\u00e4glich mit diesem Problem konfrontiert. Da wir immer versuchen, die Qualit\u00e4t unserer Architektur-Renderings zu verbessern, haben wir uns entschieden, ein einfach zu bedienendes Skript zu erstellen, mit dem wir zuf\u00e4llige Material-IDs setzen k\u00f6nnen, um die Wahrnehmung nat\u00fcrlicher Variationen zu erm\u00f6glichen.<\/p>\n<p>Unsere wichtigste Software zur Erstellung von Inhalten ist 3ds Max, daher haben wir ein Makro-Skript (in MAXScript) f\u00fcr dieses Problem erstellt.<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro.png\" alt=\"DE_intro\" \/><\/p>\n<h2>Rekursiver oder iterativer Ansatz<\/h2>\n<p>Es gibt grunds\u00e4tzlich zwei m\u00f6gliche Ans\u00e4tze zur L\u00f6sung dieses Problems. Die iterative erste iteriert durch alle Fl\u00e4chen, um eine zuf\u00e4llige Material-ID festzulegen, w\u00e4hrend die rekursive erste Version die gro\u00dfe Menge an Fl\u00e4chen in kleinere Teilgruppen aufteilt und dann allen in dieser Gruppe enthaltenen Elementen eine Material-ID zuweist; verbunden mit der Fl\u00e4chenauswahl.<\/p>\n<p>Zuerst haben wir den iterativen Ansatz implementiert, um einen Blick auf seine M\u00f6glichkeiten und Einschr\u00e4nkungen zu werfen. Danach dachten wir \u00fcber m\u00f6gliche Optimierungen und andere Ideen nach, wie dieses Problem effizienter gel\u00f6st werden k\u00f6nnte, mit einem optimalen Gleichgewicht zwischen Geschwindigkeit und einem visuell hochwertigen Ergebnis. Deshalb haben wir die rekursive Version weiter untersucht, um das Problem von einem anderen perspektivischen Standpunkt aus zu l\u00f6sen.<\/p>\n<h2>Algorithmen<\/h2>\n<h3>Iterative Version<\/h3>\n<pre style=\"color: #000000; background: #f1f0f0;\"><span style=\"color: #400000; font-weight: bold;\">function<\/span> changeIDsIterative obj minID maxID stepSize <span style=\"color: #806030;\">=<\/span>\n<span style=\"color: #806030;\">(<\/span>\n\tgetElement <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>getElementsUsingFace\n\tsetFaceID <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>setFaceMatID\n\t\t\t\n\trange <span style=\"color: #806030;\">=<\/span> <span style=\"color: #8c0000;\">1<\/span>\n\t\t\t\n\t<span style=\"color: #400000; font-weight: bold;\">for<\/span> i <span style=\"color: #806030;\">=<\/span> <span style=\"color: #8c0000;\">1<\/span> <span style=\"color: #400000; font-weight: bold;\">to<\/span> obj<span style=\"color: #8c0000;\">.<\/span>numfaces by stepSize <span style=\"color: #400000; font-weight: bold;\">do<\/span> <span style=\"color: #806030;\">(<\/span>\n\t\t\t\t\n\t\trandomID <span style=\"color: #806030;\">=<\/span> random minID maxID\n\t\t\t\t\n\t\trange <span style=\"color: #806030;\">=<\/span> i <span style=\"color: #806030;\">+<\/span> stepSize\n\t\t\t\t\n\t\t<span style=\"color: #400000; font-weight: bold;\">if<\/span><span style=\"color: #806030;\">(<\/span>range <span style=\"color: #806030;\">&gt;<\/span> obj<span style=\"color: #8c0000;\">.<\/span>numfaces<span style=\"color: #806030;\">)<\/span> <span style=\"color: #400000; font-weight: bold;\">do<\/span> <span style=\"color: #806030;\">(<\/span>\n\t\t\trange <span style=\"color: #806030;\">=<\/span> obj<span style=\"color: #8c0000;\">.<\/span>numfaces\n\t\t<span style=\"color: #806030;\">)<\/span>\n\t\t\n\t\telement <span style=\"color: #806030;\">=<\/span> getElement obj <span style=\"color: #806030;\">#<\/span>{i<span style=\"color: #8c0000;\">..<\/span>range}\n\t\tsetFaceID obj element randomID\n\t<span style=\"color: #806030;\">)<\/span>\n<span style=\"color: #806030;\">)<\/span>\n<\/pre>\n<p>Im Grunde genommen iteriert dieses Skript durch alle Fl\u00e4chen mit einem bestimmten Schritt. Dabei nimmt es die Elemente, die mit den Fl\u00e4chen innerhalb des Stufenbereichs verbunden sind und gibt dieser Auswahl von Fl\u00e4chen eine zuf\u00e4llige Material-ID im Bereich der minimalen ID und der maximalen ID (minID &lt;= ID &lt;= maxID).<\/p>\n<p>Gr\u00f6\u00dfere Werte der Schrittweite w\u00fcrden zu einer h\u00f6heren Geschwindigkeit f\u00fchren, indem viele Fl\u00e4chen \u00fcbersprungen werden, aber zu einer sichtbaren Wiederholung der gleichen verwendeten Material-ID.<\/p>\n<p>Die Anzahl der Funktionsaufrufe zum Setzen einer zuf\u00e4lligen Material-ID h\u00e4ngt also von der Schrittweite <em>s<\/em> ab:<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/Formel0.png\" alt=\"Formel0\" \/><\/p>\n<p>Vielleicht ist Ihnen aufgefallen, dass in den ersten beiden Zeilen zwei Funktionsaufrufe Variablen zugeordnet sind.<\/p>\n<pre style=\"color: #000000; background: #f1f0f0;\">getElement <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>getElementsUsingFace\nsetFaceID <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>setFaceMatID\n<\/pre>\n<p>Dies geschieht aus Leistungsgr\u00fcnden. Durch die Iinitialisierung des Funktionsaufrufs als Variable sind diese vielen Funktionsaufrufe etwas schneller auszuf\u00fchren.<\/p>\n<h3>Rekursive Version<\/h3>\n<pre style=\"color: #000000; background: #f1f0f0;\"><span style=\"color: #400000; font-weight: bold;\">function<\/span> changeIDs depth obj minFace maxFace minID maxID <span style=\"color: #806030;\">=<\/span>\n<span style=\"color: #806030;\">(<\/span>\n\t<span style=\"color: #400000; font-weight: bold;\">if<\/span><span style=\"color: #806030;\">(<\/span>depth <span style=\"color: #806030;\">&gt;<\/span> <span style=\"color: #8c0000;\">0<\/span><span style=\"color: #806030;\">)<\/span> <span style=\"color: #400000; font-weight: bold;\">then<\/span> <span style=\"color: #806030;\">(<\/span> <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span>Clustering<span style=\"color: #806030;\">,<\/span> <span style=\"color: #400000; font-weight: bold;\">if<\/span> depth !<span style=\"color: #806030;\">=<\/span> <span style=\"color: #8c0000;\">0<\/span>\n\t\tpartSize <span style=\"color: #806030;\">=<\/span> <span style=\"color: #806030;\">(<\/span><span style=\"color: #806030;\">(<\/span>maxFace <span style=\"color: #806030;\">-<\/span> minFace<span style=\"color: #806030;\">)<\/span> <span style=\"color: #806030;\">\/<\/span> <span style=\"color: #8c0000;\">2<\/span> <span style=\"color: #806030;\">+<\/span> <span style=\"color: #8c0000;\">1<\/span><span style=\"color: #806030;\">)<\/span> <span style=\"color: #400000; font-weight: bold;\">as<\/span> <span style=\"color: #400000; font-weight: bold;\">Integer<\/span> <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span>calculate the clustersize\n\t\t\n\t\tchangeIDs <span style=\"color: #806030;\">(<\/span>depth<span style=\"color: #806030;\">-<\/span><span style=\"color: #8c0000;\">1<\/span><span style=\"color: #806030;\">)<\/span> obj minFace <span style=\"color: #806030;\">(<\/span>partSize <span style=\"color: #806030;\">+<\/span> minFace<span style=\"color: #806030;\">)<\/span> minID maxID <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span> first part\n\t\tchangeIDs <span style=\"color: #806030;\">(<\/span>depth<span style=\"color: #806030;\">-<\/span><span style=\"color: #8c0000;\">1<\/span><span style=\"color: #806030;\">)<\/span> obj <span style=\"color: #806030;\">(<\/span>partSize <span style=\"color: #806030;\">+<\/span> minFace <span style=\"color: #806030;\">+<\/span> <span style=\"color: #8c0000;\">1<\/span><span style=\"color: #806030;\">)<\/span> maxFace minID maxID <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span> <span style=\"color: #400000; font-weight: bold;\">second<\/span> part \n\t\t\n\t<span style=\"color: #806030;\">)<\/span> <span style=\"color: #400000; font-weight: bold;\">else<\/span> <span style=\"color: #806030;\">(<\/span> <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span><span style=\"color: #400000; font-weight: bold;\">set<\/span> material IDs\n\t\tgetElement <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>getElementsUsingFace\n\t\tsetFaceID <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>setFaceMatID\n\t\t\n\t\trandomID <span style=\"color: #806030;\">=<\/span> random minID maxID \n                <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span><span style=\"color: #400000; font-weight: bold;\">get<\/span> a random ID between the given values\n\t\telement <span style=\"color: #806030;\">=<\/span> getElement obj <span style=\"color: #806030;\">#<\/span>{minFace<span style=\"color: #8c0000;\">..<\/span>maxFace} \n                <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span><span style=\"color: #400000; font-weight: bold;\">select<\/span> all elements <span style=\"color: #400000; font-weight: bold;\">with<\/span> faces in the given cluster of faces\n\t\tsetFaceID obj element randomID \n                <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span><span style=\"color: #400000; font-weight: bold;\">set<\/span> the random ID <span style=\"color: #400000; font-weight: bold;\">to<\/span> all faces in the selection\n\t<span style=\"color: #806030;\">)<\/span>\n<span style=\"color: #806030;\">)<\/span>\n<\/pre>\n<p>Die rekursive Version teilt die riesige Menge von in kleinere Gruppen von Fl\u00e4chen auf, bevor eine Material-ID festgelegt wird.<\/p>\n<p>Der Algorithmus teilt grunds\u00e4tzlich die Anzahl der Fl\u00e4chen in H\u00e4lften, bis der depth-wert Null ist. Dann w\u00e4hlt das Skript f\u00fcr jeden Unterabschnitt alle Elemente aus, die mit den Fl\u00e4chen des Unterabschnitts verbunden sind, und weist ihnen eine zuf\u00e4llige ID zu. Der zweite Teil ist also gleich der iterativen Version.<\/p>\n<p>Der einzige Unterschied besteht in der Art und Weise der Auswahl der Fl\u00e4chen.<\/p>\n<p>Beispiel f\u00fcr depth = 3<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/DepthValue.png\" alt=\"DepthValue\" \/><\/p>\n<p>Also die Anzahl der Teile, bei denen eine zuf\u00e4llige Material-ID gesetzt werden soll:<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/Formel2.png\" alt=\"Formel2\" \/><\/p>\n<p>Die Anzahl der faces rekursiv in Unterteile zu zerlegen, geht sehr schnell. Der Hauptengpass dieses Skripts ist der Zugriff der 3dx Max-Schnittstellen getElement und setFaceID.<\/p>\n<p>Die \u00e4quivalenten Parameter f\u00fcr iterative und rekursive Funktionsaufrufe k\u00f6nnen durch berechnet werden:<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/Formel1.png\" alt=\"Formel1\" \/><\/p>\n<h3>Welche ist jetzt besser?<\/h3>\n<p>Im Grunde leisten beide Versionen die gleiche Arbeit und sollten ein vergleichbares Ergebnis liefern k\u00f6nnen. Die Hauptunterschiede sind die Parameter und das interne Verfahren.<\/p>\n<p>Wenn Sie ein Objekt mit vielen Polygonen haben und (fast) jedes Element eine zuf\u00e4llige Material-ID haben sollte, dann ist die iterative Version einfacher zu benutzen, weil Sie einfach 1 oder vergleichbar niedrige Werte f\u00fcr die Schrittweite <em>s<\/em>. oder andere kleine Werte eingeben. Dann w\u00fcrde das Skript jeder Fl\u00e4che eine zuf\u00e4llige ID zuweisen und eine zuf\u00e4llige ID festlegen. Aber andererseits, wenn die Elemente viele faces haben, w\u00fcrde die Arbeit oft mehr als einmal durchgef\u00fchrt werden. Dies wird auch wegen der vielen Schnittstellenzugriffe von 3ds Max sehr langsam sein.<\/p>\n<p>Dann w\u00e4re es einfacher, den rekursiven Ansatz zu verwenden und mit kleinen Werten f\u00fcr die depth zu beginnen, bis man ein zufriedenstellendes Ergebnis mit gen\u00fcgend Mischung erh\u00e4lt, indem man den depth-wert erh\u00f6ht.<\/p>\n<h2>Beispiele<\/h2>\n<h3>Unterschiedliche Material-IDs: 3<\/h3>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/DE_mat.png\" alt=\"DE_mat\" \/><\/p>\n<h3>Laufzeit: iterativ<\/h3>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/itereative.png\" alt=\"Iterative\" \/><\/p>\n<h3>Laufzeit: rekursive<\/h3>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/rekursiv.png\" alt=\"Rekursiv\" \/><\/p>\n<p>Es war uns eine Freude, Ihnen diese kleinen Gedanken \u00fcber unseren Arbeitsablauf zu zeigen. Wir hoffen, Sie hatten Spa\u00df beim Lesen des Textes und beim Betrachten der Bilder. Um mehr von unseren Projekten zu sehen, besuchen Sie unseren <a href=\"http:\/\/www.lefx.de\/showroom\/\">Showroom<\/a>.[:en]One of the main problems of rendering is its perfection. Tree objects, that consist of many leaf elements with the same material applied to them, are often lack the natural variations the viewer would expect. In our production workflow we faced this problem on a daily basis. As we always try to improve the quality of our architectural renderings we decided to create an easy to use script to set random material IDs to give the perception of natural variations.<\/p>\n<p>Our main content creation software is 3ds Max, so we created a Macro Script (in MAXScript) for this problem.<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro.png\" alt=\"DE_intro\" \/><\/p>\n<h2>Recursive or iterative approach<\/h2>\n<p>There are basically two possible approaches to handle this problem. The iterative first oneone iterates through all faces for setting a random material ID while the recursive one version divides the big vast amount of faces into smaller parts groups(groups?) and then assigns a material ID to all the elements contained in this group. ?.connected to the face selection.<\/p>\n<p>At first we implemented the iterative approach to take a look at its possibilities and restrictions. After that we thought about possible optimizations and other ideas how to solve this problem more efficiently with an optimum balance of between speed and a visual qualitygood result. That\u2019s why we created further looked into the a recursive version to solve the problem from another perspective point of view.<\/p>\n<h2>Algorithms<\/h2>\n<h3>Iterative version<\/h3>\n<pre style=\"color: #000000; background: #f1f0f0;\"><span style=\"color: #400000; font-weight: bold;\">function<\/span> changeIDsIterative obj minID maxID stepSize <span style=\"color: #806030;\">=<\/span>\n<span style=\"color: #806030;\">(<\/span>\n\tgetElement <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>getElementsUsingFace\n\tsetFaceID <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>setFaceMatID\n\t\t\t\n\trange <span style=\"color: #806030;\">=<\/span> <span style=\"color: #8c0000;\">1<\/span>\n\t\t\t\n\t<span style=\"color: #400000; font-weight: bold;\">for<\/span> i <span style=\"color: #806030;\">=<\/span> <span style=\"color: #8c0000;\">1<\/span> <span style=\"color: #400000; font-weight: bold;\">to<\/span> obj<span style=\"color: #8c0000;\">.<\/span>numfaces by stepSize <span style=\"color: #400000; font-weight: bold;\">do<\/span> <span style=\"color: #806030;\">(<\/span>\n\t\t\t\t\n\t\trandomID <span style=\"color: #806030;\">=<\/span> random minID maxID\n\t\t\t\t\n\t\trange <span style=\"color: #806030;\">=<\/span> i <span style=\"color: #806030;\">+<\/span> stepSize\n\t\t\t\t\n\t\t<span style=\"color: #400000; font-weight: bold;\">if<\/span><span style=\"color: #806030;\">(<\/span>range <span style=\"color: #806030;\">&gt;<\/span> obj<span style=\"color: #8c0000;\">.<\/span>numfaces<span style=\"color: #806030;\">)<\/span> <span style=\"color: #400000; font-weight: bold;\">do<\/span> <span style=\"color: #806030;\">(<\/span>\n\t\t\trange <span style=\"color: #806030;\">=<\/span> obj<span style=\"color: #8c0000;\">.<\/span>numfaces\n\t\t<span style=\"color: #806030;\">)<\/span>\n\t\t\n\t\telement <span style=\"color: #806030;\">=<\/span> getElement obj <span style=\"color: #806030;\">#<\/span>{i<span style=\"color: #8c0000;\">..<\/span>range}\n\t\tsetFaceID obj element randomID\n\t<span style=\"color: #806030;\">)<\/span>\n<span style=\"color: #806030;\">)<\/span>\n<\/pre>\n<p>Basically this script iterates through all faces with a given step. There it takes the takes the elements which are connected with the faces within the step range and gives this selection of faces a random material ID in the range of the minimal ID and the maximal ID (minID &lt;= ID &lt;= maxID).<\/p>\n<p>Larger values of stepsizestep size would give result in more speed by skipping a lot of faces but would result in a visible repetition of the same used material ID.<\/p>\n<p>So the number of function calls when to setting a random material ID depends on the step size s:<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/Formel0.png\" alt=\"Formel0\" \/><\/p>\n<p>You may have noticed that in the first two lines two function calls are assigned to variables.<\/p>\n<pre style=\"color: #000000; background: #f1f0f0;\">getElement <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>getElementsUsingFace\nsetFaceID <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>setFaceMatID\n<\/pre>\n<p>That\u2019s because ofThis is done for performance reasons. By Iinitializing the function call as a variable these many function callswill allow it to run are slightly faster.<\/p>\n<h3>Recursive version<\/h3>\n<pre style=\"color: #000000; background: #f1f0f0;\"><span style=\"color: #400000; font-weight: bold;\">function<\/span> changeIDs depth obj minFace maxFace minID maxID <span style=\"color: #806030;\">=<\/span>\n<span style=\"color: #806030;\">(<\/span>\n\t<span style=\"color: #400000; font-weight: bold;\">if<\/span><span style=\"color: #806030;\">(<\/span>depth <span style=\"color: #806030;\">&gt;<\/span> <span style=\"color: #8c0000;\">0<\/span><span style=\"color: #806030;\">)<\/span> <span style=\"color: #400000; font-weight: bold;\">then<\/span> <span style=\"color: #806030;\">(<\/span> <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span>Clustering<span style=\"color: #806030;\">,<\/span> <span style=\"color: #400000; font-weight: bold;\">if<\/span> depth !<span style=\"color: #806030;\">=<\/span> <span style=\"color: #8c0000;\">0<\/span>\n\t\tpartSize <span style=\"color: #806030;\">=<\/span> <span style=\"color: #806030;\">(<\/span><span style=\"color: #806030;\">(<\/span>maxFace <span style=\"color: #806030;\">-<\/span> minFace<span style=\"color: #806030;\">)<\/span> <span style=\"color: #806030;\">\/<\/span> <span style=\"color: #8c0000;\">2<\/span> <span style=\"color: #806030;\">+<\/span> <span style=\"color: #8c0000;\">1<\/span><span style=\"color: #806030;\">)<\/span> <span style=\"color: #400000; font-weight: bold;\">as<\/span> <span style=\"color: #400000; font-weight: bold;\">Integer<\/span> <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span>calculate the clustersize\n\t\t\n\t\tchangeIDs <span style=\"color: #806030;\">(<\/span>depth<span style=\"color: #806030;\">-<\/span><span style=\"color: #8c0000;\">1<\/span><span style=\"color: #806030;\">)<\/span> obj minFace <span style=\"color: #806030;\">(<\/span>partSize <span style=\"color: #806030;\">+<\/span> minFace<span style=\"color: #806030;\">)<\/span> minID maxID <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span> first part\n\t\tchangeIDs <span style=\"color: #806030;\">(<\/span>depth<span style=\"color: #806030;\">-<\/span><span style=\"color: #8c0000;\">1<\/span><span style=\"color: #806030;\">)<\/span> obj <span style=\"color: #806030;\">(<\/span>partSize <span style=\"color: #806030;\">+<\/span> minFace <span style=\"color: #806030;\">+<\/span> <span style=\"color: #8c0000;\">1<\/span><span style=\"color: #806030;\">)<\/span> maxFace minID maxID <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span> <span style=\"color: #400000; font-weight: bold;\">second<\/span> part \n\t\t\n\t<span style=\"color: #806030;\">)<\/span> <span style=\"color: #400000; font-weight: bold;\">else<\/span> <span style=\"color: #806030;\">(<\/span> <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span><span style=\"color: #400000; font-weight: bold;\">set<\/span> material IDs\n\t\tgetElement <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>getElementsUsingFace\n\t\tsetFaceID <span style=\"color: #806030;\">=<\/span> polyop<span style=\"color: #8c0000;\">.<\/span>setFaceMatID\n\t\t\n\t\trandomID <span style=\"color: #806030;\">=<\/span> random minID maxID \n                <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span><span style=\"color: #400000; font-weight: bold;\">get<\/span> a random ID between the given values\n\t\telement <span style=\"color: #806030;\">=<\/span> getElement obj <span style=\"color: #806030;\">#<\/span>{minFace<span style=\"color: #8c0000;\">..<\/span>maxFace} \n                <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span><span style=\"color: #400000; font-weight: bold;\">select<\/span> all elements <span style=\"color: #400000; font-weight: bold;\">with<\/span> faces in the given cluster of faces\n\t\tsetFaceID obj element randomID \n                <span style=\"color: #806030;\">-<\/span><span style=\"color: #806030;\">-<\/span><span style=\"color: #400000; font-weight: bold;\">set<\/span> the random ID <span style=\"color: #400000; font-weight: bold;\">to<\/span> all faces in the selection\n\t<span style=\"color: #806030;\">)<\/span>\n<span style=\"color: #806030;\">)<\/span>\n<\/pre>\n<p>The recursive version divides the huge amount of into smaller clusters of faces before setting a material ID.<\/p>\n<p>The algorithm basically divides the amount of faces into halves until the depth value is zero. Then for every subpart the script selects all elements which are connected with the faces of the subpart and assigns a random ID. So the second part is equal to the iterative version.<\/p>\n<p>The only difference is the manner of selecting the faces.<\/p>\n<p>Example for depth = 3<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/DepthValue.png\" alt=\"DepthValue\" \/><\/p>\n<p>So the number of parts where to set a random material ID is:<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/Formel2.png\" alt=\"Formel2\" \/><\/p>\n<p>Dividing the amount of faces recursively into subparts is very fast. The main bottleneck of this script is the access of the 3dx Max-Interfaces getElement and setFaceID.<\/p>\n<p>The equivalent parameters for iterative and recursive function calls can be calculated by:<\/p>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/Formel1.png\" alt=\"Formel1\" \/><\/p>\n<h3>Which one is better now?<\/h3>\n<p>Basically both version do the same work and should be able to give a comparable result. The main differences are the parameters and the internal procedure.<\/p>\n<p>If you have an object with a lot of polygons and (nearly) every element should have a random material ID then the iterative version will be easier to use because you simply enter 1 or comparable low values for the step size s. or other small values. Then the script would go assignto a random ID to every face and set a random ID. But On the other hand if the elements have a lot of faces the work would often be done more than once. This will be also very slow because of many interface accesses of 3ds Max.<\/p>\n<p>Then it would be easier to use the recursive approach and begin with small values for the depth until you get a satisfying result with enough mixture by increasing the depth value.<\/p>\n<h2>Examples<\/h2>\n<h3>Different material IDs: 3<\/h3>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/DE_mat.png\" alt=\"DE_mat\" \/><\/p>\n<h3>Duration &#8211; iterative<\/h3>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/itereative.png\" alt=\"Iterative\" \/><\/p>\n<h3>Duration &#8211; recursive<\/h3>\n<p><img decoding=\"async\" class=\"img-responsive\" src=\"http:\/\/www.lefx.de\/wp-content\/uploads\/2016\/02\/rekursiv.png\" alt=\"Rekursiv\" \/><\/p>\n<p>It was a pleasure for us to show you these little thoughts about our workflow. We hope you had fun while reading the text and looking to the pictures. To see more of our projects, visit our <a href=\"http:\/\/www.lefx.de\/showroom\/\">Showroom<\/a>.[:]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[:de]Eines der Hauptprobleme der Wiedergabe ist ihre Perfektion. Baumobjekten, die aus vielen Blattelementen bestehen, auf die das gleiche Material aufgetragen wurde, fehlen oft die nat\u00fcrlichen Variationen, die der Betrachter erwarten w\u00fcrde. In unserem Produktionsablauf sind wir t\u00e4glich mit diesem Problem konfrontiert. Da wir immer versuchen, die Qualit\u00e4t unserer Architektur-Renderings zu verbessern, haben wir uns entschieden, [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":580,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[6],"tags":[10,17,30],"class_list":["post-572","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-3ds-max","tag-maxscript","tag-workflow"],"uagb_featured_image_src":{"full":["https:\/\/test.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro_Vorschau-1.png",648,357,false],"thumbnail":["https:\/\/test.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro_Vorschau-1-150x150.png",150,150,true],"medium":["https:\/\/test.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro_Vorschau-1-300x165.png",300,165,true],"medium_large":["https:\/\/test.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro_Vorschau-1.png",648,357,false],"large":["https:\/\/test.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro_Vorschau-1.png",648,357,false],"1536x1536":["https:\/\/test.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro_Vorschau-1.png",648,357,false],"2048x2048":["https:\/\/test.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro_Vorschau-1.png",648,357,false],"trp-custom-language-flag":["https:\/\/test.lefx.de\/wp-content\/uploads\/2016\/02\/DE_intro_Vorschau-1-18x10.png",18,10,true]},"uagb_author_info":{"display_name":"Tom Micklich","author_link":"https:\/\/test.lefx.de\/en\/author\/tom-micklich\/"},"uagb_comment_info":0,"uagb_excerpt":"[:de]Eines der Hauptprobleme der Wiedergabe ist ihre Perfektion. Baumobjekten, die aus vielen Blattelementen bestehen, auf die das gleiche Material aufgetragen wurde, fehlen oft die nat\u00fcrlichen Variationen, die der Betrachter erwarten w\u00fcrde. In unserem Produktionsablauf sind wir t\u00e4glich mit diesem Problem konfrontiert. Da wir immer versuchen, die Qualit\u00e4t unserer Architektur-Renderings zu verbessern, haben wir uns entschieden,&hellip;","_links":{"self":[{"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/posts\/572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/comments?post=572"}],"version-history":[{"count":0,"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/posts\/572\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/media\/580"}],"wp:attachment":[{"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/media?parent=572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/categories?post=572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.lefx.de\/en\/wp-json\/wp\/v2\/tags?post=572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}