id Tech Forums

id Tech 4 (Doom3/Prey/Q4) => id Tech 4 Textures => Topic started by: spamclark15 on August 14, 2017, 11:27:15 PM

Title: Another Material Question
Post by: spamclark15 on August 14, 2017, 11:27:15 PM
I've been looking through all the material files looking for where these door lights are defined. I edited some for the longer red/green lights on other types of doors, but I haven't found where these are defined. Does anyone know either how to figure out what material is being used or know the material?
Title: Re: Another Material Question
Post by: MrC on August 15, 2017, 05:53:10 PM
There's probably a better way, but I just opened the lwo in notepad and saw models/mapobjects/doors/doorlocklightg which may be what you're looking for, a find in files in notepad++ returned with materials\senetemp.mtr hope that helps.
Title: Re: Another Material Question
Post by: spamclark15 on August 15, 2017, 07:46:33 PM
Awesome. How did you know which mesh to look at?
Title: Re: Another Material Question
Post by: MrC on August 15, 2017, 07:58:14 PM
Awesome. How did you know which mesh to look at?

Just browsed for it in the editor.
Title: Re: Another Material Question
Post by: spamclark15 on August 15, 2017, 11:03:42 PM
What part of the editor should I use?
Title: Re: Another Material Question
Post by: argoon on August 15, 2017, 11:24:18 PM
What part of the editor should I use?

open the game console and type:

r_showSurfaceInfo

This console command will show the material name of the surface directly under the crosshair, unfortunately it will also detect invisible materials, so you need to move around until it shows a material name that makes sense.
Title: Re: Another Material Question
Post by: spamclark15 on August 15, 2017, 11:39:39 PM
Thanks, that is very useful.
Title: Re: Another Material Question
Post by: spamclark15 on August 30, 2017, 08:48:00 AM
I'm replacing the wheels on the tablecart but trying to use deform sprite to get the 2D image of the wheels I'm not understanding. If I write it like this:

Code: [Select]
models/mapobjects/tablecart1ball
{
deform sprite
bumpmap addnormals(models/mapobjects/lab/labcart_wheel/poppawheely_local.tga, heightmap(models/mapobjects/lab/labcart_wheel/poppawheely_h.tga, 4 ) )
specularmap models/mapobjects/lab/labcart_wheel/poppawheely_s.tga
{
map models/mapobjects/lab/labcart_wheel/poppawheely_d.tga
blend diffusemap
alphatest .9
}
}

The result is wheels that show up totally black in-game. If there's some limitation to deform sprite, I rewrote it to just:

Code: [Select]
models/mapobjects/tablecart1ball
{
deform sprite
{
blend blend
map models/mapobjects/lab/labcart_wheel/poppawheely_d.tga
}
}

With this, it appears the same brightness no matter what. Does anyone know what is wrong with the first material that causes it to draw black or why the second ignores the light in the room?
Title: Re: Another Material Question
Post by: argoon on August 30, 2017, 01:13:24 PM
I don't work with materials for a very long time now, focusing on coding, so my memory is a little rusty about it but i seam to remember when i was playing with grass that deform sprite automatically uses translucency even if you don't write it explicitly, because of that it doesn't support normal maps or specular maps, there the black material error, afaik deform sprite was written by id for lights glow and the gun muzzleflash's, because of this i ended writing my own "always look to the player" script, is not very hard will see if i still have it somewhere.

ok here it is:

Code: [Select]
void player::lookAtPlayer( entity ent )
{
vector plAngles = self.getViewAngles();

plAngles_x = 0;
plAngles_y = plAngles_y + 90;
plAngles_z = 0;
ent.setAngles(plAngles);
}
   
Title: Re: Another Material Question
Post by: spamclark15 on August 30, 2017, 04:28:15 PM
Thanks. How do I use it?
Title: Re: Another Material Question
Post by: argoon on August 30, 2017, 05:34:37 PM
For this particular function you need to put it on the player script.

