이 페이지에서

Qt Quick 3D - 인스턴스 렌더링 예제

Qt Quick 3D 에서 인스턴스 렌더링을 수행하는 방법을 보여줍니다.

소행성대와 두 대의 우주선이 등장하는 우주 장면으로, 인스턴스 렌더링을 보여줍니다.

이 예제는 기본 QML API를 사용하여 인스턴스 렌더링을 수행하는 방법을 보여줍니다.

우주선과 소행성 모델은 Blender 3D 모델링 도구를 사용하여 제작되었으며, balsam을 통해 가져왔습니다.

무작위 인스턴싱

RandomInstancing 를 사용하여 소행성대를 정의하는 랜덤 테이블을 만듭니다:

RandomInstancing {
    id: randomInstancing
    instanceCount: 1500

    position: InstanceRange {
        from: Qt.vector3d(-300, -200, -500)
        to: Qt.vector3d(300, 200, 200)
    }
    scale: InstanceRange {
        from: Qt.vector3d(1, 1, 1)
        to: Qt.vector3d(10, 10, 10)
        proportional: true
    }
    rotation: InstanceRange {
        from: Qt.vector3d(0, 0, 0)
        to: Qt.vector3d(360, 360, 360)
    }
    color: InstanceRange {
        from: "grey"
        to: "white"
        proportional: true
    }

    randomSeed: 2021
}

위치와 회전은 자유롭게 변동할 수 있습니다. 크기는 모든 방향에서 균일하게 설정되며 색상은 그레이스케일로 처리됩니다. 이는 proportional 속성을 설정하여 구현됩니다.

우주선들은 InstanceList 를 사용하여 수동으로 배치됩니다:

InstanceListEntry {
    id: redShip
    eulerRotation: Qt.vector3d(0, 180, 0)
    color: "red"
    PropertyAnimation on position {
        from: Qt.vector3d(50, 10, 100)
        to: Qt.vector3d(-70, 10, 100)
        duration: 8000
    }
}

InstanceListEntry {
    id: greenShip
    position: Qt.vector3d(0, 0, -60)
    eulerRotation: Qt.vector3d(-10, 0, 30)
    color: "green"
}

InstanceListEntry {
    id: blueShip
    position: Qt.vector3d(-100, -100, 0)
    color: "blue"
}

InstanceList {
    id: manualInstancing
    instances: [ redShip, greenShip, blueShip ]
}

InstanceListEntry 의 속성은 바인딩이 가능합니다. 여기서는 빨간 우주선이 카메라의 경로를 가로지르도록 애니메이션을 적용합니다.

마지막으로 인스턴싱 테이블을 오브젝트에 적용합니다:

Asteroid {
    instancing: randomInstancing
    NumberAnimation on eulerRotation.x {
        from: 0
        to: 360
        duration: 11000
        loops: Animation.Infinite
    }
}

SimpleSpaceship {
    instancing: manualInstancing
}

소행성 모델의 회전을 애니메이션화하면, 인스턴스 테이블의 내용을 변경하지 않아도 모든 인스턴스가 회전합니다. 소행성 인스턴스는 무작위 회전을 가지므로, 모든 소행성이 서로 다른 축을 중심으로 회전하게 됩니다.

예제 프로젝트 @ code.qt.io

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.