custom portaits in my mod

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: custom portaits in my mod

Post by Dr.Disaster »

FeMaiden wrote:you guys keep saying over and over "only keep the definitions for the objects i'm using"
but how do I do that?

all the stuff is jumbled up in this one big folder.

am I supposed to hunt and peck and find each individual texture file related to the object i'm using and then make a new folder to put them in and pull them out and then take the other folders out of my mod assets?
where do I put the defintiions, do I put them in the .lua files that i've been putting all my other custom definitions in? I thought the dmcsb pack had it's own .lua files with all the definitions in them already
You are right, the dmcsb pack has it's own .lua files. Yet this tileset is really vast; it's .lua files define hundreds of objects and all come with their own gfx. If you only want to use two things it is a lot better to take only those parts you need.

I would do this:

1st: change the init.lua to this:

Code: Select all

import "mod_assets/scripts/items.lua"
import "mod_assets/scripts/monsters.lua"
import "mod_assets/scripts/objects.lua"
import "mod_assets/scripts/tiles.lua"
import "mod_assets/scripts/recipes.lua"
import "mod_assets/scripts/spells.lua"
import "mod_assets/scripts/materials.lua"
import "mod_assets/scripts/sounds.lua"
import "mod_assets/ext/grimtk/init.lua"
2nd: add this into your mod_assets/scripts/objects.lua file:

Code: Select all

    defineObject{
       name = "dm_surface_table_square",
       baseObject = "base_altar",
       components = {
          {
             class = "Model",
             model = "mod_assets/models/env/dm_table_square.fbx",
             staticShadow = true,
          },
          {
             class = "Surface",
             offset = vec(0, 0.88, 0),
             size = vec(2.5, 2),
          },
          {
             class = "Clickable",
             offset = vec(0, 0.88, 0),
             size = vec(2.5, 0.88*2, 2),
             maxDistance = 1,
          },
          {
             class = "Obstacle",
             hitSound = "impact_blunt",
          },
       },
       automapIcon = 152,
       tags = {"dm","dm_user","surface"},
    }

    defineObject{
       name = "dm_surface_table_round",
       baseObject = "dm_surface_table_square",
       components = {
          {
             class = "Model",
             model = "mod_assets/models/env/dm_table_round.fbx",
             staticShadow = true,
          },
          {
             class = "Surface",
             offset = vec(0, 0.88, 0),
             size = vec(math.sqrt(2), math.sqrt(2)),
          },
          {
             class = "Clickable",
             offset = vec(0, 0.88, 0),
             size = vec(math.sqrt(2), 0.88*2,math.sqrt(2)),
             maxDistance = 1,
          },
       },
    }

    defineObject{
       name = "dm_surface_bed_brown",
       baseObject = "dm_surface_table_square",
       components = {
          {
             class = "Model",
             model = "mod_assets/models/env/dm_bed_brown.fbx",
             staticShadow = true,
          },
          {
             class = "Surface",
             offset = vec(0.417, 0.46, 0),
             size = vec(1.54, 1.2),
          },
          {
             class = "Clickable",
             offset = vec(0.417, 0.46, 0),
             size = vec(1.54, 0.46*2, 1.2),
             maxDistance = 1,
          },
       },
    }

    defineObject{
       name = "dm_surface_bed_grey",
       baseObject = "dm_surface_bed_brown",
       components = {
          {
             class = "Model",
             model = "mod_assets/models/env/dm_bed_brown.fbx",
             material = "dm_bed_grey",
             staticShadow = true,
          },
       },
    }
3rd: create the folder "mod_assets/models/env" in your mod folder
place copies of dm_table_square.fbx, dm_table_round.fbx and dm_bed_brown.fbx from the dmcsb pack into it

4th: add this into your mod_assets/scripts/materials.lua file:

Code: Select all

        defineMaterial{ -- good normalmap
           name = "dm_bed_brown",
           diffuseMap = "mod_assets/textures/env/dm_bed_brown_dif.tga",
           specularMap = "mod_assets/textures/env/dm_bed_spec.tga",
           normalMap = "mod_assets/textures/env/dm_bed_normal.tga",
           doubleSided = false,
           lighting = true,
           alphaTest = false,
           blendMode = "Opaque",
           textureAddressMode = "Wrap",
           glossiness = 40,
           depthBias = 0,
        }

        defineMaterial{ -- good normalmap
           name = "dm_bed_grey",
           diffuseMap = "mod_assets/textures/env/dm_bed_grey_dif.tga",
           specularMap = "mod_assets/textures/env/dm_bed_spec.tga",
           normalMap = "mod_assets/textures/env/dm_bed_normal.tga",
           doubleSided = false,
           lighting = true,
           alphaTest = false,
           blendMode = "Opaque",
           textureAddressMode = "Wrap",
           glossiness = 40,
           depthBias = 0,
        }
        defineMaterial{ -- degraded normalmap
           name = "dm_table_round",
           diffuseMap = "mod_assets/textures/env/dm_table_round_dif.tga",
           normalMap = "mod_assets/textures/env/dm_table_round_normal.tga",
           specularMap = "mod_assets/textures/env/dm_table_round_spec.tga",
           doubleSided = false,
           lighting = true,
           alphaTest = false,
           blendMode = "Opaque",
           textureAddressMode = "Wrap",
           glossiness = 50,
           depthBias = 0,
        }

        defineMaterial{ -- degraded normalmap
           name = "dm_table_square",
           diffuseMap = "mod_assets/textures/env/dm_table_square_dif.tga",
           normalMap = "mod_assets/textures/env/dm_table_square_normal.tga",
           specularMap = "mod_assets/textures/env/dm_table_square_spec.tga",
           doubleSided = false,
           lighting = true,
           alphaTest = false,
           blendMode = "Opaque",
           textureAddressMode = "Wrap",
           glossiness = 60,
           depthBias = 0,
        }
