Notifications
Clear all

[Closed] Materials: Let's kick it up a notch!

Hmm…do I need to specify the type of theMat in the function I declare? I get an error at that top line:

amb = theMat.ambient

It says ambient is an unknown property. I have the function declared above the main portion of my exporter. Should it go below and will I then need to prototype it?

Also, do I need to specify if I want to do floating precision division when I’m dividing the color components by 255? Is that why you’ve sort of casted that 255 as a float: 255.0. Is that what is preventing integer division from taking place?

Thanks!

1 Reply
(@bobo)
Joined: 2 years ago

Posts: 0

Post the complete error message.
It should have said “Unknown property .ambient in …” so we can see what exactly was passed as theMat. If an object does not have a material, it would say “Unknown property .ambient in undefined”, if for some reason the material was a class that did not have .ambient, you could catch that by first asking whether the material has a property called ambient or use an error trap.

Either

if hasProperty theMat “ambient” then amb = theMat.ambient else amb = [0,0,0]

or

try(amb = theMat.ambient)catch(amb = [0,0,0])

Yes, the reason for casting the divisor as float was to avoid integer divisions. You should be safe doing color divisions by 255.0, the results should be floating point color channels between 0.0 and 1.0.

Cheers,
Bobo

The error reads:

–Unknown propery: “ambient” in test: Ink__n_paint

I guess the interpreter cannot infer that theMat is supposed to be of type material based on its parameter list. It certainly has nothing else go on. Here’s my code:


fn exportMaterial tempMat file =
(
amb = tempMat.ambient
dif = tempMat.diffuse
spe = tempMat.specular
 
WriteFloat file (amb.r / 255.0) 
WriteFloat file (amb.g / 255.0)
WriteFloat file (amb.g / 255.0)
 
WriteFloat file (dif.r / 255.0)
WriteFloat file (dif.g / 255.0)
WriteFloat file (dif.g / 255.0)
 
WriteFloat file (spe.r / 255.0)
WriteFloat file (spe.g / 255.0)
WriteFloat file (spe.g / 255.0)
 
WriteFloat file tempMat.glossiness
)
 
theObj = pickObject()
 
if superclassof theObj == GeometryClass do
(
tmesh = snapshotasmesh theObj
invTran = inverse theObj.transform
file = fopen "C:\\stuff2.dat""wb"

num_verts = tmesh.numverts
num_faces = tmesh.numfaces
 
WriteLong file num_verts
WriteLong file num_faces
 
for v = 1 to num_verts do
(
tempVert = (getVert tmesh v) * invTran
WriteFloat file tempVert.x
WriteFloat file tempVert.y
WriteFloat file tempVert.z
 
tempNorm = (getNormal tmesh v) * invTran
WriteFloat file tempNorm.x
WriteFloat file tempNorm.y
WriteFloat file tempNorm.z
)
 
for f = 1 to num_faces do
(
tempFace = getFace tmesh f
matID = getFaceMatId tmesh f 
 
WriteLong file (tempFace.x - 1) #unsigned
WriteLong file (tempFace.y - 1) #unsigned
WriteLong file (tempFace.z - 1) #unsigned
 
WriteLong file matID
)
 
tempMat = theObj.material
if classof tempMat == MultiMaterial then
(
WriteShort file tempMat.numsubs
for m = 1 to tempMat.numsubs do
exportMaterial tempMat[m] file 
)
 
else
(
WriteShort file 1
exportMaterial tempMat file
)
fclose file
)

Thanks for your help!

EDIT: A quick check to the classof tempMat resolved the problem quite nicely. Now to adapt the model loading code and see if that actually worked

Page 2 / 2