Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Ian Ross has just released a book on Anim8or. It's perect for a beginner and a good reference for experienced users. It contains detailed chapters on every aspect, with many examples. Get your own copy here: "Anim8or Tutorial Book"

Author Topic: ASL and working with materials  (Read 9885 times)

sagedavis

  • Newbie
  • *
  • Posts: 36
    • View Profile
ASL and working with materials
« on: October 14, 2008, 09:55:01 pm »

I have been working with the materials script to export materials to a .a8s file. http://homepage.ntlworld.com/w.watson3/main/files/export_materialv1.a8s

I notice that when I import my exported script, it imports them to the object tab (rather than the file tab) of the material editor.

I would prefer my palet to be global so that I can import it once and use it for any object.
So, when I export my materials in the "File" tab, I don't get any material, but, I do if it's attached to the object tab.
Her's what I get.
<code>
/* basic Material script for Anim8or 0.97d beta
*/
object $obj;
material $mat;
$obj = project.curObject;
$mat = $obj.NewMaterial ( "Gold");
$mat.LockAmbiantDiffuse = 0;
$mat.SetAmbiantColor ((0.957 , 0.831 , 0.498 ));
$mat.Ka = 0.300;
$mat.SetDiffuseColor ((0.957 , 0.831 , 0.498 ));
$mat.Kd = 1.000;
$mat.SetSpecularColor ((1 , 1 , 1 ));
$mat.Ks = 0.500;
$mat.SetEmissiveColor ((0 , 0 , 0 ));
$mat.Ke = 0.000;
$mat.roughness = 3.00;
$mat.brilliance = 10.000;
$mat.alpha = 1.00;
$mat = $obj.NewMaterial ( "Brass");
$mat.LockAmbiantDiffuse = 0;
$mat.SetAmbiantColor ((0.929 , 0.725 , 0.192 ));
$mat.Ka = 0.300;
$mat.SetDiffuseColor ((0.929 , 0.725 , 0.192 ));
$mat.Kd = 1.000;
$mat.SetSpecularColor ((1 , 1 , 1 ));
$mat.Ks = 0.500;
$mat.SetEmissiveColor ((0 , 0 , 0 ));
$mat.Ke = 0.000;
$mat.roughness = 3.00;
$mat.brilliance = 10.000;
$mat.alpha = 1.00;
$mat = $obj.NewMaterial ( "Copper");
$mat.LockAmbiantDiffuse = 0;
$mat.SetAmbiantColor ((0.875 , 0.353 , 0.129 ));
$mat.Ka = 0.300;
$mat.SetDiffuseColor ((0.875 , 0.353 , 0.129 ));
$mat.Kd = 0.700;
$mat.SetSpecularColor ((1 , 1 , 1 ));
$mat.Ks = 0.600;
$mat.SetEmissiveColor ((0 , 0 , 0 ));
$mat.Ke = 0.000;
$mat.roughness = 0.60;
$mat.brilliance = 1.800;
$mat.alpha = 1.00;
$mat = $obj.NewMaterial ( "Silver");
$mat.LockAmbiantDiffuse = 0;
$mat.SetAmbiantColor ((0.714 , 0.714 , 0.8 ));
$mat.Ka = 0.300;
$mat.SetDiffuseColor ((0.714 , 0.714 , 0.8 ));
$mat.Kd = 1.000;
$mat.SetSpecularColor ((1 , 1 , 1 ));
$mat.Ks = 0.500;
$mat.SetEmissiveColor ((0 , 0 , 0 ));
$mat.Ke = 0.000;
$mat.roughness = 3.00;
$mat.brilliance = 6.000;
$mat.alpha = 1.00;
$mat = $obj.NewMaterial ( "Steel");
$mat.LockAmbiantDiffuse = 0;
$mat.SetAmbiantColor ((0.878 , 0.878 , 0.878 ));
$mat.Ka = 0.300;
$mat.SetDiffuseColor ((0.878 , 0.878 , 0.878 ));
$mat.Kd = 0.700;
$mat.SetSpecularColor ((1 , 1 , 1 ));
$mat.Ks = 0.400;
$mat.SetEmissiveColor ((0 , 0 , 0 ));
$mat.Ke = 0.000;
$mat.roughness = 8.00;
$mat.brilliance = 2.000;
$mat.alpha = 1.00;
$mat = $obj.NewMaterial ( "Alien Green");
$mat.LockAmbiantDiffuse = 0;
$mat.SetAmbiantColor ((0.00392 , 0.408 , 0.00392 ));
$mat.Ka = 0.300;
$mat.SetDiffuseColor ((0.0118 , 0.851 , 0.0118 ));
$mat.Kd = 0.700;
$mat.SetSpecularColor ((1 , 1 , 1 ));
$mat.Ks = 0.400;
$mat.SetEmissiveColor ((0 , 0 , 0 ));
$mat.Ke = 0.000;
$mat.roughness = 3.00;
$mat.brilliance = 10.000;
$mat.alpha = 1.00;
</code>

