P3Dv4 Material Scripting

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#41
If you are exporting from the GPW as P3D v4 and you have the script added in the material already in the MDL file you import, it should remain.
 
#42
Thanks for the answer Arno. I am exporting as P3D4.4 and it seems to remain because the content error is displaying errors related to the .lua script. My issue is that the error displaying has nothing to do to a Lua script and the script itself does not work. I will try as P3Dv4, I don't know if there is a change in exporting as 4 or 4.4.
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#43
I'm not really familiar with the scripts themself, so I'm afraid I can't help with that. From the mdl point of view the scripts didnit change.
 
#45
In a scenerydesign.org thread of 2017, Arno mentioned a possibility to add visibility conditions to the model.def.xml and you then have to add it in the hierarchy editor to the model part visibility conditions. However, I do not know if he implemented it in MCX as there is no possibility to write in visibility conditions other than the ones that come in a drop down menu!
 
#46
I suspect there is problem with MCX to MDL 4.4 export. When i load the model from here into P3D, everything works finely. Then, I import the similar MDL file into MCX and add PBR materials and export back to MDL v4.4. I placed the new MDL model into similar location replacing the oldest one. Loaded P3D and the script is not working. So where is the problem actually? Is it in MCX itself or the XtoMDL export is not saving the value into MDL file?

To double confirm this, i created my own cube and added the similar script into the model and add texture. Load up into P3D, everything works. But, when i export into MDL v4.4 with PBR texture, then it's not working.
 
#47
Did this test with an aircraft model, using the following steps, basically replicating the F-16 pattern:

1- Created a 'script' folder within the aircraft folder.
2 - added a script called 'Bev_01_night.lua' to the folder using mask 0x0004, which is the landing lights identifier:
Code:
!lua
if varget("A:LIGHT STATES", "Mask") & 0x0004 > 0 then
  varset("T:EmissiveTexture", "string", "Bev_01_night.dds")
  varset("T:EmissiveScale", "number", 0.25)
else
  varset("T:EmissiveTexture", "string", "")
end
3-- added Bev_01_night.dds to the aircraft's texture folder.
4 -- added the name of the lua file to one of the materials in MCX's material editor. (Note, did not specify an emissive file.)
5 -- compiled the model to V 4.4 / 4.5
6 -- Loaded the model in sim and turned landing lights on and off -- worked fine.
 
Last edited:
#48
I guess I have to put my remarks in another thread because I am not talking of Lua script but of an alternative to it for certain applications.
 
#49
Did this test with an aircraft model, using the following steps, basically replicating the F-16 pattern:

1- Created a 'script' folder within the aircraft folder.
2 - added a script called 'Bev_01_night.lua' to the folder using mask 0x0004, which is the landing lights identifier:
Code:
!lua
if varget("A:LIGHT STATES", "Mask") & 0x0004 > 0 then
  varset("T:EmissiveTexture", "string", "Bev_01_night.dds")
  varset("T:EmissiveScale", "number", 0.25)
else
  varset("T:EmissiveTexture", "string", "")
end
3-- added Bev_01_night.dds to the aircraft's texture folder.
4 -- added the name of the lua file to one of the materials in MCX's material editor. (Note, did not specify an emissive file.)
5 -- compiled the model to V 4.4 / 4.5
6 -- Loaded the model in sim and turned landing lights on and off -- worked fine.
Could you please try that with precipitation lua script with PBR materials?
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#50
I suspect there is problem with MCX to MDL 4.4 export. When i load the model from here into P3D, everything works finely. Then, I import the similar MDL file into MCX and add PBR materials and export back to MDL v4.4. I placed the new MDL model into similar location replacing the oldest one. Loaded P3D and the script is not working. So where is the problem actually? Is it in MCX itself or the XtoMDL export is not saving the value into MDL file?

To double confirm this, i created my own cube and added the similar script into the model and add texture. Load up into P3D, everything works. But, when i export into MDL v4.4 with PBR texture, then it's not working.
I just did an export of that model with PBR materials here, but in the material settings the script is still present. So the information about the script is not lost in the process. I don't have enough knowledge about how the script itself works.
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#51
I just had a look at the script and it seems to change the diffuse texture based on a raining state. For a PBR material would it not have to change the albedo texture instead? Seems to me that you can't use the same script with PBR materials.
 

Christian Bahr

Resource contributor
#52
Could you please try that with precipitation lua script with PBR materials?
Hi.

I'm not sure if that's what you mean. But out of boredom and out of pure curiosity I wrote a little LUA script some time ago. This script ensures that the texture of a vehicle changes as it starts to rain ...

p3dv4_lua_script_texture_change_rain.jpg



Code:
!lua

--Get precip state.
local raining = 0x00000004
local precipState = varget("A:AMBIENT PRECIP STATE", "Mask")
precipState = math.floor(precipState)

--Define textures.
textureDry= "mercedes_cls_diffuse_dark_blue.dds"
textureWet = "mercedes_cls_diffuse_gold.dds"

if precipState == raining then

varset("T:DiffuseTexture", "string", textureWet)

else

varset("T:DiffuseTexture", "string", textureDry)
end

Even if it is not PBR textures, it helps a bit further. And maybe someone who is more familiar with LUA can check the consistency of the script.