Like this.

on the player script inside the player object write:

void lookAtPlayer( entity ent );

then outside the player object, below the Init() function write the function i posted, btw put the code inside the lookAtPlayer function, the one inside the {},
inside the following code:

eachFrame { past the code here }

then inside the player Init() function write this:

thread lookAtPlayer($entityName);    // entityname is the name of the object you want to always look at the player;

and that's it.

There's a serious problem with this code tho, because it runs from the player script side, unfortunately makes it very complex for multiple objects, this way you need to write "thread lookAtPlayer($entityName);" for every single object you want to always look at the player! Not pretty.

But if you make it run from the object script instead (if it has one), then you just need to pass in the player ($player1) to a single look at function and multiple objects (of that type) will then look at the player just fine.

I recommend that you learn how to script is very important if you want to make more complex modifications to the game.
But for now, here is a small tutorial in how to create a new BASIC game object script, hope this make you want to learn more:

1 - inside the scripts folder create a new txt file

2 - rename it to lookAt and change the .txt extension to .script

3 - inside the script file past the following code:

Code: [Select]
#ifndef _LOOK_AT_
#define _LOOK_AT_

object lookAT {


vector plAngles;

entity player;


void init();
void lookAtPlayer();
};

void lookAT::init()
{
player = $player1;

        thread lookAtPlayer();
}


void lookAT::lookAtPlayer()
{
      eachFrame
      {
           plAngles = player.getViewAngles();

   plAngles_x = 0;
   plAngles_y = plAngles_y + 90;
   plAngles_z = 0;
   self.setAngles(plAngles);
      }
}
#endif


5 - open the doom_main.script

and past the following code after the ai_base script

Code: [Select]
#include "script/lookAt.script"

6 - open the editor, select the entity you want the script to run on

8 - write the following key value par:

key - scriptobject
value - lookAT

9 - Run the map
 
Title: Re: Another Material Question
Post by: spamclark15 on August 31, 2017, 04:35:12 AM
models/mapobjects/tablecart1ball

This is the object that I want it to apply to. When you say player script, you mean doom_main.script? There's no player.script. Is this all 1 set of instructions or 2 ways of doing it?
Title: Re: Another Material Question
Post by: argoon on August 31, 2017, 08:21:21 AM
There is a player script, look carefully, is not called player.script but has player written on its file name. ;)

Imo what i wrote is very explicit, but maybe is because i wrote it, and others maybe have problems reading it, i don't know, ok what i posted was two ways for doing this, one (bad way) from the player script side and one where you make a new script.
Title: Re: Another Material Question
Post by: bitterman on August 31, 2017, 11:44:12 AM
argoon thanks for your posts.

Сan I ask a few questions about example above?

1. What is the expression '#ifndef' (it's not about general purpose, it's about D3 scripting)?

2. If entity on the map have a scriptobject and init() as described above then it (init) will be start at start of level? IMO this is not typical behavior for level script wich must be placed in /maps, not in /script.
Title: Re: Another Material Question
Post by: spamclark15 on August 31, 2017, 05:31:28 PM
You mention the entity and the map, but it's not a single entity but rather all instances of a material I need it to work on, and that's on any map.
Title: Re: Another Material Question
Post by: argoon on August 31, 2017, 09:27:19 PM
argoon thanks for your posts.

Сan I ask a few questions about example above?

1. What is the expression '#ifndef' (it's not about general purpose, it's about D3 scripting)?

2. If entity on the map have a scriptobject and init() as described above then it (init) will be start at start of level? IMO this is not typical behavior for level script wich must be placed in /maps, not in /script.

Those are called pre-processor keywords on c and c++, they are special keywords that are run before the script compiler, they are used by script engine to create macros and Global variables, etc. In this case i'm defining _LOOK_AT_  before compilation so any variable i put inside this script doesn't conflits with variables with the same name on other script files.  Is akin to using the:  "using namespace mapname" keyword for map scripts.

