View Full Version : 16 bit presision
chrrox 12-25-2010, 04:28 AM Is it possible to call this function in max script with .net?
or does anyone have a script to do this?
Thanks so much in advance and happy holidays.
http://msdn.microsoft.com/en-us/library/dw4t9w27.aspx?appId=Dev10IDEF1&l=EN-US&k=k%28EHINVALIDCAST%29&rd=true
|
|
denisT
12-25-2010, 04:58 AM
Is it possible to call this function in max script with .net?
or does anyone have a script to do this?
Thanks so much in advance and happy holidays.
http://msdn.microsoft.com/en-us/library/dw4t9w27.aspx?appId=Dev10IDEF1&l=EN-US&k=k%28EHINVALIDCAST%29&rd=true
it seams the same as bit.floatAsInt
UInt16 doesn't make any sense in MXS. Using MAX->.NET value conversion you can convert mxs float to Single and after that staying in .NET you can convert Single to UInt16, but UInt16 converted to mxs value becomes Integer.
chrrox
12-25-2010, 11:08 AM
Yes that is what i want to do is convert a float i read in max. Then using .net inside max convert it to 1/2 precision floating point that is usable in max. Can you explain in a small example how to do that please.
Thanks again :)
denisT
12-25-2010, 07:47 PM
Can you explain in a small example how to do that please.
single = dotnet.ValueToDotNetObject <any_float> (dotnetclass "System.Single")
-- it's .net object now and you can pass to other .net method
uint = single.ToUInt16 asdotnetobject:on
-- it's a .net object
ps. i don't have a chance to check it. i'm answering from my cell phone.
chrrox
12-25-2010, 10:03 PM
I think its using this class but i cant figure out what i am doing wrong to get it working.
Convert = dotnet.ValueToDotNetObject 1.0f (dotnetclass "System.Convert")
-- it's .net object now and you can pass to other .net method
uint = Convert.ToUInt16 asdotnetobject:on
-- it's a .net object
i get the error
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2010\Scripts\; position: 42; line: 1
-- Unable to convert: 1f to type: System.Convert
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2010\Scripts\; position: 180; line: 3
-- Unknown property: "ToUInt16" in undefined
OK
denisT
12-25-2010, 11:00 PM
I think its using this class but i cant figure out what i am doing wrong to get it working.
Convert = dotnet.ValueToDotNetObject 1.0f (dotnetclass "System.Convert")
-- it's .net object now and you can pass to other .net method
uint = Convert.ToUInt16 asdotnetobject:on
-- it's a .net object
i get the error
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2010\Scripts\; position: 42; line: 1
-- Unable to convert: 1f to type: System.Convert
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2010\Scripts\; position: 180; line: 3
-- Unknown property: "ToUInt16" in undefined
OK
did I use "Convert" class in my sample? No. Please check MXS help
MAXScript / DotNet Value Conversions
chrrox
12-25-2010, 11:02 PM
single = dotnet.ValueToDotNetObject 1.0 (dotnetclass "System.Single")
-- it's .net object now and you can pass to other .net method
uint = single.ToUInt16 asdotnetobject:on
-- it's a .net object
gives the error
dotNetObject:System.Single
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2010\Scripts\; position: 175; line: 3
-- Unknown property: "ToUInt16" in dotNetObject:System.Single
OK
denisT
12-25-2010, 11:20 PM
single = dotnet.ValueToDotNetObject 1.0 (dotnetclass "System.Single")
-- it's .net object now and you can pass to other .net method
uint = single.ToUInt16 asdotnetobject:on
-- it's a .net object
gives the error
dotNetObject:System.Single
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2010\Scripts\; position: 175; line: 3
-- Unknown property: "ToUInt16" in dotNetObject:System.Single
OK
ok. that's my bad. you have to use "Convert" class...
(dotnetclass "System.Convert").ToUInt16 single asdotnetobject:on
denisT
12-26-2010, 05:16 AM
technically max should convert float to UInt16 directly:
dotnet.ValueToDotNetObject <any_float> (dotnetclass "System.UInt16")
chrrox
12-26-2010, 06:45 PM
Thanks for all your time.
I get no errors now but when i try to do something like this
test = 1.0
dotnet.ValueToDotNetObject test (dotnetclass "System.UInt16")
print test
I am not sure how to get the value out.
I am very bad at this i know i am sorry in advance.
denisT
12-27-2010, 05:39 AM
Thanks for all your time.
I get no errors now but when i try to do something like this
test = 1.0
dotnet.ValueToDotNetObject test (dotnetclass "System.UInt16")
print test
I am not sure how to get the value out.
I am very bad at this i know i am sorry in advance.
test_float = 1.0
test_uint16 = dotnet.ValueToDotNetObject test_float (dotnetclass "System.UInt16")
print test_uint16
print (test_uint16.ToString())
CGTalk Moderation
12-27-2010, 05:39 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.