Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 21-Nov-2012 00:06:51

kdkirmse
Member
Registered: 20-Nov-2012
Posts: 4

Change material using script

I am attempting to change a material color within a addsourcecode script and am having some trouble
getting the handle of a material. What follows is my test code.

fun TestColor(string)=
    let (V3DgetSessionView c3dXsession) -> viewstr in
    let V3DgetDefaultSession viewstr -> sessionstr in
    let SO3SceneGetMaterial (V3DgetSession sessionstr)  "V3DdefaultResources" "BaseWhite" -> mat in
    if mat == nil then nil else
    (
        SO3MaterialSetAmbient mat (make_rgba 0 0 255 0);
        SO3MaterialSetDiffuse mat (make_rgba 0 0 255 0);
        SO3MaterialSetSelfIllumination mat (make_rgba 0 0 255 0);
    );
   0;;

I have been trying to figure out the OS3D structure for this kind of access and have not made a lot of progress.

Offline

#2 21-Nov-2012 10:55:37

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: Change material using script

Hi,
What are "some trouble" ?
Are you activate log and console in your Scol settings ?

Offline

#3 21-Nov-2012 18:37:59

kdkirmse
Member
Registered: 20-Nov-2012
Posts: 4

Re: Change material using script

I have modified the function:

fun TestColor(string)=
    _showconsole;
    let (V3DgetSessionView c3dXsession) -> viewstr in
    let V3DgetDefaultSession viewstr -> sessionstr in
    let SO3SceneGetMaterial (V3DgetSession sessionstr)  "V3DdefaultResources" "BaseWhite" -> mat in
    if mat == nil then
    (
        _fooS "material not found";
        0;
    )
    else
    (
        _fooS "action";
        SO3MaterialSetAmbient mat (make_rgba 0 0 255 0);
        SO3MaterialSetDiffuse mat (make_rgba 0 0 255 0);
        SO3MaterialSetSelfIllumination mat (make_rgba 0 0 255 0);
        0;
    );;

The log shows

> Action : Scene.Test Color.Run with param : abc and reply param : Scene.Key_3

The console shows:

loading tmp/tmp3891288.pkg ...
typechecking
fun TestColor : fun [u0] I
Generating bytescodes for 'TestColor' ...
167 bytes generated (for a total of 15632) 
Loading Complete

> exec: TestColor "abc"

material not found

Offline

#4 21-Nov-2012 19:31:08

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: Change material using script

kdkirmse wrote:
loading tmp/tmp3891288.pkg ...
typechecking
fun TestColor : fun [u0] I
Generating bytescodes for 'TestColor' ...
167 bytes generated (for a total of 15632) 
Loading Complete

> exec: TestColor "abc"

material not found

The material is not found ... So, the variable 'mat' is at nil when you execute this function.
A material named "BaseWhite" already exists in the loaded 3d scene at this moment ? It seems that not.

What is "abc" ? If it is the name of the material, you should put it in SO3SceneGetMaterial like that :

let SO3SceneGetMaterial (V3DgetSession sessionstr)  "V3DdefaultResources" string -> mat in

Offline

#5 21-Nov-2012 19:46:25

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: Change material using script

Hello,

first you can directly use (V3DgetSession c3dXsession)
then BaseWhite is not part of the "V3DdefaultResources" group.
and this material is not supposed to be changed.

try with a material from a scene, you can see how on material color plugIT
\os3dplugins\material\matcolor\cmatcolor.pkg

Offline

#6 21-Nov-2012 19:48:37

kdkirmse
Member
Registered: 20-Nov-2012
Posts: 4

Re: Change material using script

I am not using the "abc" parameter at the moment.

As a test I changed the color of "BaseWhite" using a "material color inst" plugIt and have seen the expected color change

Offline

#7 21-Nov-2012 20:22:12

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: Change material using script

Try using the group name "Scene" in the editor

Offline

#8 21-Nov-2012 20:49:09

kdkirmse
Member
Registered: 20-Nov-2012
Posts: 4

Re: Change material using script

I changed the group to "Scene" and that worked.

Thank You

Offline

Board footer

Powered by FluxBB