Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Difficulty with modifying externally texture loading script

kaelgodoy
Registered User
Quote
2021-07-16 23:04:45

I have a problem where I can't get the engine to access the directory that contains the textures. I'm using as base the externally loading texture script that is available on the Ambiera website, and I want to modify it to be able to specify which directory will be used to load the textures.
I have minimal scripting knowledge, the only thing I know is to edit an existing script and create some variables, so I'm stuck editing that script. I've already managed to create a new option to decide where the textures directory will be, I've also already created the variable (I believe), and I also took the opportunity to reduce the names of other properties.
If anyone can help me, I am extremely grateful

Original script:

/*
<action jsname="action_LoadTexture" description="Dynamically load a texture">
<property name="ChangeWhichNode" type="scenenode" />
<property name="MaterialIndexToChange" type="int" default="0" />
<property name="TextureToLoad" type="string" />
</action>
*/

action_LoadTexture = function()
{
};

action_LoadTexture.prototype.execute = function(currentNode)
{
var tex = ccbLoadTexture(this.TextureToLoad);
ccbSetSceneNodeMaterialProperty(this.ChangeWhichNode, this.MaterialIndexToChange, "Texture1", tex);
}


Modified script:

/*
<action jsname="action_LoadTexture" description="Dynamically load a texture">
<property name="ChangeWhichNode" type="scenenode" />
<property name="MaterialIndexToChange" type="int" default="0" />
<property name="DirectoryName" type="string" />
<property name="TextureToLoad" type="string" />
</action>
*/

action_LoadTexture = function()
{
};

action_LoadTexture.prototype.execute = function(currentNode)
{
var index = this.MaterialIndexToChange
var node = this.ChangeWhichNode
var dir = this.DirectoryName;
var tex = ccbLoadTexture(this.TextureToLoad);

ccbSetSceneNodeMaterialProperty(node, index, "Texture1", dir, tex);

}


Oh, and when I open the game, I get a message saying that it was not possible to set the material property because there are a wrong amount of parameters.
(It occurs when I add the variable "dir" to the option "ccbSetSceneNodeMaterialProperty", on line 21).

🔎︎


If the image doesn't appear, this is the link to see it: https://prnt.sc/1bwgmnj


just_in_case
Moderator
Quote
2021-07-17 06:06:38

well as per the above code you using an extra parameters in Line 21, that might be the reason it is not working.

You added the var "dir" as an extra parameter, you need to replace it with tex, but then it will not load the texture because it is just a string value.

by the way, to load textures from a directory you don't need to modify the script just put the directory path along with the texture name in your "texture to load " string parameter in the action.

for example, in your editor, you added the above unmodified original action to a behavior, and suppose there is a texture in a folder named "data"

then you simply put "data/texture.png" in your texture to load, now it will load the texture from that directory if it exists in the project folder.

hope that helps.


kaelgodoy
Registered User
Quote
2021-07-17 06:35:04

Omg, i'm very dumb, hahaha. Thx bro, you saved me. On my game the player has nightmares, so the textures has to change when a trigger activates, and some of these triggers are to change the textures.
Again, thanks for the help :D


Barry
Guest
Quote
2023-02-17 17:03:27

How would you specify the second texture in the model?

For example, texture: 'sam/grey.jpg' works for the first texture but how do I access the second texture?


just_in_case
Moderator
Quote
2023-02-18 03:11:50

@barry, go to irredit/irrlicht properties and you will see 4 textures slot in the materials property there. You can then attach upto 4 textures in there, but they won't work if your material doesn't support multiple textures. It depends on your material type.


Barry
Guest
Quote
2023-02-18 17:54:42

I can see the textures in the model but cant figure out how to access the different texture layers from the script.


just_in_case
Moderator
Quote
2023-02-19 06:00:25

@Barry, I don't know what you are trying to achieve and what are you doing in the script.

In order to get the second texture of a mode via script you can use the below command:

 var s = ccbGetSceneNodeFromName("cubeMesh1");
var secondTexture = ccbGetSceneNodeMaterialProperty(s,0,"Texture2");
print(secondTexture);


it will print the name of the second texture assigned to your cubeMesh1, you can assign second texture to the cubemesh with the help of irredit/irrlicht properties.

Hope that helps :)


Barry
Guest
Quote
2023-02-20 00:07:21

Thanks!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "?nternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact