holoride
Search Results for

    Show / Hide Table of Contents
    ❮ Grid Spawner & Permitted Area
    Pose Nodes ❯

    Picking Prefabs

    By default, the spawner nodes of the Spatial Experience SDK (such as GridSpawner or PoseSetSpawner) instantiate a single, static GameObject asset assigned to their Prefab field. However, to build immersive, realistic, and visually rich procedural worlds, you must break up monotony by spawning multiple object variations.

    To achieve this, the SDK utilizes the unified PrefabSelectorNode (displayed as Prefab Selector in the Graph Editor) connected directly to the spawner's prefabList port.


    The Prefab Selector Architecture

    The PrefabSelectorNode represents a powerful, unified data-provider paradigm that replaces the legacy PickPrefabRandomly and PickPrefabByMap nodes. By consolidating map-driven region targeting and weighted randomness into a single node, it enables sophisticated, hybrid asset-distribution strategies:

    ---
    config:
      flowchart:
        subGraphTitleMargin:
          bottom: 30
    ---
    flowchart TD
        %% Data Maps
        subgraph Data_Inputs ["1. Previously Authored Map Layers"]
            MapA["OSM Forest Mask"]
            MapB["Perlin Grass Noise"]
        end
    
        %% Selector Node with its elements
        subgraph Selector_Comp ["2. Unified Prefab Selector Node"]
            Sub1["Prefab 1: Oak Tree <br> (Weight: 10)"]
            Sub2["Prefab 2: Pine Tree <br> (Weight: 2)"]
            Sub3["Prefab 3: Flower <br> (Weight: 2)"]
            Node["Prefab Selector Node <br> (Evaluates highest Map value, falls back to weights)"]
    
            Sub1 & Sub2 & Sub3 -->|List element| Node
        end
    
        MapA -->|Assigns Forest Map| Sub1 & Sub2
        MapB -->|Assigns Grass Map| Sub3
    
        %% Spawner
        subgraph Spawner_Pipeline ["3. Spawner & Display Output"]
            Grid["GridSpawner"]
            Output["Procedural Scene <br> (Spawns forest trees in Forest, flowers in Grass, <br> choosing Oak/Pine randomly inside Forest!)"]
        end
    
        Node -->|Plug into prefabList port| Grid
        Grid -->|Spawns GameObjects| Output
    
        %% Styling (Vibrant, highly colored borderless theme)
        style Data_Inputs fill:#e0f2fe,stroke-width:0px
        style MapA fill:#0284c7,stroke-width:0px,color:#fff
        style MapB fill:#0ea5e9,stroke-width:0px,color:#fff
        
        style Selector_Comp fill:#f3e8ff,stroke-width:0px
        style Node fill:#7c3aed,stroke-width:0px,color:#fff
        style Sub1 fill:#9c27b0,stroke-width:0px,color:#fff
        style Sub2 fill:#9c27b0,stroke-width:0px,color:#fff
        style Sub3 fill:#9c27b0,stroke-width:0px,color:#fff
        
        style Spawner_Pipeline fill:#fce7f3,stroke-width:0px
        style Grid fill:#db2777,stroke-width:0px,color:#fff
        style Output fill:#16a34a,stroke-width:0px,color:#fff
    

    Core Pipeline Evaluation Rules:

    1. GPU-to-CPU Map Reading: For each candidate coordinate, the node queries all connected region maps. If an element's map input is left unconnected, it defaults to a value of 0.0f.
    2. Region Isolation (Highest Map Value): The node compares the map values for all elements. It identifies the highest map value at that coordinate and discards any prefabs whose connected maps returned a lower value.
    3. Seeded Weighted Randomness: For all elements that are tied with the highest map value, the node sums their Weight parameters and selects a final prefab using seeded, weighted randomness.
    4. Absolute Determinism: Although selection incorporates randomness, the random generator is seeded using the candidate’s precise spatial coordinate. This guarantees that your virtual scene is completely stable—the same spot on the real-world road will always spawn the exact same object variation, preventing visual popping.

    Three Practical Spawning Strategies

    The unified PrefabSelectorNode accommodates three distinct distribution workflows depending on how you configure its parameters:

    Strategy A: Pure Weighted Randomness (Global Mixing)

    To distribute assets across the entire scene based strictly on chance (like spawning 90% green grass clumps and 10% red mushrooms):

    • Leave the map ports of all elements completely disconnected (making them all default to a map value of 0.0f and tie for the highest value).

    • Configure their Weight parameters in the Inspector. The probability of selection is proportional to their relative weight:

      Note

      Selection Probability Formula:
      Probability = Individual Weight / Sum of All Weights

    Strategy B: Pure Map-Driven Regions (Zoning)

    To restrict specific objects to specific regions (like spawning streetlights exclusively inside cities, and spruce trees inside pine forests):

    • Connect your regional maps (like an OSM city-boundaries geometry rasterizer or Perlin noise) to the corresponding map ports.
    • Keep the Weight parameters of all elements at their default, identical values (e.g. 1.0f).
    • The prefab whose connected map returns the highest value at that coordinate will be spawned.
    Tip

    To ensure that multiple elements evaluate an identical map value, you can plug the same input map node into multiple element ports on the node in the Graph Editor.

    Strategy C: Hybrid Regional Randomness (The Production Standard)

    To achieve both region-zoning and rich variety (like spawning Pine trees and Oak trees in a forest, while spawning Cactus variants in the desert):

    • Plug your forest map into both the Pine and Oak elements' map ports (ensuring they share the same highest map value within the forest zone).
    • Plug your desert map into the Cactus elements' map ports.
    • Adjust their Weight values. Within the forest zone, the node will discard the cacti, evaluate the identical forest map values as a tie, and use the weights to procedurally select between Oaks and Pines!

    ...


    ❮ Grid Spawner & Permitted Area
    Pose Nodes ❯
    In This Article

    Back to top
    ©   holoride
    Privacy   Imprint