Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Decimal places as needed
  RSS 2.0 ATOM  

Decimal places as needed
Rate this thread
 
64049
 
Permlink of this thread  
avatar
  • Total Posts: 10
  • Joined: 14 April 2010 09:20 PM

I read a vertex normal of a face in maxscript and it returns an array of 3 arrays like this:

#([0,-1,0], [0,-1,0], [0,-1,0])

this is ok but when I extract single numbers from each array and send it to output (just like below, example for one number only):

for 1 to theMesh.numfaces do
 ( 
 
vertexNormal meshop.getfaceRnormals theMesh i
 format 
"%,%,%,%,%,%,%,%,%," vertexNormal[1].x vertexNormal[1].y vertexNormal[1].z vertexNormal[2].x vertexNormal[2].y vertexNormal[2].z vertexNormal[3].x vertexNormal[3].y vertexNormal[3].z to:outFile

I am getting the right numbers but all of them have decimal places like for example “0” is “0.0” and I want to shrink the file size as much as possible so where not needed I want maxscript not to put this unnecessary data:

0.0,-1.0,0.0,
0.0,-1.0,0.0,
0.0,-1.0,0.0

How do I do it?



Replies: 0
avatar
  • Anubis
  • Posted: 31 January 2012 12:53 PM

Thats normal, as all Point3 values [ x, y, z ] are Floats.
You can convert them to an Integers like this:

format "%,%,%,%,%,%,%,%,%," (vertexNormal[1].as integer\
(vertexNormal[1].as integer) (vertexNormal[1].as integer) ...

but will lose the precision, for example this [-0.0626732,-0.0635639,0.996008] will become 0,0,0



Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 0
avatar

Anubis 31 January 2012 12:53 PM

Thats normal, as all Point3 values [ x, y, z ] are Floats.
You can convert them to an Integers like this:

format "%,%,%,%,%,%,%,%,%," (vertexNormal[1].as integer\
(vertexNormal[1].as integer) (vertexNormal[1].as integer) ...

but will lose the precision, for example this [-0.0626732,-0.0635639,0.996008] will become 0,0,0

I know about “to integer” but I have to keep the numbers as floats. I just found in the manual how max displays floats and it seems that I will just have to live with the .0 in the decimals. Anyway thanks



Replies: 0
avatar
  • Anubis
  • Posted: 01 February 2012 03:03 AM

VertexFusion 01 February 2012 12:42 AM

I know about “to integer” but I have to keep the numbers as floats. I just found in the manual how max displays floats and it seems that I will just have to live with the .0 in the decimals. Anyway thanks

Then i’m a bit confusing on what you ask for… decimals is floats. Maybe you need specific culture formating where for example “0.1” become “0,1” (ie replacing dot with comma)? or maybe to become “.1”, or rounding, or something else?



Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 0
avatar

Anubis 01 February 2012 03:03 AM
VertexFusion 01 February 2012 12:42 AM

I know about “to integer” but I have to keep the numbers as floats. I just found in the manual how max displays floats and it seems that I will just have to live with the .0 in the decimals. Anyway thanks

Then i’m a bit confusing on what you ask for… decimals is floats. Maybe you need specific culture formating where for example “0.1” become “0,1” (ie replacing dot with comma)? or maybe to become “.1”, or rounding, or something else?

It is the way maxscript outputs data from my array. I am reading UVs from my object, then I split the components and only append U and V to the second array. Then when I output this array to file with format command (I use a loop so I can arrange them as I need to) max is displaying decimals on the numbers which normally don’t have any, in the original array. More explanation below

Straight output of one vertex UV array just as the function gets it is and it looks like so
#(0.5, 1, 0)

My processing way. I separate 3 components and append two of them to the SECOND array and then output it, it looks like so: #(0.5, 1.0, 0.0)

So you can see that there are unnecessary decimals added to the numbers.



Replies: 0
avatar
  • Anubis
  • Posted: 01 February 2012 08:32 AM

Yeah, the display value is different from stored value.
If you like to keep displayed value as is then use “as string” conversion.



Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 0