Skip to content
Model

Gameplay / Model

Model Class

Physical Simulation and material Settings


Adding physical effects to the game helps to enhance the immersion of the scene, because it can encourage Player to believe that they are indeed interacting with the simulation content and can get feedback in some way.

How does physical simulation work?

The property of the Model define that the static model has physical characteristics, among which the more important ones are:

  • The physical simulation can be enabled when the property of the static model instance physicsEnabled is True.

  • mass The property represents the magnitude of gravity.

  • friction The attribute represents the magnitude of frictional force.

  • restitution The property represents the spring force.

  • lockPosition The property represents the constraint. Which axis of the constraint does not change in this axis.

How can I customize settings for material?

Materials are resources that can be applied to static models of mesh objects, allowing for control over the visual appearance of the scene.

  • setMaterial Method: Replace the static model material and pass in the left material resource ID.

  • setStaticMeshAsset Method: Replace the static model by passing in the left static model resource ID.

Precautions

The current version of the physics related interface does not support multi terminal synchronization

Usage example: create a script named "ModelExample", place it in the object bar, open the script, enter the following code to save, run the game, and you can use F1 key to dynamically generate a model in the scene and simulate physics. The code is as follows:

ts
@Component
export default class ModelExample extends Script {
    //When the script is instanced, this function will be call before the first frame update
    protected async onStart(): Promise<void> {
        if(SystemUtil.isClient())
            {
                InputUtil.onKeyDown(Keys.F1,()=>{
                    // F1 key notifies the server to execute an event
                    mw.Event.dispatchToServer("Model");
                });
            }
        if(SystemUtil.isServer()){
            mw.Event.addClientListener("Model",()=>{
                let box = GameObject.spawn("197386",{
                    transform:new Transform(new Vector(500,0,100),new Rotation(0,0,0),new Vector(1,1,1)),
                    replicates:true
                }) as Model;
                // Control quality
                box.massEnabled = true;
                // Set quality
                box.mass = 200;
                // Quality of use
                box.gravityEnabled = true;
                // Set friction force
                box.friction = 0.1;
                // Set elasticity
                box.restitution = 1;
                // Enable physical simulation
                box.physicsEnabled = true;
                // Switch off shadow projection
                box.castShadow = false;
            });
        }
    }
}
@Component
export default class ModelExample extends Script {
    //When the script is instanced, this function will be call before the first frame update
    protected async onStart(): Promise<void> {
        if(SystemUtil.isClient())
            {
                InputUtil.onKeyDown(Keys.F1,()=>{
                    // F1 key notifies the server to execute an event
                    mw.Event.dispatchToServer("Model");
                });
            }
        if(SystemUtil.isServer()){
            mw.Event.addClientListener("Model",()=>{
                let box = GameObject.spawn("197386",{
                    transform:new Transform(new Vector(500,0,100),new Rotation(0,0,0),new Vector(1,1,1)),
                    replicates:true
                }) as Model;
                // Control quality
                box.massEnabled = true;
                // Set quality
                box.mass = 200;
                // Quality of use
                box.gravityEnabled = true;
                // Set friction force
                box.friction = 0.1;
                // Set elasticity
                box.restitution = 1;
                // Enable physical simulation
                box.physicsEnabled = true;
                // Switch off shadow projection
                box.castShadow = false;
            });
        }
    }
}

Hierarchy

Table of contents

Properties

click

Properties

onBeforeDestroyDelegate: MulticastDelegate<() => void> other
Event callback before object destruction
onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Monitor custom attribute synchronization events
onDestroyDelegate: MulticastDelegate<() => void> other
Event callback after object destruction
onPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>
Monitor system replicated events

Accessors

