import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { Laya3D } from "Laya3D" ; import { Handler } from "laya/utils/Handler" ; import { Laya } from "Laya" ; import { Stage } from "laya/display/Stage" ; import { Stat } from "laya/utils/Stat" ; import { Camera } from "laya/d3/core/Camera" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { DirectionLight } from "laya/d3/core/light/DirectionLight" ; import { MeshSprite3D } from "laya/d3/core/MeshSprite3D" ; import { Transform3D } from "laya/d3/core/Transform3D" ; import { Rigidbody3D } from "laya/d3/physics/Rigidbody3D" ; import { FixedConstraint } from "laya/d3/physics/constraints/FixedConstraint" ; import { BoxColliderShape } from "laya/d3/physics/shape/BoxColliderShape" ; import { PrimitiveMesh } from "laya/d3/resource/models/PrimitiveMesh" ; import { Script3D } from "laya/d3/component/Script3D" ; import { Config3D } from "Config3D" ; export class PhysicsWorld_ConstraintFixedJoint { private scene : Scene3D ; private camera : Camera ; constructor ( ) { Laya3D . init ( 0 , 0 , null , Handler . create ( this , ( ) => { Laya . stage . scaleMode = Stage . SCALE_FULL ; Laya . stage . screenMode = Stage . SCREEN_NONE ; Stat . show ( ) ; Config3D . useCannonPhysics = false ; this . scene = ( < Scene3D > Laya . stage . addChild ( new Scene3D ( ) ) ) ; this . camera = ( < Camera > this . scene . addChild ( new Camera ( 0 , 0.1 , 100 ) ) ) ; this . camera . transform . translate ( new Vector3 ( 0 , 3 , 10 ) ) ; this . camera . clearColor = null ; var directionLight = ( < DirectionLight > this . scene . addChild ( new DirectionLight ( ) ) ) ; directionLight . color = new Vector3 ( 1 , 1 , 1 ) ; directionLight . transform . worldMatrix . setForward ( new Vector3 ( - 1.0 , - 1.0 , 1.0 ) ) ; this . addbox ( ) ; } ) ) ; } addbox ( ) { var box = ( < MeshSprite3D > this . scene . addChild ( new MeshSprite3D ( PrimitiveMesh . createBox ( 1 , 1 , 1 ) ) ) ) ; var transform = box . transform ; var pos = transform . position ; pos . setValue ( 0 , 5 , 0 ) ; transform . position = pos ; var rigidBody = box . addComponent ( Rigidbody3D ) ; var boxShape = new BoxColliderShape ( 1 , 1 , 1 ) ; rigidBody . colliderShape = boxShape ; rigidBody . mass = 10 ; rigidBody . isKinematic = true ; var box2 = ( < MeshSprite3D > this . scene . addChild ( new MeshSprite3D ( PrimitiveMesh . createBox ( 1 , 1 , 1 ) ) ) ) ; var transform2 = box2 . transform ; var pos2 = transform2 . position ; pos2 . setValue ( 0 , 3 , 0 ) ; transform2 . position = pos2 ; var rigidBody2 = box2 . addComponent ( Rigidbody3D ) ; var boxShape2 = new BoxColliderShape ( 1 , 1 , 1 ) ; rigidBody2 . colliderShape = boxShape2 ; rigidBody2 . mass = 10 ; var fixedConstraint = box . addComponent ( FixedConstraint ) ; fixedConstraint . anchor = new Vector3 ( 0 , 0 , 0 ) ; fixedConstraint . connectAnchor = new Vector3 ( 0 , 2 , 0 ) ; box . addComponent ( FixedEventTest ) ; fixedConstraint . setConnectRigidBody ( rigidBody , rigidBody2 ) ; } } export class FixedEventTest extends Script3D { private fixedConstraint : FixedConstraint ; onStart ( ) { this . fixedConstraint = this . owner . getComponent ( FixedConstraint ) ; this . fixedConstraint . breakForce = 1000 ; } onUpdate ( ) { if ( this . fixedConstraint ) { var mass = this . fixedConstraint . connectedBody . mass ; this . fixedConstraint . connectedBody . mass = mass + 1 ; } } onJointBreak ( ) { console . log ( "duanle" ) ; } }