Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 3D实体的多个实例_Qt_Qml_Qt3d - Fatal编程技术网

Qt 3D实体的多个实例

Qt 3D实体的多个实例,qt,qml,qt3d,Qt,Qml,Qt3d,我正在尝试在Qt3D中创建多个球体。以下是我开发的代码 Entity{ Repeater { model: 10 SphereMesh { id: sphereMesh1 radius: 1 } Transform { id: sphereTransform1 property real userAngle: 0.0

我正在尝试在Qt3D中创建多个球体。以下是我开发的代码

Entity{
    Repeater {

        model: 10
        SphereMesh {
            id: sphereMesh1
            radius: 1
        }

        Transform {
            id: sphereTransform1
            property real userAngle: 0.0
            matrix: {
                var m = Qt.matrix4x4();
                m.rotate(userAngle, Qt.vector3d(0, 1, 0));
                m.translate(Qt.vector3d(index, 0, 0));
                return m;
            }
        }

        PhongMaterial {
            id: material1
        }

        Entity {
            id: sphereEntity1
            components: [ sphereMesh1, material1, sphereTransform1 ]
        }
     }
  }
我已经在上面写了一个转发器来创建10个球体,但是屏幕是空白的。有什么提示吗?

使用

实体{
id:根
摄像机{
id:mainCamera
projectionType:CameraLens.PerspectiveProjection
视野:45
专题:16/9
近平面:0.1
飞机:1000.0
位置:Qt.vector3d(0.0,0.0,-40.0)
上向量:Qt.vector3d(0.0,1.0,0.0)
viewCenter:Qt.vector3d(0.0,0.0,0.0)
}
轨道摄影机控制器{
id:mainCameraController
摄像机:主摄像机
}
组成部分:[
渲染设置{
视区{
normalizedRect:Qt.rect(0.0,0.0,1.0,1.0)
渲染曲面选择器{
摄影师{
id:摄像师
摄像机:主摄像机
平截头{
清除缓冲区{
缓冲区:ClearBuffers.AllBuffers
clearColor:#333333“
NoDraw{}
}
分层过滤器{
filterMode:LayerFilter.DiscardAnyMatchingLayers
图层:[顶层]
}
分层过滤器{
filterMode:LayerFilter.AcceptionMatchingLayers
图层:[顶层]
清除缓冲区{
缓冲区:ClearBuffers.DepthBuffer
}
}
}
}
}
}
},
输入设置{}
]
层{
id:顶层
递归:对
}
列表模型{
id:entityModel
列表元素{x:0;y:0;z:0}
}
节点安装器{
id:实例
模型:entityModel
代表:实体{
球面网{
id:sphereMesh1
半径:1
}
转化{
id:sphereTransform1
平移:Qt.vector3d(x,y,z)
}
语音材料{
编号:material1
环境:“红色”
}
实体{
id:sphereEntity1
组件:[sphereMesh1,material1,sphereTransform1]
}
}
Component.onCompleted:
{

对于(var i=0;i如果您只放置一个球体,会发生什么情况?请提供,以便我们可以运行和测试它。qml文件是我在绘制单个球体时使用的基本代码。文件的解释和输出是,我不确定qml repeater如何工作,但可能与此有关,您不允许在e之间共享转换实体。您是否在没有中继器的情况下尝试了您的代码?它是否工作?我猜您使用的
中继器
是不正确的。您必须提供一个。如果您隐式地这样做(如示例中所示),您必须只提供一个项。我猜您的代码中只有一个逻辑错误。实际上它必须是
中继器{model:10;Entity{…}}
Entity {
id: root


Camera {
    id: mainCamera
    projectionType: CameraLens.PerspectiveProjection
    fieldOfView: 45
    aspectRatio: 16/9
    nearPlane : 0.1
    farPlane : 1000.0
    position: Qt.vector3d( 0.0, 0.0, -40.0 )
    upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
    viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
}

OrbitCameraController {
    id: mainCameraController
    camera: mainCamera
}

components: [
    RenderSettings {

        Viewport {
            normalizedRect: Qt.rect(0.0, 0.0, 1.0, 1.0)
            RenderSurfaceSelector {
                CameraSelector {
                    id: cameraSelector
                    camera: mainCamera
                    FrustumCulling {
                        ClearBuffers {
                            buffers: ClearBuffers.AllBuffers
                            clearColor: "#333333"
                            NoDraw {}
                        }
                        LayerFilter {
                            filterMode: LayerFilter.DiscardAnyMatchingLayers
                            layers: [topLayer]
                        }
                        LayerFilter {
                            filterMode: LayerFilter.AcceptAnyMatchingLayers
                            layers: [topLayer]
                            ClearBuffers {
                                buffers: ClearBuffers.DepthBuffer
                            }
                        }
                    }
                }
            }
        }
    },
    InputSettings {}
]

Layer {
    id: topLayer
    recursive: true
}

ListModel {
    id: entityModel

    ListElement { x: 0; y: 0; z: 0 }
}



NodeInstantiator {
    id: instance

    model: entityModel

    delegate:Entity{

        SphereMesh {
            id: sphereMesh1
            radius:1
        }

        Transform {
            id: sphereTransform1

            translation: Qt.vector3d(x,y,z)

        }

        PhongMaterial {
            id: material1
            ambient: "red"
        }

        Entity {
            id: sphereEntity1
            components: [ sphereMesh1, material1, sphereTransform1 ]
        }
    }

    Component.onCompleted:
    {
        for(var i=0;i<10;i++)
        {
            entityModel.append({"x" : i*3, "y" : 0.0, "z" : Math.random()} )

        }

    }
}