mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 09:46:02 +08:00
[ts] Removed error checking in loaders.
Safe to assume the data is valid. If not the ref impl can be used to check it, which has error checks.
This commit is contained in:
parent
3c0a43687b
commit
afcd899bca
@ -204,9 +204,7 @@ module spine {
|
|||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
let linkedMesh = this.linkedMeshes[i];
|
let linkedMesh = this.linkedMeshes[i];
|
||||||
let skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
|
let skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
|
||||||
if (!skin) throw new Error("Skin not found: " + linkedMesh.skin);
|
|
||||||
let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
|
let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
|
||||||
if (!parent) throw new Error("Parent mesh not found: " + linkedMesh.parent);
|
|
||||||
linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent as VertexAttachment : linkedMesh.mesh;
|
linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent as VertexAttachment : linkedMesh.mesh;
|
||||||
linkedMesh.mesh.setParentMesh(parent as MeshAttachment);
|
linkedMesh.mesh.setParentMesh(parent as MeshAttachment);
|
||||||
linkedMesh.mesh.updateUVs();
|
linkedMesh.mesh.updateUVs();
|
||||||
@ -839,7 +837,6 @@ module spine {
|
|||||||
for (let iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
|
for (let iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
|
||||||
let attachmentName = input.readStringRef();
|
let attachmentName = input.readStringRef();
|
||||||
let attachment = skin.getAttachment(slotIndex, attachmentName) as VertexAttachment;
|
let attachment = skin.getAttachment(slotIndex, attachmentName) as VertexAttachment;
|
||||||
if (!attachment) throw Error("Vertex attachment not found: " + attachmentName);
|
|
||||||
let weighted = attachment.bones;
|
let weighted = attachment.bones;
|
||||||
let vertices = attachment.vertices;
|
let vertices = attachment.vertices;
|
||||||
let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
|
let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
|
||||||
|
|||||||
@ -73,10 +73,7 @@ module spine {
|
|||||||
|
|
||||||
let parent: BoneData = null;
|
let parent: BoneData = null;
|
||||||
let parentName: string = getValue(boneMap, "parent", null);
|
let parentName: string = getValue(boneMap, "parent", null);
|
||||||
if (parentName) {
|
if (parentName) parent = skeletonData.findBone(parentName);
|
||||||
parent = skeletonData.findBone(parentName);
|
|
||||||
if (!parent) throw new Error("Parent bone not found: " + parentName);
|
|
||||||
}
|
|
||||||
let data = new BoneData(skeletonData.bones.length, boneMap.name, parent);
|
let data = new BoneData(skeletonData.bones.length, boneMap.name, parent);
|
||||||
data.length = getValue(boneMap, "length", 0) * scale;
|
data.length = getValue(boneMap, "length", 0) * scale;
|
||||||
data.x = getValue(boneMap, "x", 0) * scale;
|
data.x = getValue(boneMap, "x", 0) * scale;
|
||||||
@ -100,11 +97,8 @@ module spine {
|
|||||||
if (root.slots) {
|
if (root.slots) {
|
||||||
for (let i = 0; i < root.slots.length; i++) {
|
for (let i = 0; i < root.slots.length; i++) {
|
||||||
let slotMap = root.slots[i];
|
let slotMap = root.slots[i];
|
||||||
let slotName: string = slotMap.name;
|
let boneData = skeletonData.findBone(slotMap.bone);
|
||||||
let boneName: string = slotMap.bone;
|
let data = new SlotData(skeletonData.slots.length, slotMap.name, boneData);
|
||||||
let boneData = skeletonData.findBone(boneName);
|
|
||||||
if (!boneData) throw new Error("Slot bone not found: " + boneName);
|
|
||||||
let data = new SlotData(skeletonData.slots.length, slotName, boneData);
|
|
||||||
|
|
||||||
let color: string = getValue(slotMap, "color", null);
|
let color: string = getValue(slotMap, "color", null);
|
||||||
if (color) data.color.setFromString(color);
|
if (color) data.color.setFromString(color);
|
||||||
@ -126,16 +120,10 @@ module spine {
|
|||||||
data.order = getValue(constraintMap, "order", 0);
|
data.order = getValue(constraintMap, "order", 0);
|
||||||
data.skinRequired = getValue(constraintMap, "skin", false);
|
data.skinRequired = getValue(constraintMap, "skin", false);
|
||||||
|
|
||||||
for (let ii = 0; ii < constraintMap.bones.length; ii++) {
|
for (let ii = 0; ii < constraintMap.bones.length; ii++)
|
||||||
let boneName = constraintMap.bones[ii];
|
data.bones.push(skeletonData.findBone(constraintMap.bones[ii]));
|
||||||
let bone = skeletonData.findBone(boneName);
|
|
||||||
if (!bone) throw new Error("IK bone not found: " + boneName);
|
|
||||||
data.bones.push(bone);
|
|
||||||
}
|
|
||||||
|
|
||||||
let targetName: string = constraintMap.target;
|
data.target = skeletonData.findBone(constraintMap.target);
|
||||||
data.target = skeletonData.findBone(targetName);
|
|
||||||
if (!data.target) throw new Error("IK target bone not found: " + targetName);
|
|
||||||
|
|
||||||
data.mix = getValue(constraintMap, "mix", 1);
|
data.mix = getValue(constraintMap, "mix", 1);
|
||||||
data.softness = getValue(constraintMap, "softness", 0) * scale;
|
data.softness = getValue(constraintMap, "softness", 0) * scale;
|
||||||
@ -156,16 +144,11 @@ module spine {
|
|||||||
data.order = getValue(constraintMap, "order", 0);
|
data.order = getValue(constraintMap, "order", 0);
|
||||||
data.skinRequired = getValue(constraintMap, "skin", false);
|
data.skinRequired = getValue(constraintMap, "skin", false);
|
||||||
|
|
||||||
for (let ii = 0; ii < constraintMap.bones.length; ii++) {
|
for (let ii = 0; ii < constraintMap.bones.length; ii++)
|
||||||
let boneName = constraintMap.bones[ii];
|
data.bones.push(skeletonData.findBone(constraintMap.bones[ii]));
|
||||||
let bone = skeletonData.findBone(boneName);
|
|
||||||
if (!bone) throw new Error("Transform constraint bone not found: " + boneName);
|
|
||||||
data.bones.push(bone);
|
|
||||||
}
|
|
||||||
|
|
||||||
let targetName: string = constraintMap.target;
|
let targetName: string = constraintMap.target;
|
||||||
data.target = skeletonData.findBone(targetName);
|
data.target = skeletonData.findBone(targetName);
|
||||||
if (!data.target) throw new Error("Transform constraint target bone not found: " + targetName);
|
|
||||||
|
|
||||||
data.local = getValue(constraintMap, "local", false);
|
data.local = getValue(constraintMap, "local", false);
|
||||||
data.relative = getValue(constraintMap, "relative", false);
|
data.relative = getValue(constraintMap, "relative", false);
|
||||||
@ -195,16 +178,11 @@ module spine {
|
|||||||
data.order = getValue(constraintMap, "order", 0);
|
data.order = getValue(constraintMap, "order", 0);
|
||||||
data.skinRequired = getValue(constraintMap, "skin", false);
|
data.skinRequired = getValue(constraintMap, "skin", false);
|
||||||
|
|
||||||
for (let ii = 0; ii < constraintMap.bones.length; ii++) {
|
for (let ii = 0; ii < constraintMap.bones.length; ii++)
|
||||||
let boneName = constraintMap.bones[ii];
|
data.bones.push(skeletonData.findBone(constraintMap.bones[ii]));
|
||||||
let bone = skeletonData.findBone(boneName);
|
|
||||||
if (!bone) throw new Error("Transform constraint bone not found: " + boneName);
|
|
||||||
data.bones.push(bone);
|
|
||||||
}
|
|
||||||
|
|
||||||
let targetName: string = constraintMap.target;
|
let targetName: string = constraintMap.target;
|
||||||
data.target = skeletonData.findSlot(targetName);
|
data.target = skeletonData.findSlot(targetName);
|
||||||
if (!data.target) throw new Error("Path target slot not found: " + targetName);
|
|
||||||
|
|
||||||
data.positionMode = Utils.enumValue(PositionMode, getValue(constraintMap, "positionMode", "Percent"));
|
data.positionMode = Utils.enumValue(PositionMode, getValue(constraintMap, "positionMode", "Percent"));
|
||||||
data.spacingMode = Utils.enumValue(SpacingMode, getValue(constraintMap, "spacingMode", "Length"));
|
data.spacingMode = Utils.enumValue(SpacingMode, getValue(constraintMap, "spacingMode", "Length"));
|
||||||
@ -229,40 +207,27 @@ module spine {
|
|||||||
let skin = new Skin(skinMap.name);
|
let skin = new Skin(skinMap.name);
|
||||||
|
|
||||||
if (skinMap.bones) {
|
if (skinMap.bones) {
|
||||||
for (let ii = 0; ii < skinMap.bones.length; ii++) {
|
for (let ii = 0; ii < skinMap.bones.length; ii++)
|
||||||
let bone = skeletonData.findBone(skinMap.bones[ii]);
|
skin.bones.push(skeletonData.findBone(skinMap.bones[ii]));
|
||||||
if (!bone) throw new Error("Skin bone not found: " + skinMap.bones[i]);
|
|
||||||
skin.bones.push(bone);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skinMap.ik) {
|
if (skinMap.ik) {
|
||||||
for (let ii = 0; ii < skinMap.ik.length; ii++) {
|
for (let ii = 0; ii < skinMap.ik.length; ii++)
|
||||||
let constraint = skeletonData.findIkConstraint(skinMap.ik[ii]);
|
skin.constraints.push(skeletonData.findIkConstraint(skinMap.ik[ii]));
|
||||||
if (!constraint) throw new Error("Skin IK constraint not found: " + skinMap.ik[i]);
|
|
||||||
skin.constraints.push(constraint);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skinMap.transform) {
|
if (skinMap.transform) {
|
||||||
for (let ii = 0; ii < skinMap.transform.length; ii++) {
|
for (let ii = 0; ii < skinMap.transform.length; ii++)
|
||||||
let constraint = skeletonData.findTransformConstraint(skinMap.transform[ii]);
|
skin.constraints.push(skeletonData.findTransformConstraint(skinMap.transform[ii]));
|
||||||
if (!constraint) throw new Error("Skin transform constraint not found: " + skinMap.transform[i]);
|
|
||||||
skin.constraints.push(constraint);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skinMap.path) {
|
if (skinMap.path) {
|
||||||
for (let ii = 0; ii < skinMap.path.length; ii++) {
|
for (let ii = 0; ii < skinMap.path.length; ii++)
|
||||||
let constraint = skeletonData.findPathConstraint(skinMap.path[ii]);
|
skin.constraints.push(skeletonData.findPathConstraint(skinMap.path[ii]));
|
||||||
if (!constraint) throw new Error("Skin path constraint not found: " + skinMap.path[i]);
|
|
||||||
skin.constraints.push(constraint);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let slotName in skinMap.attachments) {
|
for (let slotName in skinMap.attachments) {
|
||||||
let slot = skeletonData.findSlot(slotName);
|
let slot = skeletonData.findSlot(slotName);
|
||||||
if (!slot) throw new Error("Slot not found: " + slotName);
|
|
||||||
let slotMap = skinMap.attachments[slotName];
|
let slotMap = skinMap.attachments[slotName];
|
||||||
for (let entryName in slotMap) {
|
for (let entryName in slotMap) {
|
||||||
let attachment = this.readAttachment(slotMap[entryName], skin, slot.index, entryName, skeletonData);
|
let attachment = this.readAttachment(slotMap[entryName], skin, slot.index, entryName, skeletonData);
|
||||||
@ -278,9 +243,7 @@ module spine {
|
|||||||
for (let i = 0, n = this.linkedMeshes.length; i < n; i++) {
|
for (let i = 0, n = this.linkedMeshes.length; i < n; i++) {
|
||||||
let linkedMesh = this.linkedMeshes[i];
|
let linkedMesh = this.linkedMeshes[i];
|
||||||
let skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
|
let skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
|
||||||
if (!skin) throw new Error("Skin not found: " + linkedMesh.skin);
|
|
||||||
let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
|
let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
|
||||||
if (!parent) throw new Error("Parent mesh not found: " + linkedMesh.parent);
|
|
||||||
linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? <VertexAttachment>parent : <VertexAttachment>linkedMesh.mesh;
|
linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? <VertexAttachment>parent : <VertexAttachment>linkedMesh.mesh;
|
||||||
linkedMesh.mesh.setParentMesh(<MeshAttachment> parent);
|
linkedMesh.mesh.setParentMesh(<MeshAttachment> parent);
|
||||||
linkedMesh.mesh.updateUVs();
|
linkedMesh.mesh.updateUVs();
|
||||||
@ -410,11 +373,7 @@ module spine {
|
|||||||
if (!clip) return null;
|
if (!clip) return null;
|
||||||
|
|
||||||
let end = getValue(map, "end", null);
|
let end = getValue(map, "end", null);
|
||||||
if (end) {
|
if (end) clip.endSlot = skeletonData.findSlot(end);
|
||||||
let slot = skeletonData.findSlot(end);
|
|
||||||
if (!slot) throw new Error("Clipping end slot not found: " + end);
|
|
||||||
clip.endSlot = slot;
|
|
||||||
}
|
|
||||||
|
|
||||||
let vertexCount = map.vertexCount;
|
let vertexCount = map.vertexCount;
|
||||||
this.readVertices(map, clip, vertexCount << 1);
|
this.readVertices(map, clip, vertexCount << 1);
|
||||||
@ -465,7 +424,6 @@ module spine {
|
|||||||
for (let slotName in map.slots) {
|
for (let slotName in map.slots) {
|
||||||
let slotMap = map.slots[slotName];
|
let slotMap = map.slots[slotName];
|
||||||
let slotIndex = skeletonData.findSlotIndex(slotName);
|
let slotIndex = skeletonData.findSlotIndex(slotName);
|
||||||
if (slotIndex == -1) throw new Error("Slot not found: " + slotName);
|
|
||||||
for (let timelineName in slotMap) {
|
for (let timelineName in slotMap) {
|
||||||
let timelineMap = slotMap[timelineName];
|
let timelineMap = slotMap[timelineName];
|
||||||
if (!timelineMap) continue;
|
if (!timelineMap) continue;
|
||||||
@ -606,9 +564,7 @@ module spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timelines.push(timeline);
|
timelines.push(timeline);
|
||||||
|
}
|
||||||
} else
|
|
||||||
throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -618,7 +574,6 @@ module spine {
|
|||||||
for (let boneName in map.bones) {
|
for (let boneName in map.bones) {
|
||||||
let boneMap = map.bones[boneName];
|
let boneMap = map.bones[boneName];
|
||||||
let boneIndex = skeletonData.findBoneIndex(boneName);
|
let boneIndex = skeletonData.findBoneIndex(boneName);
|
||||||
if (boneIndex == -1) throw new Error("Bone not found: " + boneName);
|
|
||||||
for (let timelineName in boneMap) {
|
for (let timelineName in boneMap) {
|
||||||
let timelineMap = boneMap[timelineName];
|
let timelineMap = boneMap[timelineName];
|
||||||
if (timelineMap.length == 0) continue;
|
if (timelineMap.length == 0) continue;
|
||||||
@ -652,8 +607,7 @@ module spine {
|
|||||||
} else if (timelineName === "sheary") {
|
} else if (timelineName === "sheary") {
|
||||||
let timeline = new ShearYTimeline(timelineMap.length, timelineMap.length, boneIndex);
|
let timeline = new ShearYTimeline(timelineMap.length, timelineMap.length, boneIndex);
|
||||||
timelines.push(readTimeline1(timelineMap, timeline, 0, 1));
|
timelines.push(readTimeline1(timelineMap, timeline, 0, 1));
|
||||||
} else
|
}
|
||||||
throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -813,18 +767,15 @@ module spine {
|
|||||||
for (let deformName in map.deform) {
|
for (let deformName in map.deform) {
|
||||||
let deformMap = map.deform[deformName];
|
let deformMap = map.deform[deformName];
|
||||||
let skin = skeletonData.findSkin(deformName);
|
let skin = skeletonData.findSkin(deformName);
|
||||||
if (!skin) throw new Error("Skin not found: " + deformName);
|
|
||||||
for (let slotName in deformMap) {
|
for (let slotName in deformMap) {
|
||||||
let slotMap = deformMap[slotName];
|
let slotMap = deformMap[slotName];
|
||||||
let slotIndex = skeletonData.findSlotIndex(slotName);
|
let slotIndex = skeletonData.findSlotIndex(slotName);
|
||||||
if (slotIndex == -1) throw new Error("Slot not found: " + slotMap.name);
|
|
||||||
for (let timelineName in slotMap) {
|
for (let timelineName in slotMap) {
|
||||||
let timelineMap = slotMap[timelineName];
|
let timelineMap = slotMap[timelineName];
|
||||||
let keyMap = timelineMap[0];
|
let keyMap = timelineMap[0];
|
||||||
if (!keyMap) continue;
|
if (!keyMap) continue;
|
||||||
|
|
||||||
let attachment = <VertexAttachment>skin.getAttachment(slotIndex, timelineName);
|
let attachment = <VertexAttachment>skin.getAttachment(slotIndex, timelineName);
|
||||||
if (!attachment) throw new Error("Deform attachment not found: " + timelineMap.name);
|
|
||||||
let weighted = attachment.bones;
|
let weighted = attachment.bones;
|
||||||
let vertices = attachment.vertices;
|
let vertices = attachment.vertices;
|
||||||
let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
|
let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
|
||||||
@ -884,7 +835,6 @@ module spine {
|
|||||||
for (let ii = 0; ii < offsets.length; ii++) {
|
for (let ii = 0; ii < offsets.length; ii++) {
|
||||||
let offsetMap = offsets[ii];
|
let offsetMap = offsets[ii];
|
||||||
let slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
|
let slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
|
||||||
if (slotIndex == -1) throw new Error("Slot not found: " + offsetMap.slot);
|
|
||||||
// Collect unchanged items.
|
// Collect unchanged items.
|
||||||
while (originalIndex != slotIndex)
|
while (originalIndex != slotIndex)
|
||||||
unchanged[unchangedIndex++] = originalIndex++;
|
unchanged[unchangedIndex++] = originalIndex++;
|
||||||
@ -910,7 +860,6 @@ module spine {
|
|||||||
for (let i = 0; i < map.events.length; i++, frame++) {
|
for (let i = 0; i < map.events.length; i++, frame++) {
|
||||||
let eventMap = map.events[i];
|
let eventMap = map.events[i];
|
||||||
let eventData = skeletonData.findEvent(eventMap.name);
|
let eventData = skeletonData.findEvent(eventMap.name);
|
||||||
if (!eventData) throw new Error("Event not found: " + eventMap.name);
|
|
||||||
let event = new Event(Utils.toSinglePrecision(getValue(eventMap, "time", 0)), eventData);
|
let event = new Event(Utils.toSinglePrecision(getValue(eventMap, "time", 0)), eventData);
|
||||||
event.intValue = getValue(eventMap, "int", eventData.intValue);
|
event.intValue = getValue(eventMap, "int", eventData.intValue);
|
||||||
event.floatValue = getValue(eventMap, "float", eventData.floatValue);
|
event.floatValue = getValue(eventMap, "float", eventData.floatValue);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user