Foundation

Foundation

Foundation is a grid-less, sprawling medieval city building simulation with a heavy focus on organic development and monument creation.

Learn more and find the game on Steam, GOG.com, Facebook, Twitter, Youtube.

How to add scaling to any decoration

This guide will go step by step through the process of making your models scalable.

Posted by on (updated ago)


Wondering how to make your Foundation models scalable? Look no further!

This guide is intended as a follow-up to my other beginners guide. If you're just looking to get started please go back to my other guide.

Below is an (optional) complete downloadable version of this mod. Also included inside the zip is an original .blend file for reference.

RaisinMuffin's Modding Tutorial - Scaling


The first thing to know is that scaling is made up of a couple of different parts:

  • End Part - The top of the building part
  • Root Part - The bottom of the building part
  • Tiling Part - The middle of the building part

This can be used to make buildings have multiple floors or, in our case, "float" a decoration up higher.

Step 1 - Blend File

A few new locaters need to be added within the .fbx file as shown below. You can use the .blend files from the optional download above as reference here.

Since we want our models to "float", we only need a model within the "End_Part". The other two will have no models in them.

In the below picture, I have 2 models. "Cube_Part" and "Cube_Large_Part" are going to be my "End_Part".

This will make more sense when we get to the coding part.

  • The "End_Part" gets an "Attach_Bottom".
  • The "Root_Part" gets both an "Attach_Bottom" and an "Attach_Top".
  • The "Tiling_Part" also gets both an "Attach_Bottom" and an "Attach_Top".


orientation

As you can see above they need to be rotated the correct way so these nodes can snap together.

The direction the X axis faces is the front facing direction:

  • Attach_Top - X has to face up
  • Attach_Bottom - X has to face down

You can display the axis of the locator within the object properties as show above under viewport display.

Below is the setup you should find in the .blend files within the mod download above.

I prefer to stack my parts closer together and scale all of the attach nodes down by .5, however you can just leave them full sized which works fine as well.


Step 2a - Mod.lua File - Asset Processor

First thing we register is the "Asset Processor".

This is necessary for the scaling nodes to work properly.

It is used for more than just this purpose but we won't get into those in this tutorial. Just make sure it's registered for each .fbx you're using in your mod.

Tutorial:registerAssetProcessor("models/cube.fbx", {
	DataType = "BUILDING_ASSET_PROCESSOR"
})

Step 2b - Mod.lua File - Asset IDs

Here we register two new ids for the "Root_Part" and "Tiling_Part".

Tutorial:registerAssetId("models/cube.fbx/Prefab/Root_Part", "PREFAB_ROOT_PART")
Tutorial:registerAssetId("models/cube.fbx/Prefab/Tiling_Part", "PREFAB_TILING_PART")

Step 2c - Mod.lua File - Scaling Parts

Here we register the "Building_Part" for the "Tiling_Part".

Tutorial:registerAsset({
	DataType = "BUILDING_PART",
	Id = "TILING",
	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_DEFAULT",
		CoreObjectPrefab = "PREFAB_TILING_PART"
	}
})

Step 2d - Mod.lua File - Building Parts

Here we register a slightly different version of a building part. We simply just changed the ConstructorData and created an extra "Building_Part".

Below you can see that our "Root_Part" goes in "CoreObjectPrefab".

"Tiling_Part" goes in the "FillerList" and "BasementFillerList".

The model we'll use needs to be a building part like before so we'll put our model, which in this case is "PREFAB_CUBE_PART", into its own "Building_Part".

Take that Id , "CUBE", and put it into "EndPart" in a separate "Building_Part". Then use that "Building_Part" Id, which is "CUBE_PART", for the main monument list.

You will need a new copy of this code below for each object you want in your mod. So for this mod we'll have 2, one for "Cube_Part" and one for "Cube_Large_Part".

