ModelBuilderclass

Provides the ability to generate `Sandbox.Model`s at runtime. A new instance is available from `Sandbox.Model.Builder`.

objectModelBuilder
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public sealed class Sandbox.ModelBuilder

Constructors1

Showing 1 constructors

Methods39

Showing 39 methods

public Sandbox.AnimationBuilder AddAnimation(string name, float frameRate)PUBLIC

Adds an animation to this model and returns a builder to construct the animation. Duplicate names are given a numeric suffix. Animations without frames are omitted from the finished model.

ParameterTypeDescription
namestringThe name of the animation.
frameRatefloatThe frames per second of the animation.
Returns:AnimationBuilderA builder for the new animation.

public Sandbox.ModelBuilder AddAttachment(string name, Vector3 position, Rotation rotation, string parentName = null)PUBLIC

Adds a named attachment point to the skeleton.

ParameterTypeDescription
namestringThe attachment name.
positionVector3The position relative to the parent bone.
rotationRotationThe rotation relative to the parent bone.
parentName = nullstringThe parent bone name, or null for a model-space attachment.
Returns:ModelBuilder

public Sandbox.BallJointBuilder AddBallJoint(int body1, int body2, System.Nullable`1<Transform> frame1 = null, System.Nullable`1<Transform> frame2 = null, bool collision = False)PUBLIC

ParameterTypeDescription
body1int
body2int
frame1 = nullNullable<Transform>
frame2 = nullNullable<Transform>
collision = Falsebool
Returns:BallJointBuilder

public Sandbox.PhysicsBodyBuilder AddBody(float mass = 0, Sandbox.Surface surface = null, string boneName = null)PUBLIC

Adds a physics body to the model. Joints refer to bodies by the order they are added.

ParameterTypeDescription
mass = 0floatThe mass in kilograms. A value of 0 calculates mass from the body's shapes and surface density.
surface = nullSurfaceThe surface properties applied to the body.
boneName = nullstringOptional name of the bone this body is attached to. Leave empty for non-skeletal bodies.
Returns:PhysicsBodyBuilderA builder for the new body.

public void AddBones(Sandbox.ModelBuilder.Bone[] bones)PUBLIC

Adds multiple bones to the skeleton.

ParameterTypeDescription
bonesBone[]The bones to add.
Returns:void

public Sandbox.ModelBuilder AddCollisionCapsule(Vector3 center0, Vector3 center1, float radius)PUBLIC

Adds a capsule collision shape.

ParameterTypeDescription
center0Vector3The center of the first rounded end.
center1Vector3The center of the second rounded end.
radiusfloatThe capsule radius.
Returns:ModelBuilder

public Sandbox.ModelBuilder AddCollisionSphere(float radius, Vector3 center = null)PUBLIC

Adds a sphere collision shape.

ParameterTypeDescription
radiusfloatThe sphere radius.
center = nullVector3The sphere center.
Returns:ModelBuilder

public Sandbox.FixedJointBuilder AddFixedJoint(int body1, int body2, System.Nullable`1<Transform> frame1 = null, System.Nullable`1<Transform> frame2 = null, bool collision = False)PUBLIC

ParameterTypeDescription
body1int
body2int
frame1 = nullNullable<Transform>
frame2 = nullNullable<Transform>
collision = Falsebool

public Sandbox.HingeJointBuilder AddHingeJoint(int body1, int body2, System.Nullable`1<Transform> frame1 = null, System.Nullable`1<Transform> frame2 = null, bool collision = False)PUBLIC

ParameterTypeDescription
body1int
body2int
frame1 = nullNullable<Transform>
frame2 = nullNullable<Transform>
collision = Falsebool

public Sandbox.HitboxSetBuilder AddHitboxSet(string name = default)PUBLIC

Adds a named hitbox set.

ParameterTypeDescription
name = defaultstringThe hitbox set name.
Returns:HitboxSetBuilderA builder for the new hitbox set.