About the second question, this is not a map script, this is a object script and those go on the script folder, init() in a object script is just like constructors in c++, so any function inside init() will run at the exact moment the entity (object) spawns in the game, it can be at level start or not.

Quote
You mention the entity and the map, but it's not a single entity but rather all instances of a material I need it to work on, and that's on any map.

object scripts run on any map the object exists, because they are called by the entities them self's at spawn time.

To know more about this i recommend that you guys read about OOP programming (Object Oriented Programming).   
Title: Re: Another Material Question
Post by: spamclark15 on August 31, 2017, 09:46:15 PM
Would love to learn more, but I'm already busy now studying something else. :|

I'm wondering what I should put in for "$entityName". I'm working with models/mapobjects/tablecart1ball, so would tablecart1ball be the entity name?
Title: Re: Another Material Question
Post by: bitterman on September 01, 2017, 11:44:28 PM
Btw when I try to replace 'while(1)' to 'eachFrame' (for level script) I get an error "Built-in function can't be used without an object".

Title: Re: Another Material Question
Post by: Phrozo on September 02, 2017, 09:13:35 AM
Try sys.eachFrame
Title: Re: Another Material Question
Post by: Phrozo on September 02, 2017, 09:35:16 AM
models/mapobjects/tablecart1ball

This is the object that I want it to apply to. When you say player script, you mean doom_main.script? There's no player.script. Is this all 1 set of instructions or 2 ways of doing it?

That isn't a object, its a material. That script won't help you without one.
Title: Re: Another Material Question
Post by: argoon on September 02, 2017, 09:44:19 AM
Btw when I try to replace 'while(1)' to 'eachFrame' (for level script) I get an error "Built-in function can't be used without an object".

Hum I didn't knew that was locked to objects only, need to study why, I'm working on engine c++ so have not scripted any level for a while now.
I'm not near my computer tho so will see later, for now continue using while loop for level scripting as always, sorry.

Try sys.eachFrame

sys is indeed a object but eachframe that I recommend is not a c++ function, callable by sys, is just a script macro made using #define, it is written at the bottom of the doom_defs.script if I'm recalling correctly.


models/mapobjects/tablecart1ball

This is the object that I want it to apply to. When you say player script, you mean doom_main.script? There's no player.script. Is this all 1 set of instructions or 2 ways of doing it?

That isn't a object, its a material. That script won't help you without one.

Exactly my script needs to be assigned to a entity in the editor or on a def file, it has no knowledge of materials it will only change the yaw (rotation) of a object no matter the materials on its surface.



bitterman add a thought, I assume you're calling your map script from within the map folder, using the script with the map name next to the map file,  perhaps that is why it doesn't work, if you open the script folder you see Id software put map scripts there as well, and call them from the doom_main.script just like with objects. The difference with this method is that you need to enclose your script code inside a "use namespace mapname" or all function/variables names will conflict with each other.
Title: Re: Another Material Question
Post by: spamclark15 on September 03, 2017, 03:55:00 AM
models/mapobjects/tablecart1ball

This is the object that I want it to apply to. When you say player script, you mean doom_main.script? There's no player.script. Is this all 1 set of instructions or 2 ways of doing it?

That isn't a object, its a material. That script won't help you without one.

So much for that...
Title: Re: Another Material Question
Post by: argoon on September 03, 2017, 10:44:33 AM
models/mapobjects/tablecart1ball

This is the object that I want it to apply to. When you say player script, you mean doom_main.script? There's no player.script. Is this all 1 set of instructions or 2 ways of doing it?

That isn't a object, its a material. That script won't help you without one.

So much for that...

