qt 3d basics - kdab · everything is a qnode qt 3d ecs explained p.24 qt3dcore::qnode is the base...
TRANSCRIPT
Qt3DBasicsKévinOttens,SoftwareCraftsmanatKDAB
Qt3DBasics
Qt3DBasics p.2
FeatureSet
EntityComponentSystem?Kezaco?
HelloDonut
Qt3DECSExplained
InputHandling
DrawingBasics
BeyondtheTipoftheIceberg
TheFutureofQt3D
Qt3DBasics
FeatureSet p.3
FeatureSet
EntityComponentSystem?Kezaco?
HelloDonut
Qt3DECSExplained
InputHandling
DrawingBasics
BeyondtheTipoftheIceberg
TheFutureofQt3D
WhatisQt3D?
FeatureSet p.4
Itisnotabout3D!
Multi-purpose,notjustagameengine
Softreal-timesimulationengine
Designedtobescalable
Extensibleandflexible
SimulationEngine
FeatureSet p.5
Thecoreisnotinherentlyabout3D
ItcandealwithseveraldomainsatonceAI,logic,audio,etc.Andofcourseitcontainsa3Drenderertoo!
AllyouneedforacomplexsystemsimulationMechanicalsystemsPhysics...andalsogames
Scalability
FeatureSet p.6
Frontend/backendsplitFrontendislightweightandonthemainthreadBackendexecutedinasecondarythreadWheretheactualsimulationruns
Non-blockingfrontend/backendcommunication
Backendmaximizesthroughputviaathreadpool
ExtensibilityandFlexibility
FeatureSet p.7
Domainscanbeaddedviaindependentaspects...onlyifthere'snotsomethingfittingyourneedsalready
ProvidebothC++andQMLAPIs
IntegrateswellwiththerestofQtPullingyoursimulationdatafromadatabaseanyone?
EntityComponentSystemisusedtocombinebehaviorinyourownobjectsNodeepinheritancehierarchy
Qt3DBasics
EntityComponentSystem?Kezaco? p.8
FeatureSet
EntityComponentSystem?Kezaco?
HelloDonut
Qt3DECSExplained
InputHandling
DrawingBasics
BeyondtheTipoftheIceberg
TheFutureofQt3D
ECS:Definitions
EntityComponentSystem?Kezaco? p.9
ECSisanarchitecturalpatternPopularingameenginesFavorscompositionoverinheritance
Anentityisageneralpurposeobject
Anentitygetsitsbehaviorbycombiningdata
Datacomesfromtypedcomponents
CompositionvsInheritance
EntityComponentSystem?Kezaco? p.10
Let'sanalyseafamiliarexample:SpaceInvaders
CompositionvsInheritancecont'd
EntityComponentSystem?Kezaco? p.11
Typicalinheritancehierarchy
CompositionvsInheritancecont'd
EntityComponentSystem?Kezaco? p.12
Allfineuntilcustomerrequiresnewfeature:
CompositionvsInheritancecont'd
EntityComponentSystem?Kezaco? p.13
Typicalsolution:Addfeaturetobaseclass
CompositionvsInheritancecont'd
EntityComponentSystem?Kezaco? p.14
Doesn'tscale:
CompositionvsInheritancecont'd
EntityComponentSystem?Kezaco? p.15
Whataboutmultipleinheritance?
CompositionvsInheritancecont'd
EntityComponentSystem?Kezaco? p.16
Whataboutmix-inmultipleinheritance?
CompositionvsInheritancecont'd
EntityComponentSystem?Kezaco? p.17
Doesitscale?
CompositionvsInheritancecont'd
EntityComponentSystem?Kezaco? p.18
Isinheritanceflexibleenough?
CompositionvsInheritancecont'd
EntityComponentSystem?Kezaco? p.19
Inheritance:Relationshipsbakedinatdesigntime.Complexinheritancehierarchies:deep,wide,multipleinheritanceFeaturestendtomigratetobaseclass
EntityComponentSystemAllowschangesatruntimeAvoidsinheritancelimitationsHasadditionalcosts:MoreQObjectsDifferenttomostOOPdeveloper'sexperience
Wedon'thavetobakeinassumptionstoQt3Dthatwecan'tlaterchangewhenaddingfeatures.
Qt3DBasics
HelloDonut p.20
FeatureSet
EntityComponentSystem?Kezaco?
HelloDonut
Qt3DECSExplained
InputHandling
DrawingBasics
BeyondtheTipoftheIceberg
TheFutureofQt3D
HelloDonut(QML)
HelloDonut p.21
GoodpracticehavingrootEntitytorepresentthescene
OneEntityper"object"inthescene
Objectsgivenbehaviorbyattachingcomponentsubclasses
ForanEntitytobedrawnitneeds:AmeshgeometrydescribingitsshapeAmaterialdescribingitssurfaceappearance
Demoqt3d/ex-hellodonut-qml
C++APIvsQMLAPI
HelloDonut p.22
QMLAPIisamirroroftheC++API
C++classnamesliketherestofQt
QMLelementnamesjustdon'thavetheQinfrontQt3DCore::QNodevsNodeQt3DCore::QEntityvsEntity...
Qt3DBasics
Qt3DECSExplained p.23
FeatureSet
EntityComponentSystem?Kezaco?
HelloDonut
Qt3DECSExplained
InputHandling
DrawingBasics
BeyondtheTipoftheIceberg
TheFutureofQt3D
EverythingisaQNode
Qt3DECSExplained p.24
Qt3DCore::QNodeisthebasetypeforeverythingItinheritsfromQObjectandallitsfeaturesInternallyimplementsthefrontend/backendcommunication
Qt3DCore::QEntity
ItinheritsfromQt3DCore::QNodeItjustaggregatesQt3DCore::QComponents
Qt3DCore::QComponent
ItinheritsfromQt3DCore::QNodeActualdataisprovidedbyitssubclasses
Qt3DCore::QTransformQt3DRender::QMeshQt3DRender::QMaterial
...
EverythingisaQNodecont'd
Qt3DECSExplained p.25
YouStillNeedaSystem
Qt3DECSExplained p.26
ThesimulationisexecutedbyQt3DCore::QAspectEngine
Qt3DCore::QAbstractAspectsubclassinstancesareregisteredontheengineBehaviorcomesfromtheaspectsprocessingcomponentdataAspectscontrolthedomainsmanipulatedbyyoursimulation
Qt3DprovidesQt3DRender::QRenderAspectQt3DInput::QInputAspectQt3DLogic::QLogicAspect
NotethataspectshavenoAPIoftheirownItisallprovidedbyQt3DCore::QComponentsubclasses
Qt3DBasics
InputHandling p.27
FeatureSet
EntityComponentSystem?Kezaco?
HelloDonut
Qt3DECSExplained
InputHandling
DrawingBasics
BeyondtheTipoftheIceberg
TheFutureofQt3D
PhysicalDevices
InputHandling p.28
Tohandleinputwefirstneedtogenerateinputevents
SubclassesofQt3DInput::QAbstractPhysicalDevicerepresentinputdevices
Qt3DInput::QKeyboardDeviceQt3DInput::QMouseDevice
Otherscanbeaddedlater
Onit'sownadevicedoesn'tdomuchInputhandlersexposesignalsemittedinresponsetoevents
Picking
InputHandling p.29
HighlevelpickingprovidedbyQt3DRender::QObjectPickercomponentImplicitlyassociatedwithmousedeviceUsesray-castbasedpicking
Qt3DRender::QObjectPickeremitssignalsforyoutohandle:pressed(),released(),clicked()
moved()-onlywhendragEnabledistrueentered(),exited()-onlywhenhoverEnabledistrue
ThecontainsMousepropertyprovidesamoredeclarativealternativetoentered(),exited()
PhysicalDevicesvsLogicalDevices
InputHandling p.30
Physicaldevicesprovideonlydiscreteevents
Hardtousethemtocontrolavalueovertime
Logicaldeviceprovidesawayto:HaveananalogviewonaphysicaldeviceAggregateseveralphysicaldevicesinaunifieddevice
LogicalInputAction
InputHandling p.31
Qt3DInput::QActionprovidesabinaryvalue
Itisactivatedbysomeinput,canbe:AsinglebuttoninputwithQt3DInput::QActionInputAsimultaneouscombinationofbuttoninputswithQt3DInput::QInputChord
AsequenceofbuttoninputswithQt3DInput::QInputSequence
Whentheactionstatechangestheactivepropertyistoggled
Demoqt3d/ex-logical-input-qml
LogicalInputAxis
InputHandling p.32
Qt3DInput::QAxisprovidesananalogvaluebetween-1and1
Itvariesovertimewhensomeinputisgenerated,canbe:WhenaphysicalaxisvarieswithQt3DInput::QAnalogAxisInputWhileabuttonispressedwithQt3DInput::QButtonAxisInput
Whentheaxisstatechangesthevaluepropertychanges
Demoqt3d/ex-logical-axes-qml
PuttingitAllTogether:MovingBoxes
InputHandling p.33
Focusmanagedusingtab
Focusedboxappearsbigger
Thearrowsmovetheboxontheplane
Pageup/downrotatetheboxonitsYaxis
Boxeslightupwhenonmousehover
Clickingonaboxgivesitthefocus
Boxescanbemovedaroundwiththemouse
Demoqt3d/sol-moving-boxes-qml-step3
Qt3DBasics
DrawingBasics p.34
FeatureSet
EntityComponentSystem?Kezaco?
HelloDonut
Qt3DECSExplained
InputHandling
DrawingBasics
BeyondtheTipoftheIceberg
TheFutureofQt3D
TheSceneGraph
DrawingBasics p.35
ThescenegraphprovidesthespatialrepresentationofthesimulationQt3DCore::QEntity:whattakespartinthesimulationQt3DCore::QTransform:whereitis,whatscaleitis,whatorientationithas
Hierarchicaltransformsarecontrolledbytheparent/childrelationshipSimilartoQWidget,QQuickItem,etc.
Ifthesceneisrendered,weneedapointofviewonitThisisprovidedbyQt3DRender::QCamera
Qt3DCore::QTransform
DrawingBasics p.36
InheritsfromQt3DCore::QComponent
Representsanaffinetransformation
Threewaysofusingit:Throughproperties:scale3D,rotation,translationThroughhelperfunctions:rotateAround()Throughthematrixproperty
Transformationsareapplied:toobjectsinScale/Rotation/TranslationordertocoordinatesystemsinTranslation/Rotation/Scaleorder
Transformationsaremultipliedalongtheparent/childrelationship
Transformscont'd
DrawingBasics p.37
1 importQt3D.Core2.023 Entity{4 components:[5 Transform{6 scale3D:Qt.vector3d(1,2,1.5)7 translation:Qt.vector3d(0,0,-1)8 }9 ]1011 Entity{12 components:[13 Transform{translation:Qt.vector3d(0,1,0)}14 ]15 }16 }
Geometries
DrawingBasics p.38
Qt3DRender::QRenderAspectdrawsQt3DCore::QEntityswithashape
Qt3DRender::QGeometryRenderer'sgeometrypropertyspecifiestheshape
Qt3DprovidesconveniencesubclassesofQt3DRender::QGeometryRenderer:
Qt3DExtras::QSphereMeshQt3DExtras::QCuboidMeshQt3DExtras::QPlaneMeshQt3DExtras::QTorusMeshQt3DExtras::QConeMeshQt3DExtras::QCylinderMesh
QtDemoexamples/qt3d/basicshapes-cpp
Materials
DrawingBasics p.39
IfaQt3DCore::QEntityonlyhasashapeitwillappearblack
TheQt3DRender::QMaterialcomponentprovidesasurfaceappearance
Qt3DprovidesconveniencesubclassesofQt3DRender::QMaterial:
Qt3DExtras::QPhongMaterialQt3DExtras::QPhongAlphaMaterialQt3DExtras::QDiffuseMapMaterialQt3DExtras::QDiffuseSpecularMapMaterialQt3DExtras::QGoochMaterial
...
Demoqt3d/sol-textured-scene
Lights
DrawingBasics p.40
Evenwithshapesandmaterialswewouldseenothing
Weneedsomelights...luckilyQt3Dsetsadefaultoneforusifnoneisprovided
Ingeneralwewantsomecontrolofthescenelighting
Qt3Dprovidesthefollowinglighttypes:DirectionalLightPointLightSpotLight
Labqt3d/ex-lights-qml
Qt3DBasics
BeyondtheTipoftheIceberg p.41
FeatureSet
EntityComponentSystem?Kezaco?
HelloDonut
Qt3DECSExplained
InputHandling
DrawingBasics
BeyondtheTipoftheIceberg
TheFutureofQt3D
MakingyourOwnGeometries
BeyondtheTipoftheIceberg p.42
UsingQt3DRender::QBufferwecancreateourownvertices
GeometryRenderercontrolshowbuffersarecombinedandparsed
Usefultomakeyouowngeometriesprogrammatically:FromafunctionFromdatasetsFromuserinteraction
Demoqt3d/ex-surface-function
TextureCompositionandFiltering
BeyondtheTipoftheIceberg p.43
Possibletosampleseveraltexturesinasinglematerial
Alsoeasytoreusestocklightingmodel
Thenyoucanblendasyouseefitintheshader
Demoqt3d/sol-earth
ProceduralTextures
BeyondtheTipoftheIceberg p.44
LotsofexamplesavailableontheInternethttps://www.shadertoy.com/
UsuallywrittenforWebGLorOpenGLES2MayrequiresomeadaptationManyarefarfromsimple!
ButtheyareeasytoplugintheMaterialsystemandtoparameterize
Demoqt3d/ex-plasma
IntegratingwithQtQuickusingScene3D
BeyondtheTipoftheIceberg p.45
ProvidedbytheQtQuick.Scene3Dmodule
TakesanEntityaschildwhichwillbeyourwholescene
Loadedaspectsarecontrolledwiththeaspectsproperty
HovereventsareonlyacceptedifthehoverEnabledpropertyistrue
Demoqt3d/ex-controls-overlay
Andmore...
BeyondtheTipoftheIceberg p.46
Layermanagement
Ownmaterialsandlightingmodels
Texturemipmaps
CubeMaps
PortabilityofyourcodeaccrossseveralOpenGLversions
Completecontrolovertherenderingalgorithm
Loadingcompleteobjectsorscenesfromfiles(3ds,collada,qml...)
Post-processingeffects(singleormulti-pass)
Instancedrendering
etc.
Demoqt3d/ex-multiple-effects
Demoqt3d/sol-asteroids
Qt3DBasics
TheFutureofQt3D p.47
FeatureSet
EntityComponentSystem?Kezaco?
HelloDonut
Qt3DECSExplained
InputHandling
DrawingBasics
BeyondtheTipoftheIceberg
TheFutureofQt3D
WhatdoesthefutureholdforQt3D?
TheFutureofQt3D p.48
Qt3DCoreEfficiencyimprovemmentsBackendthreadpoolandjobhandlingimprovements-jobsspawningjobs
Qt3DRenderUseQtQuickorQPaintertorenderintoatextureEmbedQtQuickintoQt3DincludinginputhandlingLevelofDetail(LOD)supportformeshesBillboards-camerafacingentitiesTextsupport-2Dand3DAdditionalmaterialssuchasPhysicsBasedRendering(PBR)materialsParticlesystems
Qt3DInputAxisinputsthatapplycumulativeaxisvaluesasposition,velocityoraccelerationAdditionalinputdevicesupport3Dmousecontrollers,gamecontrollers
Enumeratedinputssuchas8-waybuttons,hatswitchesordials
WhatdoesthefutureholdforQt3D?
TheFutureofQt3D p.49
Newaspects:CollisionDetectionAspectAllowstodetectwhenentitiescollideorenter/exitvolumesinspace
AnimationAspectKeyframeanimationSkeletalanimationMorphtargetanimationRemovesanimationworkloadfrommainthread
PhysicsAspectRigidbodyandsoftbodyphysicssimulation
AIAspect,3DPositionalAudioAspect...
Tooling:Designtimetooling-sceneeditorBuildtimetooling-assetconditionersformeshes,texturesetc.