angularDamping(): number other
Angular damping
canAffectNavigation(): boolean
Obtain the navigation data whether the model collision affects dynamic navigation
castShadow(): boolean other
Get whether to enable shadows
centerOfMass(): Vector other
Get centroid offset
collisionEnabled(): boolean other
Whether to open collision
collisionGroup(): string other
Get the corresponding collision group
color(): LinearColor other
Model color
friction(): number other
Obtain the magnitude of frictional force
gravityEnabled(): boolean other
Get whether enable gravity
linerDamping(): number other
Obtain linear damping
lockPositionX(): boolean other
Get whether constraint position X
lockPositionY(): boolean other
Get whether constraint position Y
lockPositionZ(): boolean other
Get whether constraint position Z
lockRotationX(): boolean other
Get whether to constraint rotation X
lockRotationY(): boolean other
Get whether to constrain rotation Y
lockRotationZ(): boolean other
Get whether to constraint rotation Z
mass(): number other
Obtain the quality size
massEnabled(): boolean other
Obtain whether quality is being used
onTouch(): MulticastGameObjectDelegate
Enter Model Event
onTouchEnd(): MulticastGameObjectDelegate
Leaving the Model Event
opacity(): number other
Obtain single-layer transparency of the model
physicsAngularVelocity(): Vector other
Obtain angular velocity (only effective when simulation is enabled)
physicsEnabled(): boolean other
Obtain whether to simulate physics
physicsLinearVelocity(): Vector other
Obtain linear velocity (only effective when simulation is enabled)
queryEnabled(): boolean other
Do you want to enable space query
restitution(): number other
Obtain elasticity size
touchEnabled(): boolean other
Are Touched and TouchEnded events triggered on the model.
click

Accessors

actorFlagValue(): number other
Get object tags
actorLevel(): number other
Obtain Actor Level
assetId(): string other
Retrieve the UID of the resource currently being used by the object
gameObjectId(): string other
Get the unique identification of an object (a string that uniquely identifies an object).
isDestroyed(): boolean other
Has the current object been destroyed
isReady(): boolean other
Current object status
localTransform(): Transform other
Local transformation of the current object
name(): string other
Return the current object name
netStatus(): NetStatus other
Get the current object synchronization status
parent(): GameObject other
Retrieve the current parent object
tag(): string other
Get the tag of the current object
worldTransform(): Transform other
Current object world transformation

Methods

addAngularImpulse(impulse: Vector, velChange?: boolean): void other
Add an angular impulse to the model that opens the physical simulation
addForce(force: Vector, velChange?: boolean): void other
Add a force to the model that enables physical simulation
addImpulse(impulse: Vector, velChange?: boolean): void other
Add a impulse force to the model that opens the physical simulation
addTorque(torque: Vector, velChange?: boolean): void other
Add a torque to the model that enables physical simulation
createMaterialInstance(Index: number): void other
Create material Instances
getAllMaterialSlots(): MaterialSlot[] other
Get all material slot
getMaterialInstance(): MaterialInstance[] other
Return the current material instance
getMaterialSlot(index: number): MaterialSlot other
Retrieve the material slot of the specified index
resetMaterial(index?: number): void other
Restore object material
setCullDistance(inCullDistance: number): void other
Objects beyond this distance from Player will be trimmed
setMaterial(MaterialGUID: string): void other
Set object material
setOutline(enabled: boolean, color?: LinearColor, width?: number): void other
Set object outline and outline color
setPostProcessOutline(enabled: boolean, color?: LinearColor, width?: number): void other
Set object stroke and stroke color.
setStaticMeshAsset(InAssetGuid: string): void other
Set static mesh asset
click

Methods