public Sandbox.MaterialGroupBuilder AddMaterialGroup(string name)PUBLIC

Adds a named material variant and returns a builder for its materials.

ParameterTypeDescription
namestringThe material group name.
Returns:MaterialGroupBuilderA builder for the new material group.

public Sandbox.ModelBuilder AddSurface(Sandbox.Surface surface)PUBLIC

Adds a surface that can be referenced by collision mesh material indices.

ParameterTypeDescription
surfaceSurfaceThe surface to add. Null uses the default surface.
Returns:ModelBuilder

public Sandbox.Model Create()PUBLIC

Builds the model.

Returns:ModelThe finished model.

public Sandbox.ModelBuilder WithEyePosition(Vector3 position)PUBLIC

Sets the model-space position used as the model's eye position.

ParameterTypeDescription
positionVector3The eye position.
Returns:ModelBuilder

public Sandbox.ModelBuilder WithHullBounds(BBox bounds)PUBLIC

Sets the bounds used for physics and gameplay queries. If not set, the bounds are calculated from the model's physics data.

ParameterTypeDescription
boundsBBoxThe model-space hull bounds.
Returns:ModelBuilder

public Sandbox.ModelBuilder WithLodDistance(int lod, float distance)PUBLIC

Sets the distance at which an LOD level becomes active. By default, each level switches at `lod * 50`.

ParameterTypeDescription
lodintThe LOD level, from 0 to 7.
distancefloatThe switch distance.
Returns:ModelBuilder

Exceptions

ExceptionCondition
ArgumentOutOfRangeExceptionThe LOD level is outside the range 0 to 7.

public Sandbox.ModelBuilder WithMass(float mass)PUBLIC

Sets the mass, in kilograms, used by collision shapes added directly to this builder. The default is 1000.

ParameterTypeDescription
massfloatThe total mass of the collision body.
Returns:ModelBuilder

public Sandbox.ModelBuilder WithMaxEyeDeflection(float degrees)PUBLIC

Sets the maximum angle, in degrees, that the model's eyes can turn away from forward.

ParameterTypeDescription
degreesfloatThe maximum eye deflection angle.
Returns:ModelBuilder

public Sandbox.ModelBuilder WithName(string name)PUBLIC

Sets the name used to identify the model.

ParameterTypeDescription
namestringThe model name.
Returns:ModelBuilder

public Sandbox.ModelBuilder WithSurface(string name)PUBLIC

Sets the surface used by collision shapes added directly to this builder.

ParameterTypeDescription
namestringThe surface name.
Returns:ModelBuilder

public Sandbox.ModelBuilder WithViewBounds(BBox bounds)PUBLIC

Sets the bounds used for rendering and visibility. If not set, the bounds are calculated from the model's meshes.

ParameterTypeDescription
boundsBBoxThe model-space visibility bounds.
Returns:ModelBuilder

On this page

