We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

assign materials with JSfunction

Home Forums Programming assign materials with JSfunction

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #35224
    rzr87
    Participant

    Hi there.

    I have successfully setup a GET command in as JSfunction in puzzles. in MyApp.js
    the script is triggered by puzzles and returns a value in which I could setup if and else commands.

    To simplify, the script checks the stock quantity in Woocommerce and if its Zero it needs to change the material on the object that’s out of stock.

    I am no coder so I had to sniff the internet to put this together.

    Right now the script creates a new material on the object with this command:
    var obj = app.scene.getObjectByName(‘Image_2’);
    obj.material = new v3d.MeshBasicMaterial({ color: 0x5c5c5c });

    My question what command do I use to assign a material to the object I already created in Blender
    created

    #35227

    Hi,

    you can get a loaded material as follows:

    var material = v3d.SceneUtils.getMaterialByName(app, "yourMaterialName");

    Chief 3D Verger | LinkedIn | Twitter

    #35228
    rzr87
    Participant

    Thanks for your quick reply.

    Apologies I am no coder. this is what and it still isn’t working.

    app.ExternalInterface.SET1 = function() {

    var obj = app.scene.getObjectByName(‘face’);
    var material = v3d.SceneUtils.getMaterialByName(app,
    “1_GoldMatte”);
    obj.material = material(‘1_GoldMatte’);
    };

    So as a test I have an event that triggers the SET1 jsfunction that needs to change “face” object to the “1_GoldMatte” material.

    The above code is not working :-( what am I doing wrong?

    #35230

    try it like this:

    obj.material = material;

    Chief 3D Verger | LinkedIn | Twitter

    #35249
    rzr87
    Participant

    Thanks again for your help.

    This seems to work but the object then gets a black material applied instead of the Gold matte

    I think its actually assigning a new material but it might be blank.

    This can also work if I can assign a new PBR shader with a texture using Javascript

    #35252
    web
    Customer

    Just a question. But why are you going the Javascript way if you are not a coder, when you have puzzles? They should do the job quite easy for someone without that coding knowledge.

    #35254
    rzr87
    Participant

    Hi there.

    I completely agree. the GET command I am using is in Javascript and it returns a value in which I can use if and else command.

    so IF the item is not in stock it has to change the object to a different material to show its out of stock ELSE it leaves the material as is.

    I am not sure how send the value back to puzzles so should the IF command be triggered, the command to change the material has to be in Javascript.

    Or is there an easier way? :yes:

    #35278

    right, you can trigger the puzzles instead of doing this in code. If you need to change the material, you should use this puzzle
    https://www.soft8soft.com/docs/manual/en/puzzles/Materials.html#assign_material
    which you can trigger from JavaScript as shown here

    https://www.soft8soft.com/docs/manual/en/introduction/Using-JavaScript.html

    Chief 3D Verger | LinkedIn | Twitter

    #35283
    rzr87
    Participant

    Thanks loads Yuri

    Please keep up the good work your software rocks

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.