QML, Combining multiple meshes into single entity
Asked Answered
U

1

8

I am trying to create a customizable Qt3D component by merging three ConeMeshes into a single entity. The user must be able to interact with the custom entity, so I have added an ObjectPicker to the file. Normally, I would use a predefined scaled .obj file, but my manager wants the objects to be drawn directly by Qt.

The two meshes I want to combine are defined in a seperate qml file, so I can call it within my Scene3D.

Entity {
    ObjectPicker {
    id: combinedPicker
    }
    ConeMesh {
    id: conemesh1
    ...
    }
    ConeMesh {
    id: conemesh2
    ...
    }
    Transform {
    id: conetransform1
    }
    Transform {
    id: conetransform2
    }
    Entity {
    components: [conemesh1, conetransform1, conemesh2, conetransform2, combinedPicker]
    }
}

My approach for putting the meshes together is to enclose them as components in a separate Entity scope, as shown in the last line. But this approach only renders the last entry in the components array. Above, that would be conemesh2.

Previously I tried to create multiple Entity instances, and pass each one the id of the ObjectPicker,

Entity {
components: [conemesh1, conetransform1, combinedPicker]
}
Entity {
components: [conemesh2, conetransform2, combinedPicker]
}

But as per the documentation of ObjectPicker, the object picker is not meant to be shared by multiple components.

So my question is this: What is the correct approach when merging multiple meshes into one single mesh in Qml?

Ula answered 8/10, 2018 at 10:36 Comment(0)
U
5

I solved the problem by "factoring" out the ObjectPicker element, effectivly making it a sibling of the mesh entities.

 Entity {
    components: 
        [conePicker]
    Entity {
      id: pipeTopEntity
      components: [coneMeshTop, coneTransformTop, floorMaterialTop]
    }
    Entity {
      id: pipeBodyEntity
      components: [coneMeshBody, coneTransformBody, floorMaterialBody]
    }
    Entity {
      id: pipeBotEntity
      components: [ coneMeshBot, coneTransformBot,  floorMaterialBot]
    }
}
Ula answered 8/10, 2018 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.