Page 1 of 1

Scatter file scaling problem

Posted: Wed Oct 01, 2014 10:57 pm
by kraken
Hello,

Does anyone know if the scatter file transformation matrix recognizes scaling values? Every time I try to randomly scale objects they get distorted.
I thought it was a simple matter of multiply the scale factor to the appropriate matrix cell. In this case, it appears to be:

sx 0 0 0
0 sy 0 0
0 0 sz 0
0 0 0 1

Where sx, sy, and sz are the factors to be applied. Or am I doing this in the wrong direction?


-------------------------

If anyone is interested here's a simple javascript I wrote to create output you can cut and paste as a scatter file.

Code: Select all

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Scatter File Randomizer</title>
</head>

<body>
<label>translate uniform</label><input id="translate" type="text"><br>
<label>trans x</label><input id="transx" type="text"><br>
<label>trans y</label><input id="transy" type="text"><br>
<label>trans z</label><input id="transz" type="text"><br>
<label>rot x</label><input id="rotx" type="text"><br>
<label>rot y</label><input id="roty" type="text"><br>
<label>rot z</label><input id="rotz" type="text"><br>
<label>scale uniform</label><input id="scale" type="text"><br>
<label>scale x</label><input id="scalex" type="text"><br>
<label>scale y</label><input id="scaley" type="text"><br>
<label>scale z</label><input id="scalez" type="text"><br><br>
<label>Quantity</label><input id="qty" type="text" value=10><br>
<input type='button' onclick="createTransform()" value = "start">

<div id="test">test
</div>
</body>
<script language = "javascript">
var matrix = new Array(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1); // standard transformation matrix
function createTransform(){
var qty = document.getElementById('qty').value;
var str = '';

for (var i = 0; i < qty; i++)
						str = rotationRange() + str;
						
						document.getElementById('test').innerHTML = str;
}



function randomNum(){
	
	var rnd = Math.random()
	return rnd;
}




function rotationRange(){
	var defaultVal = 1;
	
	var x = document.getElementById("rotx").value;
	var y = document.getElementById("roty").value;
	var z = document.getElementById("rotz").value;
	var a = 180 * randomNum();
	
	var d = document.getElementById('translate').value;
	var dx = document.getElementById('transx').value;
	var dy = document.getElementById('transy').value;
	var dz = document.getElementById('transz').value;
	
	var s = document.getElementById('scale').value;
	var sx = document.getElementById('scalex').value;
	var sy = document.getElementById('scaley').value;
	var sz = document.getElementById('scalez').value;
	
	
	// ------------ rotate -----------------//
	
	if(x == '') x = defaultVal * randomNum();
		else x = x * randomNum();
		
	if(y == '') y = defaultVal * randomNum();
		else y = y * randomNum();
		
	if(z == '') z = defaultVal * randomNum();
		else z = z * randomNum();
	
	// -------------- translate ----------- //
		
    if(d == '')
	defaultVal = 200;
	else
	defaultVal = d;
	
	if(dx == '') dx = defaultVal * randomNum();
		else dx = dx * randomNum();
		
	if(dy == '') dy = defaultVal * randomNum();
		else dy = dy * randomNum();
		
	if(dz == '') dz = defaultVal * randomNum();
		else dz = dz * randomNum();	
	
	// ------------ scale -------------------//
	
	if(s == '') defaultVal = 1;
		else defaultVal = s;
		
		var uniformScale = randomNum();
		
	if(sx == '') sx = defaultVal * uniformScale;
		else sx = sx * randomNum();
		
	if(sy == '') sy = defaultVal * uniformScale;
		else sy = sy * randomNum();
		
	if(sz == '') sz = defaultVal * uniformScale;
		else sz = sz * randomNum();	
			
	
	// borrowed this code snippet from http://evanw.github.io/lightgl.js/docs/matrix.html - me likey.
	
	var m = matrix;

  var d = Math.sqrt(x*x + y*y + z*z) ;
  a *= Math.PI / 180; x /= d; y /= d; z /= d;
  var c = Math.cos(a), s = Math.sin(a), t = 1 - c;

  m[0] = (x * x * t + c) * sx ;  //scale x
  m[1] = x * y * t - z * s;
  m[2] = x * z * t + y * s;
  m[3] = dx;

  m[4] = y * x * t + z * s;
  m[5] =  (y * y * t + c) * sy;  // scale y
  m[6] = y * z * t - x * s;
  m[7] = dy;

  m[8] = z * x * t - y * s;
  m[9] = z * y * t + x * s; 
  m[10] =  (z * z * t + c) * sz ; // scale z
  m[11] = dz;

  m[12] = 0;  // we are ignoring these - not recognized by Octane
  m[13] = 0;
  m[14] = 0;
  m[15] = 1;
	
	var out ='';
	
	for (var i =0; i<12; i++) {
		out = out+ m[i] + " ";
	}
	
	return out + "<br>";
}



