Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML, Combining multiple meshes into single entity

Tags:

mesh

qt

qml

qt3d

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?

like image 575
Anders Avatar asked Oct 08 '18 10:10

Anders


1 Answers

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]
    }
}
like image 171
Anders Avatar answered Nov 19 '22 23:11

Anders