From 10a8adad53c7393e63cf9bde320255ac844bb734 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 18 Jun 2015 20:39:40 +0800 Subject: [PATCH 1/2] Change physics3d api to jsb namespace --- .../jsb_cocos2dx_physics3d_manual.cpp | 2 +- cocos/scripting/js-bindings/script/jsb.js | 2 +- .../script/physics3d/jsb_physics3d.js | 14 +- .../src/Physics3DTest/Physics3DTest.js | 124 +++++++++--------- tools/tojs/cocos2dx_physics3d.ini | 2 +- 5 files changed, 72 insertions(+), 72 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/physics3d/jsb_cocos2dx_physics3d_manual.cpp b/cocos/scripting/js-bindings/manual/physics3d/jsb_cocos2dx_physics3d_manual.cpp index 868ec2f9d5..5c3da4628c 100644 --- a/cocos/scripting/js-bindings/manual/physics3d/jsb_cocos2dx_physics3d_manual.cpp +++ b/cocos/scripting/js-bindings/manual/physics3d/jsb_cocos2dx_physics3d_manual.cpp @@ -390,7 +390,7 @@ bool js_cocos2dx_physics3d_Physics3DWorld_rayCast(JSContext *cx, uint32_t argc, void register_all_cocos2dx_physics3d_manual(JSContext *cx, JS::HandleObject global) { JS::RootedObject ccObj(cx); - get_or_create_js_obj(cx, global, "cc", &ccObj); + get_or_create_js_obj(cx, global, "jsb", &ccObj); JS::RootedValue tmpVal(cx); JS_GetProperty(cx, ccObj, "PhysicsSprite3D", &tmpVal); diff --git a/cocos/scripting/js-bindings/script/jsb.js b/cocos/scripting/js-bindings/script/jsb.js index e88f281201..878a8f988a 100644 --- a/cocos/scripting/js-bindings/script/jsb.js +++ b/cocos/scripting/js-bindings/script/jsb.js @@ -138,5 +138,5 @@ if (jsb.ParticleSystem3D) { require('script/3d/jsb_cocos2d_3d_ext.js'); } -if(cc.Physics3DObject) +if(jsb.Physics3DObject) require("script/physics3d/jsb_physics3d.js"); diff --git a/cocos/scripting/js-bindings/script/physics3d/jsb_physics3d.js b/cocos/scripting/js-bindings/script/physics3d/jsb_physics3d.js index e2e3d68c38..19d94145a8 100644 --- a/cocos/scripting/js-bindings/script/physics3d/jsb_physics3d.js +++ b/cocos/scripting/js-bindings/script/physics3d/jsb_physics3d.js @@ -20,7 +20,7 @@ * THE SOFTWARE. */ -cc.Physics3DRigidBodyDes = function(){ +jsb.Physics3DRigidBodyDes = function(){ this.mass = 0; this.localInertia = cc.math.vec3(0, 0, 0); this.shape = null; @@ -31,28 +31,28 @@ cc.Physics3DRigidBodyDes = function(){ this.disableSleep = false; }; -cc.physics3DRigidBodyDes = function(){ - return new cc.Physics3DRigidBodyDes(); +jsb.physics3DRigidBodyDes = function(){ + return new jsb.Physics3DRigidBodyDes(); }; -cc.Physics3DComponent.PhysicsSyncFlag = { +jsb.Physics3DComponent.PhysicsSyncFlag = { NONE : 0, NODE_TO_PHYSICS : 1, //align node transform to the physics PHYSICS_TO_NODE : 2, // align physics transform to the node NODE_AND_NODE : 1 | 2, //pre simulation, align the physics object to the node and align the node transform according to physics object after simulation }; -cc.HitResult = function(){ +jsb.HitResult = function(){ this.hitPosition = cc.math.vec3(); this.hitNormal = cc.math.vec3(); this.hitObj = null; } -cc.hitResult = function(){ +jsb.hitResult = function(){ return new cc.HitResult(); }; -cc.Physics3DObject.PhysicsObjType = { +jsb.Physics3DObject.PhysicsObjType = { UNKNOWN : 0, RIGID_BODY : 1, }; \ No newline at end of file diff --git a/tests/js-tests/src/Physics3DTest/Physics3DTest.js b/tests/js-tests/src/Physics3DTest/Physics3DTest.js index 1e87d6b773..1cb1bef5cb 100644 --- a/tests/js-tests/src/Physics3DTest/Physics3DTest.js +++ b/tests/js-tests/src/Physics3DTest/Physics3DTest.js @@ -113,7 +113,7 @@ var Physics3DTestDemo = cc.Layer.extend({ }, shootBox:function(des){ - var rbDes = cc.physics3DRigidBodyDes(); + var rbDes = jsb.physics3DRigidBodyDes(); var linearVel = cc.math.vec3Sub(des, this._camera.getPosition3D()); linearVel.normalize(); linearVel.x *= 100; @@ -121,12 +121,12 @@ var Physics3DTestDemo = cc.Layer.extend({ linearVel.z *= 100; rbDes.mass = 1; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(0.5, 0.5, 0.5)); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(0.5, 0.5, 0.5)); var v = this._camera.getPosition3D(); rbDes.originalTransform[12] = v.x; rbDes.originalTransform[13] = v.y; rbDes.originalTransform[14] = v.z; - var sprite = cc.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); + var sprite = jsb.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); sprite.setTexture("Images/Icon.png"); var rigidBody = sprite.getPhysicsObj(); @@ -140,7 +140,7 @@ var Physics3DTestDemo = cc.Layer.extend({ sprite.setPosition3D(this._camera.getPosition3D()); sprite.setScale(0.5); sprite.syncNodeToPhysics(); - sprite.setSyncFlag(cc.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); + sprite.setSyncFlag(jsb.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); sprite.setCameraMask(cc.CameraFlag.USER1); }, @@ -241,11 +241,11 @@ var BasicPhysics3DDemo = Physics3DTestDemo.extend({ ctor:function(){ this._super(); - var rbDes = cc.physics3DRigidBodyDes(); + var rbDes = jsb.physics3DRigidBodyDes(); rbDes.mass = 0; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(60, 1, 60)); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(60, 1, 60)); - var floor = cc.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); + var floor = jsb.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); floor.setTexture("Sprite3DTest/plane.png"); floor.setScaleX(60); floor.setScaleZ(60); @@ -253,11 +253,11 @@ var BasicPhysics3DDemo = Physics3DTestDemo.extend({ floor.setCameraMask(cc.CameraFlag.USER1); floor.syncNodeToPhysics(); //static object sync is not needed - floor.setSyncFlag(cc.Physics3DComponent.PhysicsSyncFlag.NONE); + floor.setSyncFlag(jsb.Physics3DComponent.PhysicsSyncFlag.NONE); //create several boxes using PhysicsSprite3D rbDes.mass = 1; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(0.8, 0.8, 0.8)); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(0.8, 0.8, 0.8)); var start_x = START_POS_X - ARRAY_SIZE_X/2; var start_y = START_POS_Y; var start_z = START_POS_Z - ARRAY_SIZE_Z/2; @@ -268,11 +268,11 @@ var BasicPhysics3DDemo = Physics3DTestDemo.extend({ var x = i + start_x, y = 5 + k + start_y, z = j + start_z; - var sprite = cc.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); + var sprite = jsb.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); sprite.setTexture("Images/CyanSquare.png"); sprite.setPosition3D(cc.math.vec3(x, y, z)); sprite.syncNodeToPhysics(); - sprite.setSyncFlag(cc.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); + sprite.setSyncFlag(jsb.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); sprite.setCameraMask(cc.CameraFlag.USER1); sprite.setScale(0.8); this.addChild(sprite); @@ -297,14 +297,14 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ this._listener.onTouchesEnded = this.onTouchesEnded.bind(this); //PhysicsSprite3d = Sprite3D + Physics3DComponent - var rbDes = cc.physics3DRigidBodyDes(); + var rbDes = jsb.physics3DRigidBodyDes(); rbDes.disableSleep = true; rbDes.mass = 10; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(5, 5, 5)); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(5, 5, 5)); - var rigidBody = cc.Physics3DRigidBody.create(rbDes); + var rigidBody = jsb.Physics3DRigidBody.create(rbDes); var quat = cc.math.quaternion(cc.math.vec3(0, 1, 0), cc.degreesToRadians(180)); - var component = cc.Physics3DComponent.create(rigidBody, cc.math.vec3(0, -3, 0), quat); + var component = jsb.Physics3DComponent.create(rigidBody, cc.math.vec3(0, -3, 0), quat); var sprite = new jsb.Sprite3D("Sprite3DTest/orc.c3b"); sprite.addComponent(component); @@ -313,20 +313,20 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ sprite.setScale(0.4); sprite.setPosition3D(cc.math.vec3(-20, 5, 0)); component.syncNodeToPhysics(); - component.setSyncFlag(cc.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); + component.setSyncFlag(jsb.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); physicsScene.setPhysics3DDebugCamera(this._camera); this._world = physicsScene.getPhysics3DWorld(); //create point to point constraint - var constraint = cc.Physics3DPointToPointConstraint.create(rigidBody, cc.math.vec3(2.5, 2.5, 2.5)); + var constraint = jsb.Physics3DPointToPointConstraint.create(rigidBody, cc.math.vec3(2.5, 2.5, 2.5)); this._world.addPhysics3DConstraint(constraint); //create hinge constraint rbDes.mass = 1; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(8, 8, 1)); - rigidBody = cc.Physics3DRigidBody.create(rbDes); - component = cc.Physics3DComponent.create(rigidBody); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(8, 8, 1)); + rigidBody = jsb.Physics3DRigidBody.create(rbDes); + component = jsb.Physics3DComponent.create(rigidBody); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScaleX(8); @@ -337,14 +337,14 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ this.addChild(sprite); component.syncNodeToPhysics(); rigidBody.setAngularVelocity(cc.math.vec3(0, 3, 0)); - constraint = cc.Physics3DHingeConstraint.create(rigidBody, cc.math.vec3(4, 4, 0.5), cc.math.vec3(0, 1, 0)); + constraint = jsb.Physics3DHingeConstraint.create(rigidBody, cc.math.vec3(4, 4, 0.5), cc.math.vec3(0, 1, 0)); this._world.addPhysics3DConstraint(constraint); //create slider constraint rbDes.mass = 1; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(3, 2, 3)); - rigidBody = cc.Physics3DRigidBody.create(rbDes); - component = cc.Physics3DComponent.create(rigidBody); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(3, 2, 3)); + rigidBody = jsb.Physics3DRigidBody.create(rbDes); + component = jsb.Physics3DComponent.create(rigidBody); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScaleX(3); @@ -357,9 +357,9 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ rigidBody.setLinearVelocity(cc.math.vec3(0, 3, 0)); rbDes.mass = 0; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(3, 3, 3)); - var rigidBodyB = cc.Physics3DRigidBody.create(rbDes); - component = cc.Physics3DComponent.create(rigidBodyB); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(3, 3, 3)); + var rigidBodyB = jsb.Physics3DRigidBody.create(rbDes); + component = jsb.Physics3DComponent.create(rigidBodyB); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScale(3); @@ -371,16 +371,16 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ var frameInA = [-4.37114e-8, 1, 0, 0, -1, -4.37114e-8, 0, 0, 0, 0, 1, 0, 0, -5, 0, 1]; var frameInB = [-4.37114e-8, 1, 0, 0, -1, -4.37114e-8, 0, 0, 0, 0, 1, 0, 0, 5, 0, 1]; - constraint = cc.Physics3DSliderConstraint.create(rigidBody, rigidBodyB, frameInA, frameInB, false); + constraint = jsb.Physics3DSliderConstraint.create(rigidBody, rigidBodyB, frameInA, frameInB, false); this._world.addPhysics3DConstraint(constraint); constraint.setLowerLinLimit(-5); constraint.setUpperLinLimit(5); //create ConeTwist constraint rbDes.mass = 1; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(3, 3, 3)); - rigidBody = cc.Physics3DRigidBody.create(rbDes); - component = cc.Physics3DComponent.create(rigidBody); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(3, 3, 3)); + rigidBody = jsb.Physics3DRigidBody.create(rbDes); + component = jsb.Physics3DComponent.create(rigidBody); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScale(3); @@ -391,15 +391,15 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ component.syncNodeToPhysics(); frameInA = [-4.37114e-8, 1, 0, 0, -1, -4.37114e-8, 0, 0, 0, 0, 1, 0, 0, -10, 0, 1]; - constraint = cc.Physics3DConeTwistConstraint.create(rigidBody, frameInA); + constraint = jsb.Physics3DConeTwistConstraint.create(rigidBody, frameInA); this._world.addPhysics3DConstraint(constraint, true); constraint.setLimit(cc.degreesToRadians(10), cc.degreesToRadians(10), cc.degreesToRadians(40)); //create 6 dof constraint rbDes.mass = 1; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(3, 3, 3)); - rigidBody = cc.Physics3DRigidBody.create(rbDes); - component = cc.Physics3DComponent.create(rigidBody); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(3, 3, 3)); + rigidBody = jsb.Physics3DRigidBody.create(rbDes); + component = jsb.Physics3DComponent.create(rigidBody); sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t"); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setScale(3); @@ -410,7 +410,7 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ component.syncNodeToPhysics(); frameInA = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; - constraint = cc.Physics3D6DofConstraint.create(rigidBody, frameInA, false); + constraint = jsb.Physics3D6DofConstraint.create(rigidBody, frameInA, false); this._world.addPhysics3DConstraint(constraint); constraint.setAngularLowerLimit(cc.math.vec3(0, 0, 0)); constraint.setAngularUpperLimit(cc.math.vec3(0, 0, 0)); @@ -432,12 +432,12 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({ farP = this._camera.unproject(size, farP); var result = this._world.rayCast(nearP, farP); - if(result !== false && result.hitObj.getObjType() == cc.Physics3DObject.PhysicsObjType.RIGID_BODY) + if(result !== false && result.hitObj.getObjType() == jsb.Physics3DObject.PhysicsObjType.RIGID_BODY) { var mat = cc.math.mat4GetInversed(result.hitObj.getWorldTransform()); var position = cc.math.mat4TransformPoint(mat, result.hitPosition); - this._constraint = cc.Physics3DPointToPointConstraint.create(result.hitObj, position); + this._constraint = jsb.Physics3DPointToPointConstraint.create(result.hitObj, position); this._world.addPhysics3DConstraint(this._constraint, true); this._pickingDistance = cc.math.vec3Length(cc.math.vec3Sub(result.hitPosition, nearP)); return; @@ -482,11 +482,11 @@ var Physics3DKinematicDemo = Physics3DTestDemo.extend({ ctor:function(){ this._super(); - var rbDes = cc.physics3DRigidBodyDes(); + var rbDes = jsb.physics3DRigidBodyDes(); rbDes.mass = 0; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(60, 1, 60)); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(60, 1, 60)); - var floor = cc.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); + var floor = jsb.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); floor.setTexture("Sprite3DTest/plane.png"); floor.setScaleX(60); floor.setScaleZ(60); @@ -495,14 +495,14 @@ var Physics3DKinematicDemo = Physics3DTestDemo.extend({ floor.setCameraMask(cc.CameraFlag.USER1); floor.syncNodeToPhysics(); //static object sync is not needed - floor.setSyncFlag(cc.Physics3DComponent.PhysicsSyncFlag.NONE); + floor.setSyncFlag(jsb.Physics3DComponent.PhysicsSyncFlag.NONE); //create Kinematics for(var i = 0; i < 3; ++i){ rbDes.mass = 0; - rbDes.shape = cc.Physics3DShape.createBox(cc.math.vec3(2, 2, 2)); + rbDes.shape = jsb.Physics3DShape.createBox(cc.math.vec3(2, 2, 2)); - var sprite = cc.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); + var sprite = jsb.PhysicsSprite3D.create("Sprite3DTest/box.c3t", rbDes); sprite.setTexture("Images/CyanSquare.png"); sprite.setCameraMask(cc.CameraFlag.USER1); var rigidBody = sprite.getPhysicsObj(); @@ -518,7 +518,7 @@ var Physics3DKinematicDemo = Physics3DTestDemo.extend({ //create Dynamic rbDes.mass = 1; - rbDes.shape = cc.Physics3DShape.createSphere(0.5); + rbDes.shape = jsb.Physics3DShape.createSphere(0.5); var start_x = START_POS_X - ARRAY_SIZE_X/2; var start_y = START_POS_Y + 5; var start_z = START_POS_Z - ARRAY_SIZE_Z/2; @@ -534,11 +534,11 @@ var Physics3DKinematicDemo = Physics3DTestDemo.extend({ rbDes.originalTransform[13] = y; rbDes.originalTransform[14] = z; - var sprite = cc.PhysicsSprite3D.create("Sprite3DTest/sphere.c3b", rbDes); + var sprite = jsb.PhysicsSprite3D.create("Sprite3DTest/sphere.c3b", rbDes); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setPosition3D(cc.math.vec3(x, y, z)); sprite.syncNodeToPhysics(); - sprite.setSyncFlag(cc.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); + sprite.setSyncFlag(jsb.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); sprite.setCameraMask(cc.CameraFlag.USER1); sprite.setScale(1/sprite.getContentSize().width); this.addChild(sprite); @@ -556,7 +556,7 @@ var Physics3DCollisionCallbackDemo = Physics3DTestDemo.extend({ ctor:function(){ this._super(); - var rbDes = cc.physics3DRigidBodyDes(); + var rbDes = jsb.physics3DRigidBodyDes(); var scale = 2; var trianglesList = jsb.Bundle3D.getTrianglesList("Sprite3DTest/boss.c3b"); @@ -568,10 +568,10 @@ var Physics3DCollisionCallbackDemo = Physics3DTestDemo.extend({ } rbDes.mass = 0; - rbDes.shape = cc.Physics3DShape.createMesh(trianglesList, trianglesList.length/3); + rbDes.shape = jsb.Physics3DShape.createMesh(trianglesList, trianglesList.length/3); - var rigidBody = cc.Physics3DRigidBody.create(rbDes); - var component = cc.Physics3DComponent.create(rigidBody); + var rigidBody = jsb.Physics3DRigidBody.create(rbDes); + var component = jsb.Physics3DComponent.create(rigidBody); var sprite = new jsb.Sprite3D("Sprite3DTest/boss.c3b"); sprite.addComponent(component); sprite.setRotation3D(cc.math.vec3(-90, 0, 0)); @@ -627,23 +627,23 @@ var Physics3DTerrainDemo = Physics3DTestDemo.extend({ terrain.setCameraMask(2); terrain.setDrawWire(false); - var rbDes = cc.physics3DRigidBodyDes(); + var rbDes = jsb.physics3DRigidBodyDes(); rbDes.mass = 0; var heightData = terrain.getHeightData(); var size = terrain.getTerrainSize(); - rbDes.shape = cc.Physics3DShape.createHeightfield(size.width, size.height, heightData, 1.0, terrain.getMinHeight(), terrain.getMaxHeight(), true, false, true); - var rigidBody = cc.Physics3DRigidBody.create(rbDes); - var component = cc.Physics3DComponent.create(rigidBody); + 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); terrain.addComponent(component); component.syncNodeToPhysics(); - component.setSyncFlag(cc.Physics3DComponent.PhysicsSyncFlag.NONE); + component.setSyncFlag(jsb.Physics3DComponent.PhysicsSyncFlag.NONE); this.addChild(terrain); //create several spheres rbDes.mass = 1; - rbDes.shape = cc.Physics3DShape.createSphere(0.5); + rbDes.shape = jsb.Physics3DShape.createSphere(0.5); var start_x = START_POS_X - ARRAY_SIZE_X/2 + 5; var start_y = START_POS_Y + 20; var start_z = START_POS_Z - ARRAY_SIZE_Z/2; @@ -655,11 +655,11 @@ var Physics3DTerrainDemo = Physics3DTestDemo.extend({ y = 5 + k + start_y, z = j + start_z; - var sprite = cc.PhysicsSprite3D.create("Sprite3DTest/sphere.c3b", rbDes); + var sprite = jsb.PhysicsSprite3D.create("Sprite3DTest/sphere.c3b", rbDes); sprite.setTexture("Sprite3DTest/plane.png"); sprite.setPosition3D(cc.math.vec3(x, y, z)); sprite.syncNodeToPhysics(); - sprite.setSyncFlag(cc.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); + sprite.setSyncFlag(jsb.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE); sprite.setCameraMask(cc.CameraFlag.USER1); sprite.setScale(1/sprite.getContentSize().width); this.addChild(sprite); @@ -670,9 +670,9 @@ var Physics3DTerrainDemo = Physics3DTestDemo.extend({ //create mesh var trianglesList = jsb.Bundle3D.getTrianglesList("Sprite3DTest/boss.c3b"); rbDes.mass = 0; - rbDes.shape = cc.Physics3DShape.createMesh(trianglesList, trianglesList.length/3); - rigidBody = cc.Physics3DRigidBody.create(rbDes); - component = cc.Physics3DComponent.create(rigidBody); + rbDes.shape = jsb.Physics3DShape.createMesh(trianglesList, trianglesList.length/3); + rigidBody = jsb.Physics3DRigidBody.create(rbDes); + component = jsb.Physics3DComponent.create(rigidBody); var sprite = new jsb.Sprite3D("Sprite3DTest/boss.c3b"); sprite.addComponent(component); sprite.setRotation3D(cc.math.vec3(-90, 0, 0)); diff --git a/tools/tojs/cocos2dx_physics3d.ini b/tools/tojs/cocos2dx_physics3d.ini index ee7c9f11a4..3c8ab8726a 100644 --- a/tools/tojs/cocos2dx_physics3d.ini +++ b/tools/tojs/cocos2dx_physics3d.ini @@ -5,7 +5,7 @@ prefix = cocos2dx_physics3d # create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) # all classes will be embedded in that namespace -target_namespace = cc +target_namespace = jsb macro_judgement = #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION From e09ba8080f9728dc6d7a66e2c1d79c784dbcb5b0 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 18 Jun 2015 21:48:57 +0800 Subject: [PATCH 2/2] Fix create Sprite with PolygonInfo issue --- cocos/scripting/js-bindings/script/jsb.js | 2 +- cocos/scripting/js-bindings/script/jsb_create_apis.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cocos/scripting/js-bindings/script/jsb.js b/cocos/scripting/js-bindings/script/jsb.js index 878a8f988a..05dbcdde49 100644 --- a/cocos/scripting/js-bindings/script/jsb.js +++ b/cocos/scripting/js-bindings/script/jsb.js @@ -138,5 +138,5 @@ if (jsb.ParticleSystem3D) { require('script/3d/jsb_cocos2d_3d_ext.js'); } -if(jsb.Physics3DObject) +if (jsb.Physics3DObject) require("script/physics3d/jsb_physics3d.js"); diff --git a/cocos/scripting/js-bindings/script/jsb_create_apis.js b/cocos/scripting/js-bindings/script/jsb_create_apis.js index 5048a2dfb7..3f14bbafdc 100644 --- a/cocos/scripting/js-bindings/script/jsb_create_apis.js +++ b/cocos/scripting/js-bindings/script/jsb_create_apis.js @@ -97,6 +97,9 @@ _p._ctor = function(fileName, rect) { } else if (fileName instanceof cc.SpriteFrame) { //init with a sprite frame this.initWithSpriteFrame(fileName); + } else if (fileName instanceof jsb.PolygonInfo) { + //init with a polygon info + this.initWithPolygon(fileName); } } };