From 1be5981d6a560580410b1b684f687dd45cc18607 Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Mon, 27 Jul 2015 14:26:50 +0800 Subject: [PATCH] add Physics3DComponent support new --- .../js-bindings/script/3d/jsb_cocos2d_3d.js | 15 +++++++++++++++ tests/js-tests/src/LightTest/LightTest.js | 4 ++-- .../MaterialSystemTest/MaterialSystemTest.js | 4 ++-- tests/js-tests/src/NavMeshTest/NavMeshTest.js | 6 +++--- .../src/Physics3DTest/Physics3DTest.js | 18 +++++++++--------- .../js-tests/src/Sprite3DTest/Sprite3DTest.js | 2 +- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/cocos/scripting/js-bindings/script/3d/jsb_cocos2d_3d.js b/cocos/scripting/js-bindings/script/3d/jsb_cocos2d_3d.js index 3b02ec56d0..a975a559ca 100644 --- a/cocos/scripting/js-bindings/script/3d/jsb_cocos2d_3d.js +++ b/cocos/scripting/js-bindings/script/3d/jsb_cocos2d_3d.js @@ -324,4 +324,19 @@ jsb.Skybox.prototype._ctor = function(positive_x, negative_x, positive_y, negati { throw new Error("error arguments"); } +} + +jsb.DirectionLight.prototype._ctor = function(direction, color){ + this.setDirection(direction); + this.setColor(color); +} + +jsb.AmbientLight.prototype._ctor = function(color){ + this.setColor(color); +} + +jsb.Physics3DComponent.prototype._ctor = function(physicsObj, translateInPhysics = cc.math.vec3(), rotInPhsyics = new cc.math.Quaternion()){ + this.init(); + this.setPhysics3DObject(physicsObj); + this.setTransformInPhysics(translateInPhysics, rotInPhsyics); } \ No newline at end of file diff --git a/tests/js-tests/src/LightTest/LightTest.js b/tests/js-tests/src/LightTest/LightTest.js index 02d92528c8..0d596ed03d 100644 --- a/tests/js-tests/src/LightTest/LightTest.js +++ b/tests/js-tests/src/LightTest/LightTest.js @@ -209,12 +209,12 @@ var LightTest = LightTestDemo.extend({ }, addLights:function(){ - this._ambientLight = jsb.AmbientLight.create(cc.color(200, 200, 200)); + this._ambientLight = new jsb.AmbientLight(cc.color(200, 200, 200)); this._ambientLight.setEnabled(true); this.addChild(this._ambientLight); this._ambientLight.setCameraMask(2); - this._directionalLight = jsb.DirectionLight.create(cc.math.vec3(-1, -1, 0), cc.color(200, 200, 200)); + this._directionalLight = new jsb.DirectionLight(cc.math.vec3(-1, -1, 0), cc.color(200, 200, 200)); this._directionalLight.setEnabled(false); this.addChild(this._directionalLight); this._directionalLight.setCameraMask(2); diff --git a/tests/js-tests/src/MaterialSystemTest/MaterialSystemTest.js b/tests/js-tests/src/MaterialSystemTest/MaterialSystemTest.js index bd3f79304d..829a59da38 100644 --- a/tests/js-tests/src/MaterialSystemTest/MaterialSystemTest.js +++ b/tests/js-tests/src/MaterialSystemTest/MaterialSystemTest.js @@ -169,10 +169,10 @@ var Material_setTechnique = MaterialSystemTestDemo.extend({ sprite.setMaterial(mat); //lights - var light1 = jsb.AmbientLight.create(cc.color.RED); + var light1 = new jsb.AmbientLight(cc.color.RED); this.addChild(light1); - var light2 = jsb.DirectionLight.create(cc.math.vec3(-1, 1, 0), cc.color.GREEN); + var light2 = new jsb.DirectionLight(cc.math.vec3(-1, 1, 0), cc.color.GREEN); this.addChild(light2); sprite.runAction(cc.rotateBy(5, cc.math.vec3(30, 60, 270)).repeatForever()); diff --git a/tests/js-tests/src/NavMeshTest/NavMeshTest.js b/tests/js-tests/src/NavMeshTest/NavMeshTest.js index 9877b7ffb9..b6dff5cd8c 100644 --- a/tests/js-tests/src/NavMeshTest/NavMeshTest.js +++ b/tests/js-tests/src/NavMeshTest/NavMeshTest.js @@ -77,7 +77,7 @@ var NavMeshBaseTestDemo = NavMeshTestScene.extend({ rbDes.mass = 0; rbDes.shape = jsb.Physics3DShape.createMesh(trianglesList, trianglesList.length/3); var rigidBody = jsb.Physics3DRigidBody.create(rbDes); - var component = jsb.Physics3DComponent.create(rigidBody); + var component = new jsb.Physics3DComponent(rigidBody); var sprite = jsb.Sprite3D.create("NavMesh/scene.obj"); sprite.addComponent(component); sprite.setCameraMask(cc.CameraFlag.USER1); @@ -90,11 +90,11 @@ var NavMeshBaseTestDemo = NavMeshTestScene.extend({ physicsScene.setNavMesh(navMesh); physicsScene.setNavMeshDebugCamera(this._camera); - var ambientLight = jsb.AmbientLight.create(cc.color(64, 64, 64)); + var ambientLight = new jsb.AmbientLight(cc.color(64, 64, 64)); ambientLight.setCameraMask(cc.CameraFlag.USER1); this.addChild(ambientLight); - var dirLight = jsb.DirectionLight.create(cc.math.vec3(1.2, -1.1, 0.5), cc.color(255, 255, 255)); + var dirLight = new jsb.DirectionLight(cc.math.vec3(1.2, -1.1, 0.5), cc.color(255, 255, 255)); dirLight.setCameraMask(cc.CameraFlag.USER1); this.addChild(dirLight); }, diff --git a/tests/js-tests/src/Physics3DTest/Physics3DTest.js b/tests/js-tests/src/Physics3DTest/Physics3DTest.js index 886970aa74..1eff7180f2 100644 --- a/tests/js-tests/src/Physics3DTest/Physics3DTest.js +++ b/tests/js-tests/src/Physics3DTest/Physics3DTest.js @@ -304,7 +304,7 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ var rigidBody = jsb.Physics3DRigidBody.create(rbDes); var quat = cc.math.quaternion(cc.math.vec3(0, 1, 0), cc.degreesToRadians(180)); - var component = jsb.Physics3DComponent.create(rigidBody, cc.math.vec3(0, -3, 0), quat); + var component = new jsb.Physics3DComponent(rigidBody, cc.math.vec3(0, -3, 0), quat); var sprite = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); sprite.addComponent(component); @@ -326,7 +326,7 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ rbDes.mass = 1; rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(8, 8, 1)); rigidBody = jsb.Physics3DRigidBody.create(rbDes); - component = jsb.Physics3DComponent.create(rigidBody); + component = new jsb.Physics3DComponent(rigidBody); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScaleX(8); @@ -344,7 +344,7 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ rbDes.mass = 1; rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(3, 2, 3)); rigidBody = jsb.Physics3DRigidBody.create(rbDes); - component = jsb.Physics3DComponent.create(rigidBody); + component = new jsb.Physics3DComponent(rigidBody); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScaleX(3); @@ -359,7 +359,7 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ rbDes.mass = 0; rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(3, 3, 3)); var rigidBodyB = jsb.Physics3DRigidBody.create(rbDes); - component = jsb.Physics3DComponent.create(rigidBodyB); + component = new jsb.Physics3DComponent(rigidBodyB); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScale(3); @@ -380,7 +380,7 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ rbDes.mass = 1; rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(3, 3, 3)); rigidBody = jsb.Physics3DRigidBody.create(rbDes); - component = jsb.Physics3DComponent.create(rigidBody); + component = new jsb.Physics3DComponent(rigidBody); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScale(3); @@ -399,7 +399,7 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ rbDes.mass = 1; rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(3, 3, 3)); rigidBody = jsb.Physics3DRigidBody.create(rbDes); - component = jsb.Physics3DComponent.create(rigidBody); + component = new jsb.Physics3DComponent(rigidBody); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScale(3); @@ -571,7 +571,7 @@ var Physics3DCollisionCallbackDemo = Physics3DTestDemo.extend({ rbDes.shape = jsb.Physics3DShape.createMesh(trianglesList, trianglesList.length/3); var rigidBody = jsb.Physics3DRigidBody.create(rbDes); - var component = jsb.Physics3DComponent.create(rigidBody); + var component = new jsb.Physics3DComponent(rigidBody); var sprite = new jsb.Sprite3D("Sprite3DTest/boss.c3b"); sprite.addComponent(component); sprite.setRotation3D(cc.math.vec3(-90, 0, 0)); @@ -634,7 +634,7 @@ var Physics3DTerrainDemo = Physics3DTestDemo.extend({ var size = terrain.getTerrainSize(); rbDes.shape = jsb.Physics3DShape.createHeightfield(size.width, size.height, heightData, 1.0, terrain.getMinHeight(), terrain.getMaxHeight(), true, false, true); var rigidBody = jsb.Physics3DRigidBody.create(rbDes); - var component = jsb.Physics3DComponent.create(rigidBody); + var component = new jsb.Physics3DComponent(rigidBody); terrain.addComponent(component); component.syncNodeToPhysics(); component.setSyncFlag(jsb.Physics3DComponent.PhysicsSyncFlag.NONE); @@ -672,7 +672,7 @@ var Physics3DTerrainDemo = Physics3DTestDemo.extend({ rbDes.mass = 0; rbDes.shape = jsb.Physics3DShape.createMesh(trianglesList, trianglesList.length/3); rigidBody = jsb.Physics3DRigidBody.create(rbDes); - component = jsb.Physics3DComponent.create(rigidBody); + component = new jsb.Physics3DComponent(rigidBody); var sprite = new jsb.Sprite3D("Sprite3DTest/boss.c3b"); sprite.addComponent(component); sprite.setRotation3D(cc.math.vec3(-90, 0, 0)); diff --git a/tests/js-tests/src/Sprite3DTest/Sprite3DTest.js b/tests/js-tests/src/Sprite3DTest/Sprite3DTest.js index ceb59d5311..2254a22e8b 100644 --- a/tests/js-tests/src/Sprite3DTest/Sprite3DTest.js +++ b/tests/js-tests/src/Sprite3DTest/Sprite3DTest.js @@ -1190,7 +1190,7 @@ var Sprite3DLightMapTest = Sprite3DTestDemo.extend({ var light = jsb.PointLight.create(cc.math.vec3(35, 75, -20.5), cc.color(255, 255, 255), 150); this.addChild(light); //set the ambient light - var ambient = jsb.AmbientLight.create(cc.color(55, 55, 55)); + var ambient = new jsb.AmbientLight(cc.color(55, 55, 55)); this.addChild(ambient); //create a listener