mirror of https://github.com/axmolengine/axmol.git
revert old timelineParser-2.x.js and add "||false" to it.
This commit is contained in:
parent
76ed15591f
commit
8183d34b68
|
@ -160,12 +160,20 @@
|
|||
}
|
||||
};
|
||||
|
||||
var skyBoxBrushInstance = null;
|
||||
var getSkyboxRes = function(json, key) {
|
||||
if(json.hasOwnProperty(key) && json[key].hasOwnProperty("Path")) {
|
||||
return json[key]["Path"];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* SingleNode
|
||||
* @param json
|
||||
* @returns {cc.Node}
|
||||
*/
|
||||
parser.initSingleNode = function(json){
|
||||
parser.initSingleNode = function(json, resourcePath){
|
||||
var node = new cc.Node();
|
||||
|
||||
this.generalAttributes(node, json);
|
||||
|
@ -173,6 +181,27 @@
|
|||
if(color != null)
|
||||
node.setColor(getColor(color));
|
||||
|
||||
if(json.hasOwnProperty("SkyBoxEnabled") && true == json["SkyBoxEnabled"]&&
|
||||
json.hasOwnProperty("SkyBoxValid") && true == json["SkyBoxValid"])
|
||||
{
|
||||
var leftFileData = resourcePath + getSkyboxRes(json, "LeftImage");
|
||||
var rightFileData = resourcePath + getSkyboxRes(json, "RightImage");
|
||||
var upFileData = resourcePath + getSkyboxRes(json, "UpImage");
|
||||
var downFileData = resourcePath + getSkyboxRes(json, "DownImage");
|
||||
var forwardFileData = resourcePath + getSkyboxRes(json, "ForwardImage");
|
||||
var backFileData = resourcePath + getSkyboxRes(json, "BackImage");
|
||||
var fileUtil = jsb.fileUtils;
|
||||
if(fileUtil.isFileExist(leftFileData)&&
|
||||
fileUtil.isFileExist(rightFileData)&&
|
||||
fileUtil.isFileExist(upFileData)&&
|
||||
fileUtil.isFileExist(downFileData)&&
|
||||
fileUtil.isFileExist(forwardFileData)&&
|
||||
fileUtil.isFileExist(backFileData))
|
||||
{
|
||||
skyBoxBrushInstance = cc.CameraBackgroundSkyBoxBrush.create(leftFileData,rightFileData,upFileData,downFileData,forwardFileData,backFileData);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
|
@ -228,8 +257,6 @@
|
|||
var node,
|
||||
self = this;
|
||||
loadTexture(json["FileData"], resourcePath, function(path, type){
|
||||
if(!cc.loader.getRes(path))
|
||||
cc.log("%s need to be preloaded", path);
|
||||
node = new cc.ParticleSystem(path);
|
||||
self.generalAttributes(node, json);
|
||||
node.setPositionType(cc.ParticleSystem.TYPE_GROUPED);
|
||||
|
@ -887,8 +914,6 @@
|
|||
];
|
||||
textureList.forEach(function(item){
|
||||
loadTexture(json[item.name], resourcePath, function(path, type){
|
||||
if(type === 0 && !loader.getRes(path))
|
||||
cc.log("%s need to be preloaded", path);
|
||||
item.handle.call(widget, path, type);
|
||||
});
|
||||
});
|
||||
|
@ -1053,8 +1078,6 @@
|
|||
var startCharMap = json["StartChar"];
|
||||
|
||||
loadTexture(json["LabelAtlasFileImage_CNB"], resourcePath, function(path, type){
|
||||
if(!cc.loader.getRes(path))
|
||||
cc.log("%s need to be preloaded", path);
|
||||
if(type === 0){
|
||||
widget.setProperty(stringValue, path, itemWidth, itemHeight, startCharMap);
|
||||
}
|
||||
|
@ -1079,8 +1102,6 @@
|
|||
widget.setString(text);
|
||||
|
||||
loadTexture(json["LabelBMFontFile_CNB"], resourcePath, function(path, type){
|
||||
if(!cc.loader.getRes(path))
|
||||
cc.log("%s need to be pre loaded", path);
|
||||
widget.setFntFile(path);
|
||||
});
|
||||
widget.ignoreContentAdaptWithSize(true);
|
||||
|
@ -1275,8 +1296,6 @@
|
|||
|
||||
});
|
||||
|
||||
delete json["AnchorPoint"];
|
||||
delete json["Size"];
|
||||
parser.generalAttributes(node, json);
|
||||
|
||||
node.setColor(getColor(json["CColor"]));
|
||||
|
@ -1293,7 +1312,7 @@
|
|||
|
||||
var blendFunc = json["BlendFunc"];
|
||||
if(blendFunc && blendFunc["Src"] !== undefined && blendFunc["Dst"] !== undefined)
|
||||
node.setBlendFunc(new cc.BlendFunc(blendFunc["Src"], blendFunc["Dst"]));
|
||||
node.setBlendFunc(new cc.BlendFunc(blendFunc["Src"] || 0, blendFunc["Dst"] || 0));
|
||||
|
||||
parser.generalAttributes(node, json);
|
||||
var color = json["CColor"];
|
||||
|
@ -1356,6 +1375,363 @@
|
|||
node.setContentSize(cc.size(x, y));
|
||||
};
|
||||
|
||||
var get3DVector = function(json, name, defValue){
|
||||
var x = defValue, y = defValue, z = defValue;
|
||||
if(json && name && json[name]){
|
||||
if(undefined !== json[name]["ValueX"]) {
|
||||
x = json[name]["ValueX"];
|
||||
} else if(undefined !== json[name]["X"]) {
|
||||
x = json[name]["X"]
|
||||
}
|
||||
if(null === x || isNaN(x))
|
||||
x = defValue;
|
||||
|
||||
if(undefined !== json[name]["ValueY"]) {
|
||||
y = json[name]["ValueY"];
|
||||
} else if(undefined !== json[name]["Y"]) {
|
||||
y = json[name]["Y"]
|
||||
}
|
||||
if(null === y || isNaN(y))
|
||||
y = defValue;
|
||||
|
||||
if(undefined !== json[name]["ValueZ"]) {
|
||||
z = json[name]["ValueZ"];
|
||||
} else if(undefined !== json[name]["Z"]) {
|
||||
z = json[name]["Z"]
|
||||
}
|
||||
if(null === z || isNaN(z))
|
||||
z = defValue;
|
||||
}
|
||||
var vec3 = cc.math.vec3(x, y, z);
|
||||
return vec3;
|
||||
};
|
||||
|
||||
parser.general3DAttributes = function(node, json){
|
||||
var pos = get3DVector(json, "Position3D", 0);
|
||||
node.setPosition3D(pos);
|
||||
|
||||
var rotation = get3DVector(json, "Rotation3D", 0);
|
||||
node.setRotation3D(rotation);
|
||||
|
||||
var scale = get3DVector(json, "Scale3D", 1.0);
|
||||
node.setScaleX(scale.x);
|
||||
node.setScaleY(scale.y);
|
||||
node.setScaleZ(scale.z);
|
||||
|
||||
var camMask =json["CameraFlagMode"];
|
||||
if(undefined !== camMask && null !== camMask)
|
||||
node.setCameraMask(camMask);
|
||||
|
||||
this.generalAttributes(node, json);
|
||||
};
|
||||
|
||||
/**
|
||||
* Node3D
|
||||
* @param json
|
||||
* @returns {*}
|
||||
*/
|
||||
parser.initNode3D = function(json){
|
||||
var node = cc.Node.create();
|
||||
if(node)
|
||||
this.general3DAttributes(node, json);
|
||||
return node;
|
||||
};
|
||||
|
||||
/**
|
||||
* Camera
|
||||
* @param json
|
||||
* @returns {*}
|
||||
*/
|
||||
parser.initCamera = function(json,resourcePath){
|
||||
var s = cc.winSize;
|
||||
var fov = json["Fov"] ? json["Fov"] : 60;
|
||||
|
||||
var nearClip = 1;
|
||||
var farClip = 500;
|
||||
if(json["ClipPlane"]){
|
||||
if(undefined !== json["ClipPlane"]["ValueX"]) {
|
||||
nearClip = json["ClipPlane"]["ValueX"];
|
||||
} else if(undefined !== json["ClipPlane"]["X"]) {
|
||||
nearClip = json["ClipPlane"]["X"];
|
||||
}
|
||||
|
||||
if(undefined !== json["ClipPlane"]["ValueY"]) {
|
||||
farClip = json["ClipPlane"]["ValueY"];
|
||||
} else if(undefined !== json["ClipPlane"]["Y"]) {
|
||||
farClip = json["ClipPlane"]["Y"];
|
||||
}
|
||||
|
||||
if(null === nearClip || isNaN(nearClip))
|
||||
nearClip = 1;
|
||||
if(null === farClip || isNaN(farClip))
|
||||
farClip = 500;
|
||||
}
|
||||
|
||||
var node = cc.Camera.createPerspective(fov, s.width/s.height, nearClip, farClip);
|
||||
|
||||
if(node){
|
||||
this.general3DAttributes(node, json);
|
||||
|
||||
var camMode = json["UserCameraFlagMode"];
|
||||
var cameraFlagData = json["CameraFlagData"];
|
||||
var cameraFlag = cc.CameraFlag.USER1;
|
||||
if(undefined === cameraFlagData || isNaN(cameraFlagData) || 0 === cameraFlagData)
|
||||
{
|
||||
switch(camMode){
|
||||
case "USER1":
|
||||
cameraFlag = cc.CameraFlag.USER1; break;
|
||||
case "USER2":
|
||||
cameraFlag = cc.CameraFlag.USER2; break;
|
||||
case "USER3":
|
||||
cameraFlag = cc.CameraFlag.USER3; break;
|
||||
case "USER4":
|
||||
cameraFlag = cc.CameraFlag.USER4; break;
|
||||
case "USER5":
|
||||
cameraFlag = cc.CameraFlag.USER5; break;
|
||||
case "USER6":
|
||||
cameraFlag = cc.CameraFlag.USER6; break;
|
||||
case "USER7":
|
||||
cameraFlag = cc.CameraFlag.USER7; break;
|
||||
case "USER8":
|
||||
cameraFlag = cc.CameraFlag.USER8; break;
|
||||
case "DEFAULT":
|
||||
cameraFlag = cc.CameraFlag.DEFAULT; break;
|
||||
}
|
||||
} else {
|
||||
cameraFlag = cameraFlagData;
|
||||
}
|
||||
node.setCameraFlag(cameraFlag);
|
||||
}
|
||||
|
||||
if(json.hasOwnProperty("SkyBoxEnabled") && true == json["SkyBoxEnabled"] &&
|
||||
json.hasOwnProperty("SkyBoxValid") && true == json["SkyBoxValid"])
|
||||
{
|
||||
var leftFileData = resourcePath + getSkyboxRes(json, "LeftImage");
|
||||
var rightFileData = resourcePath + getSkyboxRes(json, "RightImage");
|
||||
var upFileData = resourcePath + getSkyboxRes(json, "UpImage");
|
||||
var downFileData = resourcePath + getSkyboxRes(json, "DownImage");
|
||||
var forwardFileData = resourcePath + getSkyboxRes(json, "ForwardImage");
|
||||
var backFileData = resourcePath + getSkyboxRes(json, "BackImage");
|
||||
|
||||
var fileUtil = jsb.fileUtils;
|
||||
if(fileUtil.isFileExist(leftFileData)&&
|
||||
fileUtil.isFileExist(rightFileData)&&
|
||||
fileUtil.isFileExist(upFileData)&&
|
||||
fileUtil.isFileExist(downFileData)&&
|
||||
fileUtil.isFileExist(forwardFileData)&&
|
||||
fileUtil.isFileExist(backFileData))
|
||||
{
|
||||
var innerBrush = cc.CameraBackgroundSkyBoxBrush.create(leftFileData,rightFileData,upFileData,downFileData,forwardFileData,backFileData);
|
||||
node.setBackgroundBrush(innerBrush);
|
||||
}
|
||||
else
|
||||
node.setBackgroundBrush(skyBoxBrushInstance);
|
||||
}
|
||||
else if(skyBoxBrushInstance != null)
|
||||
{
|
||||
node.setBackgroundBrush(skyBoxBrushInstance);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sprite3D
|
||||
* @param json
|
||||
* @param resourcePath
|
||||
* @returns {*}
|
||||
*/
|
||||
parser.initSprite3D = function(json, resourcePath){
|
||||
var resFile = null;
|
||||
if(json["FileData"] && json["FileData"]["Path"])
|
||||
resFile = resourcePath + json["FileData"]["Path"];
|
||||
|
||||
var node = null;
|
||||
if(resFile) {
|
||||
if(jsb.fileUtils.isFileExist(resFile))
|
||||
node = jsb.Sprite3D.create(resFile);
|
||||
}
|
||||
if(null === node)
|
||||
node = jsb.Sprite3D.create();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if(json.hasOwnProperty("IsFlipped") && true == json["IsFlipped"]) {
|
||||
node.setCullFaceEnabled(true);
|
||||
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, "");
|
||||
if(animation){
|
||||
var animate = jsb.Animate3D.create(animation);
|
||||
var action = cc.RepeatForever.create(animate);
|
||||
node.runAction(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
/**
|
||||
* Particle3D
|
||||
* @param json
|
||||
* @param resourcePath
|
||||
* @returns {*}
|
||||
*/
|
||||
parser.initParticle3D = function(json, resourcePath){
|
||||
var node = null;
|
||||
|
||||
var resFile = null;
|
||||
if(json["FileData"] && json["FileData"]["Path"])
|
||||
resFile = resourcePath+json["FileData"]["Path"];
|
||||
|
||||
if(resFile){
|
||||
if(jsb.fileUtils.isFileExist(resFile))
|
||||
node = jsb.PUParticleSystem3D.create(resFile);
|
||||
}
|
||||
|
||||
if(null === node)
|
||||
node = jsb.PUParticleSystem3D.create();
|
||||
|
||||
if(node){
|
||||
this.general3DAttributes(node, json);
|
||||
node.startParticleSystem();
|
||||
}
|
||||
|
||||
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},
|
||||
{name: "NodeObjectData", handle: parser.initSingleNode},
|
||||
|
@ -1382,7 +1758,13 @@
|
|||
{name: "ProjectNodeObjectData", handle: parser.initProjectNode},
|
||||
{name: "ArmatureNodeObjectData", handle: parser.initArmature},
|
||||
{name: "BoneNodeObjectData", handle: parser.initBoneNode},
|
||||
{name: "SkeletonNodeObjectData", handle: parser.initSkeletonNode}
|
||||
{name: "SkeletonNodeObjectData", handle: parser.initSkeletonNode},
|
||||
|
||||
{name: "Sprite3DObjectData", handle: parser.initSprite3D},
|
||||
{name: "Particle3DObjectData", handle: parser.initParticle3D},
|
||||
{name: "UserCameraObjectData", handle: parser.initCamera},
|
||||
{name: "Node3DObjectData", handle: parser.initNode3D},
|
||||
{name: "Light3DObjectData", handle: parser.initLight3D}
|
||||
];
|
||||
|
||||
register.forEach(function(item){
|
||||
|
|
Loading…
Reference in New Issue