From f2f6d25408ab55ae5db9003a21d08063e2064308 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Oct 2015 10:04:56 +0800 Subject: [PATCH] update for light3d js reader --- .../studio/parsers/timelineParser-2.x.js | 125 +++++++++++++++++- 1 file changed, 124 insertions(+), 1 deletion(-) diff --git a/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js b/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js index 5699352c79..8a1e5b9cc9 100644 --- a/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js +++ b/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js @@ -1567,6 +1567,39 @@ node.setCullFace(gl.FRONT); } + if(json.hasOwnProperty("LightFlag")){ + var lightFlagStr = json["LightFlag"]; + var lightFlag = 0; + switch(lightFlagStr){ + case "LIGHT0": + lightFlag = cc.LightFlag.LIGHT0; break; + case "LIGHT1": + lightFlag = cc.LightFlag.LIGHT1; break; + case "LIGHT2": + lightFlag = cc.LightFlag.LIGHT2; break; + case "LIGHT3": + lightFlag = cc.LightFlag.LIGHT3; break; + case "LIGHT4": + lightFlag = cc.LightFlag.LIGHT4; break; + case "LIGHT5": + lightFlag = cc.LightFlag.LIGHT5; break; + case "LIGHT6": + lightFlag = cc.LightFlag.LIGHT6; break; + case "LIGHT7": + lightFlag = cc.LightFlag.LIGHT7; break; + case "LIGHT8": + lightFlag = cc.LightFlag.LIGHT8; break; + case "LIGHT9": + lightFlag = cc.LightFlag.LIGHT9; break; + case "LIGHT10": + lightFlag = cc.LightFlag.LIGHT10; break; + case "LIGHT11": + lightFlag = cc.LightFlag.LIGHT11; break; + case "LIGHT12": + lightFlag = cc.LightFlag.LIGHT12; break; + } + node.setLightMask(lightFlag); + } var autoAction = getParam(json["RunAction3D"], false); if(autoAction && resFile){ var animation = jsb.Animation3D.create(resFile, ""); @@ -1609,6 +1642,95 @@ return node; }; + + /** + * Light3D + * @param json + * @param resourcePath + * @returns {*} + */ + parser.initLight3D = function(json, resourcePath){ + var node = new cc.Node(); + + var light = jsb.DirectionLight.create(cc.math.vec3(0, 0, 1), cc.color(255,255,255,255)); + var flag = 0; + var intensity = 1; + var range = 5.0; + var outerAngle = 30.0; + var enabled = true; + + if(json.hasOwnProperty("Intensity")){ + intensity = json["Intensity"]; + } + if(json.hasOwnProperty("Enable")){ + enabled = json["Enable"]; + } + if(json.hasOwnProperty("Range")){ + range = json["Range"]; + } + if(json.hasOwnProperty("OuterAngle")){ + outerAngle = json["OuterAngle"] * 0.5; + } + if(json.hasOwnProperty("Flag")){ + var lightFlagStr = json["Flag"]; + switch(lightFlagStr){ + case "LIGHT0": + flag = cc.LightFlag.LIGHT0; break; + case "LIGHT1": + flag = cc.LightFlag.LIGHT1; break; + case "LIGHT2": + flag = cc.LightFlag.LIGHT2; break; + case "LIGHT3": + flag = cc.LightFlag.LIGHT3; break; + case "LIGHT4": + flag = cc.LightFlag.LIGHT4; break; + case "LIGHT5": + flag = cc.LightFlag.LIGHT5; break; + case "LIGHT6": + flag = cc.LightFlag.LIGHT6; break; + case "LIGHT7": + flag = cc.LightFlag.LIGHT7; break; + case "LIGHT8": + flag = cc.LightFlag.LIGHT8; break; + case "LIGHT9": + flag = cc.LightFlag.LIGHT9; break; + case "LIGHT10": + flag = cc.LightFlag.LIGHT10; break; + case "LIGHT11": + flag = cc.LightFlag.LIGHT11; break; + case "LIGHT12": + flag = cc.LightFlag.LIGHT12; break; + } + } + if(json.hasOwnProperty("Type")){ + var type = json["Type"]; + switch(type){ + case "DIRECTIONAL": + light = jsb.DirectionLight.create(cc.math.vec3(0, 0, 1), cc.color(255, 255, 255, 255)); break; + case "POINT": + light = jsb.PointLight.create(cc.math.vec3(0, 0, 0), cc.color(255, 255, 255, 255), range); break; + case "SPOT": + light = jsb.SpotLight.create(cc.math.vec3(0, 0, 1), cc.math.vec3(0, 0, 0), cc.color(255, 255, 255, 255), 0, cc.degreesToRadians(outerAngle), range); break; + case "AMBIENT": + light = jsb.AmbientLight.create(cc.color(255,255,255,255)); break; + } + } + + light.setIntensity(intensity); + light.setEnabled(enabled); + light.setLightFlag(flag); + + node.addChild(light); + if(node) + this.general3DAttributes(node, json); + + if(json["CColor"]) { + var col = getColor(json["CColor"]); + if(col && col.r !== 255 || col.g !== 255 || col.b !== 255) + node.setColor(col); + } + return node; + }; var register = [ {name: "SingleNodeObjectData", handle: parser.initSingleNode}, @@ -1641,7 +1763,8 @@ {name: "Sprite3DObjectData", handle: parser.initSprite3D}, {name: "Particle3DObjectData", handle: parser.initParticle3D}, {name: "UserCameraObjectData", handle: parser.initCamera}, - {name: "Node3DObjectData", handle: parser.initNode3D} + {name: "Node3DObjectData", handle: parser.initNode3D}, + {name: "Light3DObjectData", handle: parser.initLight3D} ]; register.forEach(function(item){