Materials are attached to objects, deform sprite also rotates the object not the material itself plus deform sprite requires models made of a single flat face (a plane), wheres my script works with any object.
You need to find, using the editor, all the objects using that material, Dark Radiant (from the DarkMod) has a option where it will select all objects using the same material, with all selected you can assign the key value, i suggested, to all of them at the same time.
Title: Re: Another Material Question
Post by: spamclark15 on September 04, 2017, 02:26:25 AM
There are table carts throughout the game though.
Title: Re: Another Material Question
Post by: Phrozo on September 04, 2017, 03:48:50 AM
Try finding the entity def of these table carts you are talking about.

If I recall r_showSurfaceInfo set to 1 should show the entity def of what you are looking at. If not try grabbing the table cart with editAFs. If not that, type editDecls in console and search for 'models/mapobjects/tablecart1ball'. Check under entityDefs for any possible hits.
Title: Re: Another Material Question
Post by: spamclark15 on September 04, 2017, 04:17:21 AM
r_showsurfaceinfo comes back with models/mapobjects/tablecart2 and the files for them are in models/mapobjects/lab/tablecart1 and tablecart2
Title: Re: Another Material Question
Post by: Phrozo on September 04, 2017, 04:19:55 AM
That's a material...
Title: Re: Another Material Question
Post by: spamclark15 on September 04, 2017, 04:31:35 AM
moveable_compcart, moveable_tablecart1, moveable_tablecart2

These are the entity defs. These 3 all use that wheel material.
Title: Re: Another Material Question
Post by: Phrozo on September 04, 2017, 10:43:28 AM
Now you can try scripting for these table carts. Make a new script file if you haven't already.


If you are not sure which one to edit just edit all of them and add the key "scriptobject" with the name of the script object you made in quotes. Then when they spawn, each table cart will run that script.
Title: Re: Another Material Question
Post by: spamclark15 on September 04, 2017, 12:12:48 PM
Alright, created lookat.script, containing:

Code: [Select]
#ifndef _LOOK_AT_
#define _LOOK_AT_

object lookAT {


vector plAngles;

entity player;


void init();
void lookAtPlayer();
};

void lookAT::init()
{
player = $player1;

        thread lookAtPlayer();
}


void lookAT::lookAtPlayer()
{
      eachFrame
      {
           plAngles = player.getViewAngles();

   plAngles_x = 0;
   plAngles_y = plAngles_y + 90;
   plAngles_z = 0;
   self.setAngles(plAngles);
      }
}
#endif

Changed doom_main.script to contain:

Code: [Select]
#include "script/ai_base.script"
#include "script/lookat.script"

The 3 carts are found within moveable.def. Other than map files, this is the only file that makes reference to those entity defs. I'm not clear on what to do next. I'm adding "lookat" to another script file?
Title: Re: Another Material Question
Post by: Phrozo on September 04, 2017, 12:48:59 PM
Okay good, you included your scripts. Now just edit each tablecart entityDef you mentioned in moveable.def to include a new line with this code somewhere among all the other key/value strings.
Code: [Select]
"scriptobject" "lookAt"

Launch the game and look at a table cart in game and see if you notice anything.
Title: Re: Another Material Question
Post by: spamclark15 on September 04, 2017, 01:05:04 PM
Changed 3 entityDefs in moveable.def to:

Code: [Select]
entityDef moveable_compcart {
"inherit" "moveable_base_fixed"
"model" "models/mapobjects/lab/compcart/compcart.lwo"
"density" "0.02"
"friction" "0.2"
"bouncyness" "0.2"
"snd_bounce" "cart_impact"
"scriptobject" "lookAt"
}

entityDef moveable_tablecart1 {
"inherit" "moveable_base_fixed"
"model" "models/mapobjects/lab/tablecart1/tablecart1.lwo"
"density" "0.01"
"friction" "0.1"
"bouncyness" "0.3"
"snd_bounce" "cart_impact"
"scriptobject" "lookAt"
}

