3D Models
3D model methods allow you to import, manage, and render OBJ models inside DirectGPU scenes.
Models must first be loaded before they can be drawn. Each loaded model is assigned a modelId which can be used for rendering and management.
Methods
Section titled “Methods”clearAll3DModels
Section titled “clearAll3DModels”Removes all loaded 3D models from DirectGPU.
Use this when resetting a scene or freeing model resources.
Example
Section titled “Example”gpu.clearAll3DModels()draw3DModel
Section titled “draw3DModel”Draws a loaded model using a single flat color.
Rotation values are specified in degrees:
rotX- rotation around the X axisrotY- rotation around the Y axisrotZ- rotation around the Z axis
Requires: DisplayID, modelId : number, position, rotation, scale, and RGB color values.
draw3DModel still supports rotX, rotY, rotZ.
Example
Section titled “Example”gpu.draw3DModel( displayId, modelId, 0, 0, 0, 0, 45, 0, 1.0, 255, 255, 255)You can also pass a quaternion rotation using qx, qy, qz, qw after the color args:
gpu.draw3DModel( displayId, modelId, 0, 0, 0, 0, 0, 0, 1, 255, 255, 255, qx, qy, qz, qw)draw3DModel can also accept a quaternion object/table as the final arg:
gpu.draw3DModel( displayId, modelId, 0, 0, 0, 0, 0, 0, 1, 255, 255, 255, pose.orientation)draw3DModelTextured
Section titled “draw3DModelTextured”Draws a loaded model using a previously loaded texture.
The texture must be loaded first using loadTexture.
Requires: DisplayID, modelId : number, textureId : number, position, rotation, scale, and RGB color values.
draw3DModelTextured supports the same optional quaternion args as draw3DModel.
Example
Section titled “Example”gpu.draw3DModelTextured( displayId, modelId, textureId, 0, 0, 0, 0, 45, 0, 1.0, 255, 255, 255)With a quaternion passed as qx, qy, qz, qw:
gpu.draw3DModelTextured( displayId, modelId, textureId, 0, 0, 0, 0, 0, 0, 1, 255, 255, 255, qx, qy, qz, qw)With a quaternion object/table:
gpu.draw3DModelTextured( displayId, modelId, textureId, 0, 0, 0, 0, 0, 0, 1, 255, 255, 255, pose.orientation)get3DModelInfo
Section titled “get3DModelInfo”Returns information about a loaded model.
Requires: modelId : number
Returns: Model information table.
Example
Section titled “Example”local info = gpu.get3DModelInfo(modelId)
print(info)load3DModel
Section titled “load3DModel”Loads OBJ model data from a normal string.
Returns: modelId : number
The returned ID can be used with draw3DModel and draw3DModelTextured.
Example
Section titled “Example”local modelId = gpu.load3DModel(objData)load3DModelFromBytes
Section titled “load3DModelFromBytes”Loads OBJ model data from Base64 encoded data.
Useful when transferring model files through APIs or networks.
Requires: base64ObjData : string
Returns: modelId : number
Example
Section titled “Example”local modelId = gpu.load3DModelFromBytes(base64ObjData)loadTexture
Section titled “loadTexture”Loads an image as a texture that can be applied to 3D models.
The image is provided as Base64 encoded image data.
Requires: base64ImageData : string
Returns: textureId : number
The returned ID can be used with draw3DModelTextured.
Example
Section titled “Example”local textureId = gpu.loadTexture(base64ImageData)unload3DModel
Section titled “unload3DModel”Removes a loaded model from DirectGPU.
Use this when a model is no longer needed to free resources.
Requires: modelId : number
Example
Section titled “Example”gpu.unload3DModel(modelId)unloadTexture
Section titled “unloadTexture”Removes a loaded texture from DirectGPU.
Use this when a texture is no longer needed to free resources.
Requires: textureId : number
Example
Section titled “Example”gpu.unloadTexture(textureId)3D model quaternion args
Section titled “3D model quaternion args”draw3DModel still supports rotX, rotY, rotZ.
Quaternion rotation can be passed using qx, qy, qz, qw after the color args.
gpu.draw3DModel(displayId, modelId, x, y, z, 0, 0, 0, scale, r, g, b, qx, qy, qz, qw)draw3DModel can also accept a quaternion object/table as the final arg.
gpu.draw3DModel(displayId, modelId, x, y, z, 0, 0, 0, scale, r, g, b, pose.orientation)draw3DModelTextured supports the same optional quaternion args.
gpu.draw3DModelTextured(displayId, modelId, textureId, x, y, z, 0, 0, 0, scale, r, g, b, qx, qy, qz, qw)gpu.draw3DModelTextured(displayId, modelId, textureId, x, y, z, 0, 0, 0, scale, r, g, b, pose.orientation)