5th: create the folder "mod_assets/textures/env" in your mod folder
place copies of dm_bed_*.* and dm_table_*.* from the dmcsb into it

6th: remove (!) the dmcsb pack from your mod folder

7th: open your mod in the editor, test and export it
Last edited by Dr.Disaster on Fri Nov 13, 2015 5:18 am, edited 1 time in total.
User avatar
gambit37
Posts: 218
Joined: Fri Mar 02, 2012 3:40 pm

Re: custom portaits in my mod

Post by gambit37 »

EDIT: Dr.Disaster beat me to it with more comprehensive instructions. Nice job :)
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: custom portaits in my mod

Post by Dr.Disaster »

gambit37 wrote:
Dr.Disaster wrote:As minmay has pointed out earlier
minmay wrote:as long as a file is somewhere in the mod_assets folder and ends with .dds, .lua, .model, .animation, .wav, .ogg, or .ivf, it will be exported into the .dat
you need to remove all these files from your mod_assets folder or they will be exported, no matter if used or not. In other words: remove all files except those listed in those objects' definitions.
Is that true? Surely only stuff defined in a Lua file gets exported? Are you saying that the files merely need to exist and they STILL get exported, even if not defined anywhere?
Yes it is true and rather easy to check.

Open the editor, create a new project, place a few things, save and export it. Your export files should not be more then a few kilobytes in size. Now copy the Germanny's tileset into the mod folder of your new project and without doing anything export again. You'll find that your .DAT file is now over 180MB strong.
User avatar
gambit37
Posts: 218
Joined: Fri Mar 02, 2012 3:40 pm

Re: custom portaits in my mod

Post by gambit37 »

Oh! Well that's annoying. I was working on the assumption that only defined things got exported. Understandable why they made it that way though: far easier to compress the whole lot, than selectively check all the definitions.
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: custom portaits in my mod

Post by THOM »

If I want to use an object from an asset-pack I do it always the same way:

1. copy over the model into my model-folder
2. copy over the texture-files into my materials-folder (sometimes I have to look into the model to know, how's the file named)
3. copy over the texture definition into my definition-file and rename the paths to the texture-files
4. copy over the object definition and rename the path to the model-file

sometimes I also have to copy over things like sound-files, sound-definions, particle-systems and so on, but basically these four steps are all you have to do to import a new object.

If I need a lot of a pack (say from the urban_town pack) I do it the other way round: I install the whole pack and erase everything from all files and folders I do not need.

In this way you keep you mod slim...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: custom portaits in my mod

Post by Komag »

THOM's method is the best, and should be done all along from the beginning, so you "always" are fully optimized. :)
Finished Dungeons - complete mods to play
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: custom portaits in my mod

Post by petri »

Guys, welcome to the world of game developement :) For projects I work on, I always try to keep the directories clean. It not only makes things technically easier, it also helps in finding the right files when developing. In big projects there can be tens, if not hundreds of thousands of files to track of. If everything is a mess it slows down development considerably.

Besides, all the asset definitions are Lua, so a talented modder could write a utility script that purges unused files from the mod_assets folder...
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: custom portaits in my mod

Post by Azel »

THOM wrote:If I want to use an object from an asset-pack I do it always the same way:

1. copy over the model into my model-folder
2. copy over the texture-files into my materials-folder (sometimes I have to look into the model to know, how's the file named)
3. copy over the texture definition into my definition-file and rename the paths to the texture-files
4. copy over the object definition and rename the path to the model-file

sometimes I also have to copy over things like sound-files, sound-definions, particle-systems and so on, but basically these four steps are all you have to do to import a new object.

If I need a lot of a pack (say from the urban_town pack) I do it the other way round: I install the whole pack and erase everything from all files and folders I do not need.

In this way you keep you mod slim...
Agreed. I feel like I spent as much time copying/pasting Assets and their References as I did playtesting what I created lol :shock:
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: custom portaits in my mod

Post by THOM »

I love this work. This way you learn to know your assets really...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: custom portaits in my mod

Post by minmay »

gambit37 wrote:This is a good argument for mod makers to define their work on a "module by module" basis. So rather than doing it the Grimrock way and separating things out into the relevant folders, it would make more sense for all the files required for say, the DM bed, to be supplied in a self contained "bed" folder. That would make it much easier for other modders to then selectively include just a few items from a resource pack. (Of course, that brings its own maintenance overhead...)
It would have been a great idea for me to do that if every sound, model and material was used in only one object. But that isn't the case: most materials, and many models and sounds, are used more than once. So the pack would end up having a bunch of duplicated files - which would result in users having to delete a bunch of files anyway, just like they do now, since you probably don't want to include duplicate files in your .dat.
gambit37 wrote:Oh! Well that's annoying. I was working on the assumption that only defined things got exported. Understandable why they made it that way though: far easier to compress the whole lot, than selectively check all the definitions.
Determining whether a file is used would require a very complicated and difficult static analysis because a file can be used dynamically. For example ModelComponent:setModel() and MaterialEx:setTexture() take string arguments that can be any file in the assets or mod_assets folder, and they may not be string constants but something like

Code: Select all

ModelComponent:setModel(string.format("mod_assets/models/cow_on_wheels_%d.fbx",cowNumber))
Of course, if you ONLY use string constants when passing filenames to defineMaterial, setModel, etc., then a simple grep of your mod_assets folder is enough to determine whether a file is used or not.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply