• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

P3Dv4 Material Scripting

arno

Administrator
Staff member
FSDevConf team
Resource contributor
Messages
32,858
Country
netherlands
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.
 
Messages
28
Country
colombia
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
Messages
32,858
Country
netherlands
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.
 
Messages
5,214
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!
 
Messages
442
Country
malaysia
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.
 
D

Deleted member 1281

Guest
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 by a moderator:
Messages
5,214
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.
 
Messages
442
Country
malaysia
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
Messages
32,858
Country
netherlands
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
Messages
32,858
Country
netherlands
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
Messages
951
Country
germany
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

  • Mercedes.zip
    1.3 MB · Views: 204
Messages
28
Country
colombia
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
Messages
951
Country
germany
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
 
Messages
28
Country
colombia
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?
 
Messages
442
Country
malaysia
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:
D

Deleted member 1281

Guest
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.
 

Christian Bahr

Resource contributor
Messages
951
Country
germany
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 :)
 
Messages
442
Country
malaysia
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.
 
D

Deleted member 1281

Guest
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