User Tools

Site Tools


guides:random_doors_and_windows

How to Randomly set Doors and Windows on a Building

Here is an example of a building (myBuilding) with randomly set door (3 models) and windows (2 models):

-- Apply building asset processor
    myMod:registerAssetProcessor("models/myFbxName.fbx", {
        DataType = "BUILDING_ASSET_PROCESSOR"
    })
 
-- Register prefab nodes
    myMod:registerAssetId("models/myFbxName.fbx/Prefab/myBuildingPart", "MY_BUILDING_PREFAB")
 
-- Register the assemblage part
    myMod:register({
        DataType = "BUILDING_PART",
        Id = "MY_BUILDING_PART",
        Mover = { DataType = "BUILDING_PART_MOVER_INSTANCE" },
        ConstructorData = {
            DataType = "BUILDING_CONSTRUCTOR_ASSEMBLAGE",
            CoreRandomBuildingPartList = { "MY_BUILDING_PREFAB" },
            MandatoryBuildingPartList = {
                -- 1 door per building,
                -- set on one major point randomly choosen amongst the major points
                -- defined in models/myFbxName.fbx under the mesh myBuildingPart
                { BuildingPart = "MY_DOOR_PART" },
                -- up to 4 windows,
                -- randomly set on the remaining major points.
                { BuildingPart = "MY_WINDOW_PART", Probability = 0.5 },
                { BuildingPart = "MY_WINDOW_PART", Probability = 0.5 },
                { BuildingPart = "MY_WINDOW_PART", Probability = 0.5 },
                { BuildingPart = "MY_WINDOW_PART", Probability = 0.5 }
            }
        }
    })
 
    myMod:registerPrefabComponent("models/myFbxName.fbx/Prefab/myBuildingPart", {
        DataType = "COMP_BUILDING_PART",
        HasBuildingZone = true,
        BuildingZone = {4, 8} -- BuildingZone of MY_BUILDING_PART 
    })
 
-- several models of door
    myMod:register({
        DataType = "BUILDING_PART",
        Id = "MY_DOOR_PART",
        ConstructorData = {
            DataType = "BUILDING_CONSTRUCTOR_RANDOM_PART",
            RandomPartList = {
                "MY_DOOR_1_PART",
                "MY_DOOR_2_PART",
                "MY_DOOR_3_PART"
            }
        }
    })
 
    -- Register the door parts
    function registerDoorPart(_doorNumber)
        myMod:registerAssetId("models/myFbxName.fbx/Prefab/myDoor" .. _doorNumber .. "_Part", "MY_DOOR_" .. _doorNumber .. "_PREFAB")
 
        myMod:register({
            DataType = "BUILDING_PART",
            Id = "MY_DOOR_" .. _doorNumber .. "_PART",
            Mover = { DataType = "BUILDING_PART_MOVER_INSTANCE" },
            ConstructorData = {
                DataType = "BUILDING_CONSTRUCTOR_DEFAULT",
                CoreObjectPrefab = "MY_DOOR_" .. _doorNumber .. "_PREFAB"
	    }
        })
 
        myMod:registerPrefabComponent("models/myFbxName.fbx/Prefab/myDoor" .. _doorNumber .. "_Part", {
            DataType = "COMP_BUILDING_PART",
            BuildingPartType = "MAJOR",
            HasBuildingZone = true,
            BuildingZone = {0.1, 1} -- generic BuildingZone for your door
        })
 
        myMod:registerPrefabComponent("models/myFbxName.fbx/Prefab/myDoor" .. _doorNumber .. "_Part", {
            DataType = "COMP_GROUNDED"
        })
    end
 
    registerDoorPart(1)
    registerDoorPart(2)
    registerDoorPart(3)
 
-- several models of window
    myMod:register({
        DataType = "BUILDING_PART",
        Id = "MY_WINDOW_PART",
        ConstructorData = {
            DataType = "BUILDING_CONSTRUCTOR_RANDOM_PART",
            RandomPartList = {
                "MY_WINDOW_1_PART",
                "MY_WINDOW_2_PART"
            }
        }
    })
 
    -- Register the window parts
    function registerWindowPart(_windowNumber)
        myMod:registerAssetId("models/myFbxName.fbx/Prefab/myWindow" .. _windowNumber .. "_Part", "MY_WINDOW_" .. _windowNumber .. "_PREFAB")
 
        myMod:register({
            DataType = "BUILDING_PART",
            Id = "MY_WINDOW_" .. _windowNumber .. "_PART",
            Mover = { DataType = "BUILDING_PART_MOVER_INSTANCE" },
            ConstructorData = {
                DataType = "BUILDING_CONSTRUCTOR_DEFAULT",
                CoreObjectPrefab = "MY_WINDOW_" .. _windowNumber .. "_PREFAB"
            }
        })
 
        myMod:registerPrefabComponent("models/myFbxName.fbx/Prefab/myWindow" .. _windowNumber .. "_Part", {
            DataType = "COMP_BUILDING_PART",
            BuildingPartType = "MAJOR",
            HasBuildingZone = true,
            BuildingZone = {0.1, 1} -- generic BuildingZone for your window
        })
    end
 
    registerWindowPart(1)
    registerWindowPart(2)
guides/random_doors_and_windows.txt · Last modified: 2021/02/23 11:56 by minotorious