//document.getElementById('test').innerHTML=out;
</script>
</html>
Found more problems...

For some reason when using the scatter file, you can not focus the camera on the objects.
No focus on objects using camera and render target.
No focus on objects using camera and render target.

Then if you just use the default camera and click on the geometry goup you can see them perfectly.
Focus achieved with default camera
Focus achieved with default camera

This may not be a octane issue, as I built these asteroids with sculptris...they could have polygon problem...notheless, only one
of the three objects accepts the materials.
Not all geometry accepts materials
Not all geometry accepts materials

Re: Scatter file scaling problem

Posted: Thu Oct 02, 2014 7:16 am
by Vue2Octane
Make sure the object is at position(0,0,0) when you export it from whatever software.
I has this problem that I exported an object at non-zero positions from Vue, then it got moved around in Octane when I changed the scaling. I always make sure the objects scaling center which i want is at (0,0,0) when I export. Actually, I think 'Scaling Center' is a good term. If it lies outside of the object, it moves around when scaling.

Also try using placement nodes before and after the object. Before to control the obejct itself, and after to control the scattered distribution.

Re: Scatter file scaling problem

Posted: Thu Oct 02, 2014 11:15 pm
by kraken
Interesting. I can see how that would definitely create a problem. I am certainly using groups of asteroids where the center of the group is not within any asteroid. However, after taking your advice and building a new asteroid with orientation at the centroid and importing it, The scaling problem was the same. Its got to be my formula.

FYI, I tried scattering individual asteroids and it tends to crash after a 100 or so objects, I'm assuming my polygon count is too high or something...but for some reason if I group 3 asteroids and scatter them 30x, it works. No explanation. Same objects, just grouped. Fortunately, this works with alembic as well. I was getting super stressed out because I was expecting to render a sequence but all attempts to export my 250 asteroid field was crashing. This isn't as nice as my original animation was design, but it will have to do considering all the limitations I'm dealing with.

Re: Scatter file scaling problem

Posted: Fri Oct 03, 2014 6:25 am
by Vue2Octane
maybe it has something to do with object format? I always export obj and use this. Polygon count was never a problem whem I scatter. From experience any obj file around 50mb or even mor scatters ok. Look up the mScatter thread in the forum. I also published a code. The code works. Maybe it helps to find any error in your code.

Re: Scatter file scaling problem

Posted: Sun Oct 05, 2014 9:47 pm
by roeland
Octane recognises scale matrices, but remember that if you want to apply a scale before or after another transform you have to use a matrix multiplication. That's different than just multiplying component by component. In case of a scaling matrix this corresponds to multiplying either all rows or all columns of the other transform matrix with the scale factors. Also check if the script works correctly, for instance if you set rotation and translation to 0, and scale to 1 it should return the identity matrix.

--
Roeland

Re: Scatter file scaling problem

Posted: Mon Oct 06, 2014 7:21 am
by Vue2Octane
yes, matrix multiplication - every row with every column - (the product sum)

In my scatter code (mScatter) I create separate matrices for translation, rotation, scaling and shearing and then I matrix-mupltiply them in the end to a final matrix. This final matrix is the one (or thousands of them for grass, trees etc) that is exported to csv/txt and which is imported into the scatter node. It works really well.

Re: Scatter file scaling problem

Posted: Thu Oct 09, 2014 2:36 pm
by kraken
Oh Right! Duh...I vaguely remember that now. You have to transform before translation. I think the term was Dot Product, or was it Cross Product (I'll have dig through my OpenCL course notes).

As far as buying mScatter, I'd love to try it out, I'm just can't stomach buying another plugin/software that doesn't deliver or is buggy. Not saying your product is buggy, I just don't know anything about it or trust any reviews. I've been burned 3x this month and lost lots of time and money believing hype. Maybe next project I can research it in greater detail.

Thanks for the insight.

Re: Scatter file scaling problem

Posted: Fri Oct 10, 2014 7:04 am
by Vue2Octane
haha, do not worry. I am not involved in any sophisticated conspirancy to rip off Octane users by offering mScatter.
It is just a small code that I did for me, so that I ca render landscapes. I share the code on the first page of the thread.

But now that you say it, I might offer the C-translated code soon and will provide an .exe file for mScatter. ;)