addComponent<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>, bInReplicates?: boolean): T: extends Script<T> other
Add a script component
asyncGetChildByName(name: string): Promise<GameObject> other
Asynchronous search for sub objects based on their names
asyncReady(): Promise<GameObject> other
Return after the object is ready
clone(gameObjectInfo?: GameObjectInfo): GameObject other
Copy Objects
destroy(): void other
delete object
getBoundingBox(nonColliding?: boolean, includeFromChild?: boolean, outer?: Vector): Vector other
Get the size of the object's bounding box
getBounds(onlyCollidingComponents: boolean, originOuter: Vector, boxExtentOuter: Vector, includeFromChild?: boolean): void other
Obtain object boundaries
getChildByGameObjectId(gameObjectId: string): GameObject other
Search for sub objects based on gameObjectid
getChildByName(name: string): GameObject other
Search for sub objects by name
getChildByPath(path: string): GameObject other
Find sub objects according to path
getChildren(): GameObject[] other
Obtain sub objects
getChildrenBoundingBoxCenter(outer?: Vector): Vector other
Get the center point of all child objects' bounding box (not including the parent object, if the parent object is unavailable, return [0,0,0])
getChildrenByName(name: string): GameObject[] other
Search for all sub objects by name
getComponent<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T> other
Get the component of the specified type
getComponentPropertys<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>): Map<string, IPropertyOptions> other
Get property of script component
getComponents<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T>[] other
Get all component of the specified type
getCustomProperties(): string[] other
Get all customize property
getCustomProperty<T: extends CustomPropertyType>(propertyName: string): T: extends CustomPropertyType other
Get customize property
getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getVisibility(): boolean other
Obtain whether the object is displayed
isPrefabActor(): boolean other
Return whether the current object is a prefabricated body
moveBy(velocity: Vector, isLocal?: boolean): void other
Smoothly move an object over time according to a given velocity vector
moveTo(targetPosition: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly move from the current position to the target position within the specified time
rotateBy(rotation: Quaternion Rotation, multiplier: number, isLocal?: boolean): void other
Rotate the object smoothly over time according to the given rotation amount
rotateTo(targetRotation: Quaternion Rotation, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current rotation to the target rotation within the specified time
scaleBy(scale: Vector, isLocal?: boolean): void other
Smoothly scale objects over time using a given scaling vector per second
scaleTo(targetScale: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current scale to the target scale within the specified time
setAbsolute(absolutePosition?: boolean, absoluteRotation?: boolean, absoluteScale?: boolean): void other
Set whether the object localTransform is relative to the parent object or the world
setCustomProperty(propertyName: string, value: undefined CustomPropertyType): void other
Set custom attributes
setVisibility(status: boolean PropertyStatus, propagateToChildren?: boolean): void other
Set whether the object is displayed
stopMove(): void other
Interrupt further movement of moveTo() and moveBy()
stopRotate(): void other
Interrupt further rotation from rotateTo() or rotateBy()
stopScale(): void other
Interrupt further scale from ScaleTo() or ScaleBy()
asyncFindGameObjectById(gameObjectId: string): Promise<GameObject> other
Asynchronous search for GameObject through gameObjectid
asyncGetGameObjectByPath(path: string): Promise<GameObject> other
Asynchronously find objects through path
asyncSpawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): Promise<T: extends GameObject<T>> other
Asynchronous construction of an object
bulkPivotTo(gameObjects: GameObject[], transforms: Transform[]): void other
Batch set position
findGameObjectById(gameObjectId: string): GameObject other
Search for objects through gameObjectid
findGameObjectByName(name: string): GameObject other
Search for objects by name
findGameObjectsByName(name: string): GameObject[] other
Search for objects by name
findGameObjectsByTag(tag: string): GameObject[] other
Get objects through customize tag
getGameObjectByPath(path: string): GameObject other
Search for objects through paths
spawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): T: extends GameObject<T> other
Construct an object

Properties

Accessors


angularDamping

get angularDamping(): number other

set angularDamping(value): void other

Angular damping

Returns

numberAngular damping

Set angular damping

Parameters

value numberUsage: angular damping

canAffectNavigation

get canAffectNavigation(): boolean

set canAffectNavigation(bInStatus): void other

Obtain the navigation data whether the model collision affects dynamic navigation

Returns

booleanDoes it affect navigation data

Set whether model collision affects navigation data of dynamic navigation

Parameters

bInStatus booleanUsage: Does it affect navigation data

castShadow

get castShadow(): boolean other

set castShadow(value): void other

Get whether to enable shadows

Returns

booleanShadow enabled state

Set shadow on status

Parameters

value booleanUsage: Shadow enabled status

centerOfMass

get centerOfMass(): Vector other

set centerOfMass(value): void other

Get centroid offset

The center of mass is the center of the object's mass. When the center of mass is offset, the shape of the object in motion will be affected, but the transformation of the object itself will not be affected

Returns

VectorCenter of mass offset

Set centroid offset

The center of mass is the center of the object's mass. When the center of mass is offset, the shape of the object in motion will be affected, but the transformation of the object itself will not be affected

Parameters

value VectorUsage: centroid offset

collisionEnabled

get collisionEnabled(): boolean other

set collisionEnabled(status): void other

Whether to open collision

Returns

booleanWhether to open collision

Whether the model collision with other objects. When the value is false, other objects can pass through the model without being blocked by it.

Precautions

It is recommended to set collision for double ended objects and collision for single ended objects, which may lead to pulling

Usage example: Drag a block into the scene and create a script called Collision to mount under the block, then copy the following code into the script:

ts
@Component
export default class Collision extends Script {
    protected onStart(): void {

        if ( SystemUtil.isClient() ) {

            InputUtil.onKeyDown(Keys.One, () => {
                this.serverSetCollisionEnabled();
            })

        }
    }

    @RemoteFunction(Server)
    serverSetCollisionEnabled() {
        let model = this.gameObject as Model;
        model.collisionEnabled = !model.collisionEnabled;
    }
}
@Component
export default class Collision extends Script {
    protected onStart(): void {

        if ( SystemUtil.isClient() ) {

            InputUtil.onKeyDown(Keys.One, () => {
                this.serverSetCollisionEnabled();
            })

        }
    }

    @RemoteFunction(Server)
    serverSetCollisionEnabled() {
        let model = this.gameObject as Model;
        model.collisionEnabled = !model.collisionEnabled;
    }
}

Expected effect: Press the 1 key to enter the game, and the character can pass through the block. Press the 1 key again, and the character cannot pass through the block.

Parameters

status booleanWhether to collide and interact with other objects

collisionGroup

get collisionGroup(): string other

set collisionGroup(value): void other

Get the corresponding collision group

Returns

stringCorresponding collision group

Set collision Group

Parameters

value stringUsage: collision group

color

get color(): LinearColor other

set color(value): void other

Model color

Returns

LinearColorModel color

Set the color of the model

Parameters

value LinearColorModel color

friction

get friction(): number other

set friction(value): void other

Obtain the magnitude of frictional force

Returns

numberFriction force magnitude

Set the magnitude of friction force

Parameters

value numberUsage: Friction force magnitude

gravityEnabled

get gravityEnabled(): boolean other

set gravityEnabled(value): void other

Get whether enable gravity

Returns

booleanWhether gravity is enable

Set whether to enable gravity

Parameters

value booleanUsage: Whether gravity is enable

linerDamping

get linerDamping(): number other

set linerDamping(value): void other

Obtain linear damping

Returns

numberLinear damping size

Set linear damping

Parameters

value numberUsage: Linear damping size

lockPositionX

get lockPositionX(): boolean other

set lockPositionX(value): void other

Get whether constraint position X

Returns

booleanIs the position X constrained

Set whether to constraint position X

Parameters

value booleanUsage: Is the position X constrained

lockPositionY

get lockPositionY(): boolean other

set lockPositionY(value): void other

Get whether constraint position Y

Returns

booleanWhether constraint position Y

Set whether to constrain position Y

Parameters

value booleanUsage: Whether to constraint position Y

lockPositionZ

get lockPositionZ(): boolean other

set lockPositionZ(value): void other

Get whether constraint position Z

Returns

booleanIs the position Z constrained

Set whether to constraint position Z

Parameters

value booleanUsage: whether to constraint position Z

lockRotationX

get lockRotationX(): boolean other

set lockRotationX(value): void other

Get whether to constraint rotation X

Returns

booleanWhether to constraint rotation X

Set whether to constraint rotation X

Parameters

value booleanUsage: Is the rotation X constrained

lockRotationY

get lockRotationY(): boolean other

set lockRotationY(value): void other

Get whether to constrain rotation Y

Returns

booleanWhether to constraint rotation Y

Set whether to constrain rotation Y

Parameters

value booleanUsage: whether to constraint rotation Y

lockRotationZ

get lockRotationZ(): boolean other

set lockRotationZ(value): void other

Get whether to constraint rotation Z

Returns

booleanWhether to constraint rotation Z

Set whether to constraint rotation Z

Parameters

value booleanUsage: whether to constraint rotation Z

mass

get mass(): number other

set mass(value): void other

Obtain the quality size

Returns

numberQuality size

Set quality size

Parameters

value numberUsage: Quality and Size

massEnabled

get massEnabled(): boolean other

set massEnabled(value): void other

Obtain whether quality is being used

Returns

booleanWhether to use quality

Set whether to enable quality

Parameters

value booleanUsage: Whether to enable quality

onTouch

get onTouch(): MulticastGameObjectDelegate

Enter Model Event

Returns

MulticastGameObjectDelegate

onTouchEnd

get onTouchEnd(): MulticastGameObjectDelegate

Leaving the Model Event

Returns

MulticastGameObjectDelegate

opacity

get opacity(): number other

set opacity(value): void other

Obtain single-layer transparency of the model

Returns

numberObtain transparency

Set single-layer transparency of the model

Parameters

value numberUsage: Transparency [0,1]

physicsAngularVelocity

get physicsAngularVelocity(): Vector other

set physicsAngularVelocity(value): void other

Obtain angular velocity (only effective when simulation is enabled)

Returns

VectorPhysical angular velocity

Set the angular velocity to be overlaid (only effective when simulation is enabled)

Parameters

value VectorUsage: Physical angular velocity magnitude

physicsEnabled

get physicsEnabled(): boolean other

set physicsEnabled(value): void other

Obtain whether to simulate physics

Returns

booleanPhysical Simulation enable Status

Set up simulated physical state

Parameters

value booleanUsage: Physical simulation state

physicsLinearVelocity

get physicsLinearVelocity(): Vector other

set physicsLinearVelocity(value): void other

Obtain linear velocity (only effective when simulation is enabled)

Returns

VectorPhysical linear velocity

Set the linear velocity that needs to be overlaid (only effective when simulation is enabled)

Parameters

value VectorUsage: Physical line velocity size

queryEnabled

get queryEnabled(): boolean other

set queryEnabled(status): void other

Do you want to enable space query

Returns

booleanDo you want to enable space query

Check whether the spatial query model is included in the detection scope. When the value is false, it will not be detected by spatial queries.

Usage example: Drag a box into the scene, create a script named Query, mount it under the box, and copy the following code into the script:

ts
@Component
export default class Query extends Script {
    effect : Effect

    protected onStart(): void {
        if ( SystemUtil.isClient() ) {
            InputUtil.onKeyDown(Keys.One, () => {
                this.serverSetQueryEnabled();
            })
        }
    }

    @RemoteFunction(Server)
    async serverSetQueryEnabled() {
        let model = this.gameObject as Model;

        let hitGameObjects = PhysicsService.sphereOverlap(this.gameObject.worldTransform.position, 30, {}, {});
        if (hitGameObjects.length > 0) {
            const success = await AssetUtil.asyncDownloadAsset("4391");
            if (success) {
                const transform = model.worldTransform.clone();
                transform.position.add(new Vector(0, 0, 150));

                GameObject.asyncSpawn("4391", {
                    replicates: true,
                    transform: transform
                }).then((effect : Effect) => {
                    this.effect = effect
                    // Play effect
                    effect.play();
                });
            }
        }
        else {
            this.effect.destroy();
            this.effect = undefined;
        }

        model.queryEnabled = !model.queryEnabled;
    }
}
@Component
export default class Query extends Script {
    effect : Effect

    protected onStart(): void {
        if ( SystemUtil.isClient() ) {
            InputUtil.onKeyDown(Keys.One, () => {
                this.serverSetQueryEnabled();
            })
        }
    }

    @RemoteFunction(Server)
    async serverSetQueryEnabled() {
        let model = this.gameObject as Model;

        let hitGameObjects = PhysicsService.sphereOverlap(this.gameObject.worldTransform.position, 30, {}, {});
        if (hitGameObjects.length > 0) {
            const success = await AssetUtil.asyncDownloadAsset("4391");
            if (success) {
                const transform = model.worldTransform.clone();
                transform.position.add(new Vector(0, 0, 150));

                GameObject.asyncSpawn("4391", {
                    replicates: true,
                    transform: transform
                }).then((effect : Effect) => {
                    this.effect = effect
                    // Play effect
                    effect.play();
                });
            }
        }
        else {
            this.effect.destroy();
            this.effect = undefined;
        }

        model.queryEnabled = !model.queryEnabled;
    }
}

Press 1 to generate effect, which is detect by the spatial query, and then press 1 to delete the effect, which is not detect by the spatial query.

Parameters

status booleanQuery whether the model is included in the detect range in space.

restitution

get restitution(): number other

set restitution(value): void other

Obtain elasticity size

Returns

numberElasticity size

Set the elasticity size

Parameters

value numberUsage: Elasticity size

touchEnabled

get touchEnabled(): boolean other

set touchEnabled(status): void other

Are Touched and TouchEnded events triggered on the model.

Returns

booleanAre Touched and TouchEnded events triggered on the model.

Are Touched and TouchEnded events triggered on the model. When the value is false, the object will not throw a touch event during interaction.

Usage example: Drag a box into the scene, create a script named Touch, mount it under the box, and copy the following code into the script:

ts
@Component
export default class Touch extends Script {
    effect : Effect

    protected onStart(): void {
        if ( SystemUtil.isClient() ) {
            InputUtil.onKeyDown(Keys.One, () => {
                this.serverSetTouchEnabled();
            })
        }

        if ( SystemUtil.isServer() ) {
            let model = this.gameObject as Model;
            model.collisionEnabled = false;
            model.onTouch.add(async () => {
                const success = await AssetUtil.asyncDownloadAsset("4391");
                if (success) {
                    const transform = model.worldTransform.clone();
                    transform.position.add(new Vector(0, 0, 150));

                    GameObject.asyncSpawn("4391", {
                        replicates: true,
                        transform: transform
                    }).then((effect : Effect) => {
                        this.effect = effect
                        // Play effect
                        effect.play();
                    });
                }
            });
            model.onTouchEnd.add(() => {
                if (this.effect != undefined) {
                    this.effect.destroy();
                    this.effect = undefined;
                }
            });
        }
    }

    @RemoteFunction(Server)
    async serverSetTouchEnabled() {
        let model = this.gameObject as Model;
        model.touchEnabled = !model.touchEnabled;
    }
}
@Component
export default class Touch extends Script {
    effect : Effect

    protected onStart(): void {
        if ( SystemUtil.isClient() ) {
            InputUtil.onKeyDown(Keys.One, () => {
                this.serverSetTouchEnabled();
            })
        }

        if ( SystemUtil.isServer() ) {
            let model = this.gameObject as Model;
            model.collisionEnabled = false;
            model.onTouch.add(async () => {
                const success = await AssetUtil.asyncDownloadAsset("4391");
                if (success) {
                    const transform = model.worldTransform.clone();
                    transform.position.add(new Vector(0, 0, 150));

                    GameObject.asyncSpawn("4391", {
                        replicates: true,
                        transform: transform
                    }).then((effect : Effect) => {
                        this.effect = effect
                        // Play effect
                        effect.play();
                    });
                }
            });
            model.onTouchEnd.add(() => {
                if (this.effect != undefined) {
                    this.effect.destroy();
                    this.effect = undefined;
                }
            });
        }
    }

    @RemoteFunction(Server)
    async serverSetTouchEnabled() {
        let model = this.gameObject as Model;
        model.touchEnabled = !model.touchEnabled;
    }
}

The character walks into the box, generate effect, walks out of the box, and effect disappear. Press 1, and the character will enter and exit the block without any changes.

Parameters

status booleanAre Touched and TouchEnded events triggered on the model.

Methods

addAngularImpulse

addAngularImpulse(impulse, velChange?): void other

Add an angular impulse to the model that opens the physical simulation

Parameters

impulse VectorUsage: set the size and direction of angular impulse
velChange? booleanUsage: Whether to ignore the impact of the model's own quality default: false Usage example: The following example shows the method of adding angular impulse ts if (model.physicsEnabled) `{ // Ensure to enable physical simulation model.addAngularImpulse(new Vector(200,0,0), true); }`

addForce

addForce(force, velChange?): void other

Add a force to the model that enables physical simulation

Parameters

force VectorUsage: Set force magnitude and direction
default: null
velChange? booleanUsage: Whether to ignore the impact of the model's own quality
default: false Usage example: The following example demonstrates the method of adding force ts if (model.physicsEnabled) `{ // Ensure to enable physical simulation model.addForce(new Vector(200,0,0), true); }`

addImpulse

addImpulse(impulse, velChange?): void other

Add a impulse force to the model that opens the physical simulation

Parameters

impulse VectorUsage: Set the magnitude and direction of impulse force
velChange? booleanUsage: Whether to ignore the impact of the model's own quality default: false

Usage example: The following example demonstrates the method of adding impulse force

ts
if (model.physicsEnabled) {
     // Ensure to enable physical simulation
     model.addImpulse(new Vector(200,0,0), true);
}
if (model.physicsEnabled) {
     // Ensure to enable physical simulation
     model.addImpulse(new Vector(200,0,0), true);
}

addTorque

addTorque(torque, velChange?): void other

Add a torque to the model that enables physical simulation

Parameters

torque VectorUsage: Set torque magnitude and direction
default: null
velChange? booleanUsage: Whether to ignore the impact of the model's own quality
default: false Usage example: The following example demonstrates the method of adding torque ts if (model.physicsEnabled) `{ // Ensure to enable physical simulation model.addTorque(new Vector(200,0,0), true); }`

createMaterialInstance

createMaterialInstance(Index): void other

Create material Instances

Parameters

Index numberUsage: What material is the
range: not exceeding the number of materials type: integer

getAllMaterialSlots

getAllMaterialSlots(): MaterialSlot[] other

Get all material slot

Returns

MaterialSlot[]Return material slot array

getMaterialInstance

getMaterialInstance(): MaterialInstance[] other

Return the current material instance

Returns

MaterialInstance[]Material instance array

If the material asset has not been loaded, the returned material instance cannot get the material property immediately. After loading the material asset, you can get the correct material property through the material instance


getMaterialSlot

getMaterialSlot(index): MaterialSlot other

Retrieve the material slot of the specified index

Parameters

indexnumber

Returns

MaterialSlotReturn the material slot of the specified index

resetMaterial

resetMaterial(index?): void other

Restore object material

Parameters

index? numberMaterial index number

setCullDistance

setCullDistance(inCullDistance): void other

Objects beyond this distance from Player will be trimmed

Parameters

inCullDistance numberUsage: cull distance range: recommended (2000, 4000) type: floating point

The final cropping distance will depend on the image quality level; When this property is modified ≤ 0, the cull distance will automatically adjust according to the object size (automatically enable the CullDistanceVolume function)

Precautions

The final cull distance will be related to the graphics quality level


setMaterial

setMaterial(MaterialGUID): void other

Set object material

Parameters

MaterialGUID stringMaterial ID default: null range: string length depends on material asset ID length

setMaterial(MaterialGUID, index): void other

Set object material

Parameters

MaterialGUID stringMaterial ID range: string length depends on material asset ID length
index numberMaterial index range: determined by the length of the material ID type: integer

setOutline

setOutline(enabled, color?, width?): void other

Set object outline and outline color

Parameters

enabled booleanDo you want to enable tracing
color? LinearColorSet the stroke color to correspond to the color Index in post-processing, with -1 indicating no color. default: mw.LinearColor.black
width? numberSet outline width default: 2 range: [0, 100] type: floating point

There needs to be post-processing objects in the scene.


setPostProcessOutline

setPostProcessOutline(enabled, color?, width?): void other

Set object stroke and stroke color.

Parameters

enabled booleanDo you want to enable tracing
color? LinearColorSet the outline color, which corresponds to the color index in Post-Processing. -1 is no color default: mw.LinearColor.black
width? numberSet outline width default: 2 range: [0, 4] type: floating point

setStaticMeshAsset

setStaticMeshAsset(InAssetGuid): void other

Set static mesh asset

Parameters

InAssetGuid stringAsset GUID range: string length depends on asset ID length