The Mercedes I have put together as an Addon Package. To test the vehicle and the LUA script you should add the Mercedes CLS as Add-on Package in P3Dv4 :)
 

Attachments

#53
Hi.

I'm not sure if that's what you mean. But out of boredom and out of pure curiosity I wrote a little LUA script some time ago. This script ensures that the texture of a vehicle changes as it starts to rain ...

View attachment 49564


Code:
!lua

--Get precip state.
local raining = 0x00000004
local precipState = varget("A:AMBIENT PRECIP STATE", "Mask")
precipState = math.floor(precipState)

--Define textures.
textureDry= "mercedes_cls_diffuse_dark_blue.dds"
textureWet = "mercedes_cls_diffuse_gold.dds"

if precipState == raining then

varset("T:DiffuseTexture", "string", textureWet)

else

varset("T:DiffuseTexture", "string", textureDry)
end

Even if it is not PBR textures, it helps a bit further. And maybe someone who is more familiar with LUA can check the consistency of the script.

The Mercedes I have put together as an Addon Package. To test the vehicle and the LUA script you should add the Mercedes CLS as Add-on Package in P3Dv4 :)
Great! Some questions...

Is this a PBR material or a standard one?
How was the workflow to achieve this? Max, export MDL, library? or MCX?
In 3dsmax did you add some Diffuse texture image or left it blank?
 

Christian Bahr

Resource contributor
#54
Is this a PBR material or a standard one?
How was the workflow to achieve this? Max, export MDL, library? or MCX?
In 3dsmax did you add some Diffuse texture image or left it blank?
This is standard P3D material, no PBR material.

Material settings and export via 3dsm as mdl file.

The diffused channel can remain empty, the textures are assigned by the script during runtime in the P3D.

3dsm_p3d_material_lua_script.jpg
 
#55
This is standard P3D material, no PBR material.

Material settings and export via 3dsm as mdl file.

The diffused channel can remain empty, the textures are assigned by the script during runtime in the P3D.

View attachment 49566
Thanks. I will try that. Last time I tried was not different from what you have, the only different thing I did was to specify the diffuse image in 3ds max. Hope with out specifying it works.

One last questions. In the error log of P3d when you closes it there appear some script errors? Is this normal?
 
#56
I just had a look at the script and it seems to change the diffuse texture based on a raining state. For a PBR material would it not have to change the albedo texture instead? Seems to me that you can't use the same script with PBR materials.
You are correct. Based on the material variables' section in the SDK, PBR texture has different script.

Standard Material variables Script Code:
XML:
varset("T:DiffuseTexture", "string", "YOUR TEXTURE.DDS")
PBR Material variables Script Code:
XML:
varset("T:AlbedoTexture", "string", "YOUR TEXTURE.DDS")
Hi.

I'm not sure if that's what you mean. But out of boredom and out of pure curiosity I wrote a little LUA script some time ago. This script ensures that the texture of a vehicle changes as it starts to rain ...

View attachment 49564


Code:
!lua

--Get precip state.
local raining = 0x00000004
local precipState = varget("A:AMBIENT PRECIP STATE", "Mask")
precipState = math.floor(precipState)

--Define textures.
textureDry= "mercedes_cls_diffuse_dark_blue.dds"
textureWet = "mercedes_cls_diffuse_gold.dds"

if precipState == raining then

varset("T:DiffuseTexture", "string", textureWet)

else

varset("T:DiffuseTexture", "string", textureDry)
end

Even if it is not PBR textures, it helps a bit further. And maybe someone who is more familiar with LUA can check the consistency of the script.

The Mercedes I have put together as an Addon Package. To test the vehicle and the LUA script you should add the Mercedes CLS as Add-on Package in P3Dv4 :)
Thanks for the attachment and codes.

I have tried changing the code for PBR materials and finally, it works!
Here are the sample images:
1557971908962.png 1557971941475.png

Edit:
Preview: Testing with PBR Material

Screenshot (7).png Screenshot (11).png Screenshot (8).png Screenshot (9).png
 
Last edited:

Christian Bahr

Resource contributor
#58
One last questions. In the error log of P3d when you closes it there appear some script errors? Is this normal?
Unfortunately I can not answer exactly. The error logging in the P3D I have switched off :)

The standard precipitation script in folder 'scripts' (PrecipWindshieldEffect.lua) can be used to tweak a VC_reflection material to show moving raindrops on the windshield -- just copy the V4 Mooney material parameters and export as V4.4/5.
I tried that with the Porsche Carrera GT, however without coming to a success. But maybe I'll find the time and pleasure again and try again. Raindrops on the car windows would be pretty cool :)
 
#59
The standard precipitation script in folder 'scripts' (PrecipWindshieldEffect.lua) can be used to tweak a VC_reflection material to show moving raindrops on the windshield -- just copy the V4 Mooney material parameters and export as V4.4/5.
I tried this but couldn’t see the effects on the windshield of the car.
 
#60
Don't expect too much, the VC raindrops effect isn't all that amazing - just a few drops appearing and disappearing as in the Mooney, the 2D view is better but then who wants that... but on that topic, has anybody managed to get A2A's free windshield effect working for their own aircraft?
 
Top