Tutorial:registerAsset({
	DataType = "BUILDING_PART",
	Id = "CUBE_PART",
	Name = "CUBE_NAME",
	Description = "CUBE_DESC",
	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_SCALER",
		CoreObjectPrefab = "PREFAB_ROOT_PART",
		EndPart = "CUBE",
		FillerList = {
		    "TILING"
    	},
		BasementFillerList = {
		    "TILING"
       	},
		MinimumScale = 2,
		IsVertical = true
	}
})
Tutorial:registerAsset({
	DataType = "BUILDING_PART",
	Id = "CUBE",
	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_DEFAULT",
		CoreObjectPrefab = "PREFAB_CUBE_PART"
	}
})

Complete Mod.lua File

Below is the complete mod.lua file from all of the previous steps that you need to make your mod work properly.

You can also find this available in the optional mod download above.

local Tutorial = foundation.createMod();

---------------------
-- Asset Processor --
---------------------
Tutorial:registerAssetProcessor("models/cube.fbx", {
	DataType = "BUILDING_ASSET_PROCESSOR"
})

---------------
-- Asset IDs --
---------------
Tutorial:registerAssetId("models/cube.fbx/Prefab/Cube_Part", "PREFAB_CUBE_PART")
Tutorial:registerAssetId("models/cube.fbx/Prefab/Cube_Large_Part", "PREFAB_CUBE_LARGE_PART")
Tutorial:registerAssetId("models/cube.fbx/Prefab/Root_Part", "PREFAB_ROOT_PART")
Tutorial:registerAssetId("models/cube.fbx/Prefab/Tiling_Part", "PREFAB_TILING_PART")

-----------------------
-- Monument Building --
-----------------------
Tutorial:registerAsset({
    DataType = "BUILDING",
    Id = "CUBE_MONUMENT",
    Name = "CUBE_MONUMENT_NAME",
    Description = "CUBE_MONUMENT_DESC",
    BuildingType = "DECORATION",
    AssetCoreBuildingPart = "BUILDING_PART_MONUMENT_POLE",
    BuildingPartSetList = {
	    {
		Name = "CUBE_LIST_NAME",
	        BuildingPartList = {
                "CUBE_PART",
                "CUBE_LARGE_PART"
	    }
        }
    }
})

--------------------
-- Building Parts --
--------------------
Tutorial:registerAsset({
	DataType = "BUILDING_PART",
	Id = "CUBE_PART",
	Name = "CUBE_NAME",
	Description = "CUBE_DESC",
	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_SCALER",
		CoreObjectPrefab = "PREFAB_ROOT_PART",
		EndPart = "CUBE",
		FillerList = {
		    "TILING"
    	},
		BasementFillerList = {
		    "TILING"
       	},
		MinimumScale = 2,
		IsVertical = true
	}
})
Tutorial:registerAsset({
	DataType = "BUILDING_PART",
	Id = "CUBE",
	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_DEFAULT",
		CoreObjectPrefab = "PREFAB_CUBE_PART"
	}
})

Tutorial:registerAsset({
	DataType = "BUILDING_PART",
	Id = "CUBE_LARGE_PART",
	Name = "CUBE_LARGE_NAME",
	Description = "CUBE_LARGE_DESC",
	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_SCALER",
		CoreObjectPrefab = "PREFAB_ROOT_PART",
		EndPart = "CUBE_LARGE",
		FillerList = {
		    "TILING"
    	},
		BasementFillerList = {
		    "TILING"
       	},
		MinimumScale = 2,
		IsVertical = true
	}
})
Tutorial:registerAsset({
	DataType = "BUILDING_PART",
	Id = "CUBE_LARGE",
	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_DEFAULT",
		CoreObjectPrefab = "PREFAB_CUBE_LARGE_PART"
	}
})

-------------------
-- Scaling Parts --
-------------------
Tutorial:registerAsset({
	DataType = "BUILDING_PART",
	Id = "TILING",
	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_DEFAULT",
		CoreObjectPrefab = "PREFAB_TILING_PART"
	}
})

Congratulations! Once you load up your mod in-game, you should now see a green arrow on your model for up and down scaling.

Scaling Cube


Contact & Help

Thank you for reading through my tutorial, I hope it helped and I look forward to seeing your new mods in-game.

If you have any comments, questions, or concerns please message me:


For more in-depth modding capabilities go check out the Foundation API.

Foundation Modding API

Comments

Join the community or sign in with your gaming account to join the conversation: