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:
@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
↳
Model
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
• | • | ||||
---|---|---|---|---|---|
Angular damping Returns
| Set angular damping Parameters
|
canAffectNavigation
• | • | ||||
---|---|---|---|---|---|
Obtain the navigation data whether the model collision affects dynamic navigation Returns
| Set whether model collision affects navigation data of dynamic navigation Parameters
|
castShadow
• | • | ||||
---|---|---|---|---|---|
Get whether to enable shadows Returns
| Set shadow on status Parameters
|
centerOfMass
• | • | ||||
---|---|---|---|---|---|
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
| 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
|
collisionEnabled
• | • | ||||
---|---|---|---|---|---|
Whether to open collision Returns
| 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
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
|
collisionGroup
• | • | ||||
---|---|---|---|---|---|
Get the corresponding collision group Returns
| Set collision Group Parameters
|
color
• | • | ||||
---|---|---|---|---|---|
Model color Returns
| Set the color of the model Parameters
|
friction
• | • | ||||
---|---|---|---|---|---|
Obtain the magnitude of frictional force Returns
| Set the magnitude of friction force Parameters
|
gravityEnabled
• | • | ||||
---|---|---|---|---|---|
Get whether enable gravity Returns
| Set whether to enable gravity Parameters
|
linerDamping
• | • | ||||
---|---|---|---|---|---|
Obtain linear damping Returns
| Set linear damping Parameters
|
lockPositionX
• | • | ||||
---|---|---|---|---|---|
Get whether constraint position X Returns
| Set whether to constraint position X Parameters
|
lockPositionY
• | • | ||||
---|---|---|---|---|---|
Get whether constraint position Y Returns
| Set whether to constrain position Y Parameters
|
lockPositionZ
• | • | ||||
---|---|---|---|---|---|
Get whether constraint position Z Returns
| Set whether to constraint position Z Parameters
|
lockRotationX
• | • | ||||
---|---|---|---|---|---|
Get whether to constraint rotation X Returns
| Set whether to constraint rotation X Parameters
|
lockRotationY
• | • | ||||
---|---|---|---|---|---|
Get whether to constrain rotation Y Returns
| Set whether to constrain rotation Y Parameters
|
lockRotationZ
• | • | ||||
---|---|---|---|---|---|
Get whether to constraint rotation Z Returns
| Set whether to constraint rotation Z Parameters
|
mass
• | • | ||||
---|---|---|---|---|---|
Obtain the quality size Returns
| Set quality size Parameters
|
massEnabled
• | • | ||||
---|---|---|---|---|---|
Obtain whether quality is being used Returns
| Set whether to enable quality Parameters
|
onTouch
• | ||
---|---|---|
Enter Model Event Returns
|
onTouchEnd
• | ||
---|---|---|
Leaving the Model Event Returns
|
opacity
• | • | ||||
---|---|---|---|---|---|
Obtain single-layer transparency of the model Returns
| Set single-layer transparency of the model Parameters
|
physicsAngularVelocity
• | • | ||||
---|---|---|---|---|---|
Obtain angular velocity (only effective when simulation is enabled) Returns
| Set the angular velocity to be overlaid (only effective when simulation is enabled) Parameters
|
physicsEnabled
• | • | ||||
---|---|---|---|---|---|
Obtain whether to simulate physics Returns
| Set up simulated physical state Parameters
|
physicsLinearVelocity
• | • | ||||
---|---|---|---|---|---|
Obtain linear velocity (only effective when simulation is enabled) Returns
| Set the linear velocity that needs to be overlaid (only effective when simulation is enabled) Parameters
|
queryEnabled
• | • | ||||
---|---|---|---|---|---|
Do you want to enable space query Returns
| 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
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
|
restitution
• | • | ||||
---|---|---|---|---|---|
Obtain elasticity size Returns
| Set the elasticity size Parameters
|
touchEnabled
• | • | ||||
---|---|---|---|---|---|
Are Touched and TouchEnded events triggered on the model. Returns
| 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
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
|
Methods
addAngularImpulse
• addAngularImpulse(impulse
, velChange?
): void
other
Add an angular impulse to the model that opens the physical simulation
Parameters
impulse Vector | Usage: set the size and direction of angular impulse |
---|---|
velChange? boolean | Usage: 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 Vector | Usage: Set force magnitude and direction default: null |
---|---|
velChange? boolean | Usage: 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 Vector | Usage: Set the magnitude and direction of impulse force |
---|---|
velChange? boolean | Usage: 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
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 Vector | Usage: Set torque magnitude and direction default: null |
---|---|
velChange? boolean | Usage: 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 number | Usage: 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
index | number |
---|
Returns
MaterialSlot | Return the material slot of the specified index |
---|
resetMaterial
• resetMaterial(index?
): void
other
Restore object material
Parameters
index? number | Material index number |
---|
setCullDistance
• setCullDistance(inCullDistance
): void
other
Objects beyond this distance from Player will be trimmed
Parameters
inCullDistance number | Usage: 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 string | Material ID default: null range: string length depends on material asset ID length |
---|
• setMaterial(MaterialGUID
, index
): void
other
Set object material
Parameters
MaterialGUID string | Material ID range: string length depends on material asset ID length |
---|---|
index number | Material 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 boolean | Do you want to enable tracing |
---|---|
color? LinearColor | Set the stroke color to correspond to the color Index in post-processing, with -1 indicating no color. default: mw.LinearColor.black |
width? number | Set 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 boolean | Do you want to enable tracing |
---|---|
color? LinearColor | Set the outline color, which corresponds to the color index in Post-Processing. -1 is no color default: mw.LinearColor.black |
width? number | Set outline width default: 2 range: [0, 4] type: floating point |
setStaticMeshAsset
• setStaticMeshAsset(InAssetGuid
): void
other
Set static mesh asset
Parameters
InAssetGuid string | Asset GUID range: string length depends on asset ID length |
---|