Home › Forums › Programming › assign materials with JSfunction
Tagged: javascript ; Assign materials
- This topic has 8 replies, 3 voices, and was last updated 4 years, 1 month ago by rzr87.
-
AuthorPosts
-
2020-11-11 at 12:35 pm #35224rzr87Participant
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
created2020-11-11 at 12:54 pm #35227Yuri KovelenovStaff2020-11-11 at 1:23 pm #35228rzr87ParticipantThanks 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?
2020-11-11 at 2:19 pm #35230Yuri KovelenovStaff2020-11-12 at 7:39 am #35249rzr87ParticipantThanks 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
2020-11-12 at 8:47 am #35252webCustomerJust 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.
2020-11-12 at 9:11 am #35254rzr87ParticipantHi 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?
2020-11-12 at 11:36 am #35278Yuri KovelenovStaffright, 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 herehttps://www.soft8soft.com/docs/manual/en/introduction/Using-JavaScript.html
2020-11-12 at 1:04 pm #35283rzr87ParticipantThanks loads Yuri
Please keep up the good work your software rocks
-
AuthorPosts
- You must be logged in to reply to this topic.