Documentation and TutorialMain Code PartsAdd 3D objects to the scenery

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

FieldRepresent for
xX Axis
yY Axis
zZ Axis

Object instance options

OptionDescription
ida unique identifier for this object instance (mandatory, allows changing the object afterwards)
typethe object type definition
positioncoordinates for placing the object, dimensional property
scaleallows scaling the object, dimensional property
rotationallows rotating the object, dimensional property

Object type options

OptionDescriptionDefault value
ida unique identifier for this object type, mandatory"undefined" or "null" depending on implementation
obja URL to the OBJ fileNone
diffusea URL to a diffuse texture file (optional)None
emissivea URL to an emissive texture file (optional)None
speculara URL to a specularity texture file (optional)None
bumpa URL to a bump texture map (optional)None
emissiveColoremissive color of the object, e.g. 0xFF0000 (for red)White if emissive is valid, Black otherwise
diffuseColordiffuse color of the object, e.g. 0x00FF00 (for green)White if diffuse is valid, Black otherwise
specularColorspecular color of the object, e.g. 0x0000FF (for blue)White if specular is valid, Black otherwise
transparentwhether the object’s texture has transparency or nottrue
bumpScalescale for bump mapping0.1
shininessthe shininess of the specular map30
physicsObject’s physicsNone

All URLs included as property value must satisfy one of these conditions:

  1. It’s a Data URL (data: protocol)
  2. 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

OptionDescription
massObject 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
shapeObject’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