Is there anything I can change in this to get it to send to the file tab in the script editor? I tried changing the first line "object $obj;" to read "file $obj;"
I am assuming that $obj is a variable and this line would be like saying $obj = object;
Thanks
Sage
Logged

sagedavis

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: ASL and working with materials
« Reply #1 on: October 14, 2008, 10:30:48 pm »

ok, never mind, I figured this out. I still don't get why this works, but, I'll explain what I did.

If you replace all instances of $obj with the word project and get rid of line 1 and 3 of the code, it works.

This is kind of weird to me, because you should be able to make $obj equal project, but I couldn't figure out how to do that.

Any thoughts?
Sage
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: ASL and working with materials
« Reply #2 on: October 15, 2008, 05:37:08 am »

I understand your problem....

In the original code "project.curObject" is assigned to "$obj". That means that "$obj" refers to the current object and all the materials will be added in the "object" tab. To get the materials in the "File" tab, you have to replace "$obj" with something that refers to the whole project (not file!). One way would be to create a project type variable and assign the current project to it:
Code: [Select]
project $proj;
$proj = project;

$proj.NewMaterial()
...

This looks pretty messy, because "project" has 2 meanings in ASL. It's a type name and it's a predefined variable that refers to the current project. Thus you don't have to create the "$proj" variable at all, you can only use "project". And that's what you did in the end...

Um... does it make sense?
Logged

sagedavis

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: ASL and working with materials
« Reply #3 on: October 16, 2008, 12:59:23 am »

sort of.

so, taking your snippet for instance.
line one is just declaring that you are going to use a variable $proj, of type project. Line two sets the varialbe $proj to always refer to the predefined variable project (current project).

Since you're a web developer, if I were to put this into PHP terms, it would be the equivilant of saying.

var $proj;
$proj = project;

of course, we can shorten this in PHP to
var $proj = project;
I don't assume we can do the same in ASL?
or casting like
$proj = (project) project;

Thanks for the help Kubajzz.. I've only slightly tinkered with ASL before, but, I'm a PHP (oop), javascript and vb programmer, so, I can speak in those terms (though my vb skills are sort of weak).

Sage
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: ASL and working with materials
« Reply #4 on: October 16, 2008, 07:24:46 am »

Quote from: sagedavis
Since you're a web developer, if I were to put this into PHP terms, it would be the equivilant of saying.

var $proj;
$proj = project;

of course, we can shorten this in PHP to
var $proj = project;
I don't assume we can do the same in ASL?
or casting like
$proj = (project) project;

haha... I'm not a web developer, in fact I don't know anything about PHP... If you look at the javascript code of IconCreator, I guess you'll find a lot of beginner-style mistakes :D I'm learning programming in C#, but I'm on the beginning...

As for your question... ASL doesn't allow you to initialize a variable in the declaration, that's why the whole $proj thing must be in 2 lines.
Logged