Add 3D objects to the scenery
The mod can create custom, textured 3D objects and add them to the scenery using game.setObject
method.
* A dimensional property included in this method is defined as an object with three fields represent 3 Axes in Coordinates
Field | Represent for |
---|---|
x | X Axis |
y | Y Axis |
z | Z Axis |
Object instance options
Option | Description |
---|---|
id | a unique identifier for this object instance (mandatory, allows changing the object afterwards) |
type | the object type definition |
position | coordinates for placing the object, dimensional property |
scale | allows scaling the object, dimensional property |
rotation | allows rotating the object, dimensional property |
Object type options
Option | Description | Default value |
---|---|---|
id | a unique identifier for this object type, mandatory | "undefined" or "null" depending on implementation |
obj | a URL to the OBJ file | None |
diffuse | a URL to a diffuse texture file (optional) | None |
emissive | a URL to an emissive texture file (optional) | None |
specular | a URL to a specularity texture file (optional) | None |
bump | a URL to a bump texture map (optional) | None |
emissiveColor | emissive color of the object, e.g. 0xFF0000 (for red) | White if emissive is valid, Black otherwise |
diffuseColor | diffuse color of the object, e.g. 0x00FF00 (for green) | White if diffuse is valid, Black otherwise |
specularColor | specular color of the object, e.g. 0x0000FF (for blue) | White if specular is valid, Black otherwise |
transparent | whether the object’s texture has transparency or not | true |
bumpScale | scale for bump mapping | 0.1 |
shininess | the shininess of the specular map | 30 |
physics | Object’s physics | None |
All URLs included as property value must satisfy one of these conditions:
- It’s a Data URL (
data:
protocol) - The protocol must be
https
(explicitly, not omitted) and the domain only matches one of these:
starblast.io
(Official Starblast)starblast.data.neuronality.com
(Neuronality’s Starblast Data)github.com
(GitHub)raw.githubusercontent.com
(Raw GitHub Content)gitlab.com
(GitLab)
If any URL-required fields mentioned above are present but don’t satisfy these conditions, the whole object is rejected to be set on the players’ clients.
Please note that GitHub and GitLab URLs can be easily converted into raw data URLs (such as changing /blob/
into /raw/
or appending ?raw=true
at the end for GitHub URLs exclusively). Any URL using GitHub or GitLab domain should point to the raw file content and not the webpage version of the file itself.
Object physics options
Note: We recommend not to use this property as it usually doesn’t work as expected
Option | Description |
---|---|
mass | Object mass, same as the specs.ship.mass property in Ship Editor Tutorial Note: If the mass is too small (<100), ships can go through the object |
shape | Object’s shape, used for creating hitbox You can omit this property to set default shape generated from the object itself or provide an array for your custom shape |
For example:
var cube = {
id: "cube",
obj: "https://raw.githubusercontent.com/pmgl/starblast-modding/master/objects/cube/cube.obj",
diffuse: "https://raw.githubusercontent.com/pmgl/starblast-modding/master/objects/cube/diffuse.jpg"
} ;
game.setObject({
id: "cube",
type: cube,
position: {x:0,y:0,z:0},
rotation: {x:0,y:0,z:0},
scale: {x:1,y:1,z:1}
}) ;
Accessing
Game property game.objects
stores all active 3D Objects maintained by the mod
You shouldn’t modify this property to keep the mod running smoothly
Changing or moving an object
Use game.setObject
again with the same object instance ID.
Note: Object type’s properties can not be changed once set. You may need to define a new object type instance with different ID and set the object you wish to update with the new object type ID.
Removing an object
game.removeObject(id)
removes the object with given id. You can omit the id parameter, which will remove all custom objects in the scene.
Example
Working example, adding cube objects to the scenery: https://github.com/pmgl/starblast-modding/blob/master/examples/adding_cube.js