Constructorspublic ModelBuilder()Methodspublic Sandbox.AnimationBuilder AddAnimation(System.String name, System.Single frameRate)public Sandbox.ModelBuilder AddAttachment(System.String name, Vector3 position, Rotation rotation, System.String parentName = null)public Sandbox.BallJointBuilder AddBallJoint(System.Int32 body1, System.Int32 body2, System.Nullable`1<Transform> frame1 = null, System.Nullable`1<Transform> frame2 = null, System.Boolean collision = False)public Sandbox.PhysicsBodyBuilder AddBody(System.Single mass = 0, Sandbox.Surface surface = null, System.String boneName = null)public System.Void AddBone(Sandbox.ModelBuilder.Bone bone)public Sandbox.ModelBuilder AddBone(System.String name, Vector3 position, Rotation rotation, System.String parentName = null)public System.Void AddBones(Sandbox.ModelBuilder.Bone[] bones)public Sandbox.ModelBuilder AddCollisionBox(Vector3 extents, System.Nullable`1<Vector3> center = null, System.Nullable`1<Rotation> rotation = null)public Sandbox.ModelBuilder AddCollisionCapsule(Vector3 center0, Vector3 center1, System.Single radius)public Sandbox.ModelBuilder AddCollisionHull(System.Collections.Generic.List`1<Vector3> vertices, System.Nullable`1<Vector3> center = null, System.Nullable`1<Rotation> rotation = null)public Sandbox.ModelBuilder AddCollisionHull(System.Span`1<Vector3> vertices, System.Nullable`1<Vector3> center = null, System.Nullable`1<Rotation> rotation = null)public Sandbox.ModelBuilder AddCollisionMesh(System.Collections.Generic.List`1<Vector3> vertices, System.Collections.Generic.List`1<System.Int32> indices, System.Collections.Generic.List`1<System.Byte> materials)public Sandbox.ModelBuilder AddCollisionMesh(System.Collections.Generic.List`1<Vector3> vertices, System.Collections.Generic.List`1<System.Int32> indices)public Sandbox.ModelBuilder AddCollisionMesh(System.Span`1<Vector3> vertices, System.Span`1<System.Int32> indices, System.Span`1<System.Byte> materials)public Sandbox.ModelBuilder AddCollisionMesh(System.Span`1<Vector3> vertices, System.Span`1<System.Int32> indices)public Sandbox.ModelBuilder AddCollisionSphere(System.Single radius, Vector3 center = null)public Sandbox.FixedJointBuilder AddFixedJoint(System.Int32 body1, System.Int32 body2, System.Nullable`1<Transform> frame1 = null, System.Nullable`1<Transform> frame2 = null, System.Boolean collision = False)public Sandbox.HingeJointBuilder AddHingeJoint(System.Int32 body1, System.Int32 body2, System.Nullable`1<Transform> frame1 = null, System.Nullable`1<Transform> frame2 = null, System.Boolean collision = False)public Sandbox.HitboxSetBuilder AddHitboxSet(System.String name = default)public Sandbox.MaterialGroupBuilder AddMaterialGroup(System.String name)public Sandbox.ModelBuilder AddMesh(Sandbox.Mesh mesh, System.Int32 lod, System.String groupName, System.Int32 choiceIndex)public Sandbox.ModelBuilder AddMesh(Sandbox.Mesh mesh, System.Int32 lod)public Sandbox.ModelBuilder AddMesh(Sandbox.Mesh mesh, System.String groupName, System.Int32 choiceIndex)public Sandbox.ModelBuilder AddMesh(Sandbox.Mesh mesh)public Sandbox.ModelBuilder AddMeshes(Sandbox.Mesh[] meshes, System.Int32 lod)public Sandbox.ModelBuilder AddMeshes(Sandbox.Mesh[] meshes)public Sandbox.SliderJointBuilder AddSliderJoint(System.Int32 body1, System.Int32 body2, System.Nullable`1<Transform> frame1 = null, System.Nullable`1<Transform> frame2 = null, System.Boolean collision = False)public Sandbox.ModelBuilder AddSurface(Sandbox.Surface surface)public Sandbox.ModelBuilder AddTraceMesh(System.Collections.Generic.List`1<Vector3> vertices, System.Collections.Generic.List`1<System.Int32> indices)public Sandbox.ModelBuilder AddTraceMesh(System.Span`1<Vector3> vertices, System.Span`1<System.Int32> indices)public Sandbox.Model Create()public Sandbox.ModelBuilder WithEyePosition(Vector3 position)public Sandbox.ModelBuilder WithHullBounds(BBox bounds)public Sandbox.ModelBuilder WithLodDistance(System.Int32 lod, System.Single distance)public Sandbox.ModelBuilder WithMass(System.Single mass)public Sandbox.ModelBuilder WithMaxEyeDeflection(System.Single degrees)public Sandbox.ModelBuilder WithName(System.String name)public Sandbox.ModelBuilder WithSurface(System.String name)public Sandbox.ModelBuilder WithViewBounds(BBox bounds)Metadata