世界

World/世界服務用於需要與世界互動的代碼,如生成角色、查找角色或控制定向光。

通過在您的服務、角色和組件類中注入World來訪問世界。


@Service()
class Game extends GameInstance {
    private world = inject(World)
    
    onStart() {
        
    }
    
}

定向光/Directional Light

預設情況下,每個場景都有產生陰影的定向光。您可能想要訪問它以在運行時更新方向或強度。

@Service()
class Game extends GameInstance {
    private world = inject(World)
    
    onStart() {
        this.world.directionalLight.intensity = 0.2 
        this.world.directionalLight.direction.applyAxisAngle(new THREE.Vector3(0,0,1), Math.PI / 2)

    }
    
}

定向光暴露以下:

  • direction: Vector3 - 可以更新方向向量以改變光的方向。這可用於模擬太陽。

  • intensity: number - 光的亮度。

  • position: Vector3 - 定向光實例的位置。這不能被改變;相反,請改變方向。

最后更新于