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

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

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

우주선과 소행성 모델은 블렌더 3D 모델링 툴을 사용하여 생성하고 발삼으로 임포트했습니다.

랜덤 인스턴싱

소행성 필드를 정의하는 랜덤 테이블을 만들기 위해 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
    position: Qt.vector3d(50, 10, 100)
    eulerRotation: Qt.vector3d(0, 180, 0)
    color: "red"
    NumberAnimation on position.x {
        from: 50
        to: -70
        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

© 2025 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.