entityDef moveable_tablecart2 {
"inherit" "moveable_base_fixed"
"model" "models/mapobjects/lab/tablecart2/tablecart2.lwo"
"density" "0.01"
"friction" "0.1"
"bouncyness" "0.3"
"snd_bounce" "cart_impact"
"scriptobject" "lookAt"
}

Trying to load a map with one of these results in:

Code: [Select]
WARNING: idScriptObject::SetType: Can't create object of type 'lookAt'.  Must
be an object type.
--------- Game Map Shutdown ----------
--------------------------------------
********************
ERROR: Script object 'lookAt' not found on entity 'moveable_tablecart2_6'.
********************
Title: Re: Another Material Question
Post by: Phrozo on September 04, 2017, 01:14:39 PM
I miss read your object name. It isn't 'lookAt' it's 'lookAT' so change it and try again.
Title: Re: Another Material Question
Post by: spamclark15 on September 04, 2017, 07:06:21 PM
Alright, I tried it out and the entire carts turn to face me. :o I need to find the 1ball entity but all I can find are the material and skin.
Title: Re: Another Material Question
Post by: Phrozo on September 04, 2017, 10:44:22 PM
What exactly is the desired effect you want?
Title: Re: Another Material Question
Post by: spamclark15 on September 04, 2017, 10:59:08 PM
For the wheels to have this behavior as they're flat. The problem is that using deform sprite on their material turns them completely black. This can be prevented by changing the material to just a single texture, but then they appear fullbright.
Title: Re: Another Material Question
Post by: spamclark15 on September 04, 2017, 11:04:35 PM
What I thought would work is if the latter appear fullbright but are otherwise functional, to find some way of writing the material for the wheels so that they show up at the right brightness but I haven't thought of any way of doing this without adding another texture which would cause them to appear black. It's like I'm trading problems.
Title: Re: Another Material Question
Post by: Phrozo on September 05, 2017, 06:41:52 AM
Just for clarity.
Code: [Select]
models/mapobjects/tablecart1ball
{
deform sprite
{
blend blend
map models/mapobjects/lab/labcart_wheel/poppawheely_d.tga
}
}

Not all blend modes interact with light, such as blend, add, or filter. Blend mode blend is often used for opaque particles like dust or smoke and is rendered based on how strong the alpha parameter is.

Looking through the source code deform sprite doesn't appear to work correctly with light interaction so stages like normalmap, diffusemap, and specularmap may not work at all with deform, but I can't say for certain.
Title: Re: Another Material Question
Post by: spamclark15 on September 05, 2017, 03:19:23 PM
Yes, that is what I had for the material. It is always fully bright.
Title: Re: Another Material Question
Post by: spamclark15 on September 12, 2017, 09:09:32 AM
Would you happen to know where the light color from the GUI on a viewweapon is set? The .gui files for the weapons that have GUIs apparently don't set it.
Title: Re: Another Material Question
Post by: Phrozo on September 13, 2017, 02:31:53 AM
The color is hard set in the material being used for the weapon gui lights, which is 'lights/viewWeaponGuiLight' found in lights.mtr.
Title: Re: Another Material Question
Post by: spamclark15 on September 13, 2017, 09:12:39 AM
Thanks! Also dealing with materials, I'm trying to rewrite the gui/hell/stamina material to scroll only a single TGA but getting it to do 3 things simultaneously, that is, scroll, have translucency, and exist within the box for stamina is proving to be difficult. Currently I have it written:

Code: [Select]
gui/hell/stamina
{
{
blend blend
map guis/assets/hud/mp/lstafill2.tga
// colored
}

{
maskcolor
map guis/assets/hud/mp/lstafill2.tga
scroll time * -1, 0
// colored
}

This reuses the top part of the original code where lstafill2.tga has an alpha channel the shape of the stamina bar. Since I don't want all the effects that the original material had which combined more than one image together, this has been a challenging material to figure out so I'm sort of lost at this point.