bool jsb_cocos2dx_spine_getAttachment(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SkeletonRenderer* cobj = (SkeletonRenderer*)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 2) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spAttachment* ret = cobj->getAttachment(arg0, arg1); jsval jsret = JSVAL_NULL; do { if (ret) { jsret = spattachment_to_jsval(cx, *ret); } } while(0); args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); return false; }
bool jsb_cocos2dx_spine_findBone(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); SkeletonRenderer* cobj = (SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spBone* ret = cobj->findBone(arg0); jsval jsret = JSVAL_NULL; do { if (ret) { jsret = spbone_to_jsval(cx, *ret); } } while (0); args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); return false; }
bool jsb_cocos2dx_spine_findSlot(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SkeletonRenderer* cobj = (SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spSlot* ret = cobj->findSlot(arg0); jsval jsret = JSVAL_NULL; do { if (ret) { jsret = spslot_to_jsval(cx, *ret); } } while (0); JS_SET_RVAL(cx, vp, jsret); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); return false; }
bool jsb_cocos2dx_spine_setDebugSolots(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SkeletonRenderer* cobj = (SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { bool enable = args.get(0).toBoolean(); cobj->setDebugSlotsEnabled(enable); args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); return false; }
bool jsb_cocos2dx_spine_setDebugSolots(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); SkeletonRenderer* cobj = (SkeletonRenderer *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { bool enable = JSVAL_TO_BOOLEAN(argv[0]); cobj->setDebugSlotsEnabled(enable); JS_SET_RVAL(cx, vp, JSVAL_NULL); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); return false; }
SkeletonRenderer* SkeletonRenderer::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) { SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlasFile, scale); node->autorelease(); return node; }
SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale) { SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlas, scale); node->autorelease(); return node; }
SkeletonRenderer* SkeletonRenderer::createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) { SkeletonRenderer* node = new SkeletonRenderer(skeletonData, ownsSkeletonData); node->autorelease(); return node; }
void SkeletonAnimationFbo::renderToCache(Renderer* renderer, RenderCmdsCache* cache) { if (!cache) return; cache->clear(); if (!renderer) return; SkeletonRenderer* skeletonRenderer = (SkeletonRenderer*)renderer; if (mShouldRelaseCacheTexture){ mShouldRelaseCacheTexture = false; skeletonRenderer->releaseTextures(); } const QRectF rect = calculateSkeletonRect(); if (!isSkeletonValid()) return; cache->setSkeletonRect(rect); cache->bindShader(RenderCmdsCache::ShaderTexture); int additive = -1; Color color; const float* uvs = 0; int verticesCount = 0; const int* triangles = 0; int trianglesCount = 0; float r = 0, g = 0, b = 0, a = 0; for (int i = 0, n = mspSkeleton->slotsCount; i < n; i++) { spSlot* slot = mspSkeleton->drawOrder[i]; if (!slot->attachment) continue; Texture *texture = 0; switch (slot->attachment->type) { case SP_ATTACHMENT_REGION: { spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment; spRegionAttachment_computeWorldVertices(attachment, slot->bone, mWorldVertices); texture = getTexture(attachment); uvs = attachment->uvs; verticesCount = 8; triangles = quadTriangles; trianglesCount = 6; r = attachment->r; g = attachment->g; b = attachment->b; a = attachment->a; break; } case SP_ATTACHMENT_MESH: { spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment; spMeshAttachment_computeWorldVertices(attachment, slot, mWorldVertices); texture = getTexture(attachment); uvs = attachment->uvs; verticesCount = attachment->verticesCount; triangles = attachment->triangles; trianglesCount = attachment->trianglesCount; r = attachment->r; g = attachment->g; b = attachment->b; a = attachment->a; break; } case SP_ATTACHMENT_SKINNED_MESH: { spSkinnedMeshAttachment* attachment = (spSkinnedMeshAttachment*)slot->attachment; spSkinnedMeshAttachment_computeWorldVertices(attachment, slot, mWorldVertices); texture = getTexture(attachment); uvs = attachment->uvs; verticesCount = attachment->uvsCount; triangles = attachment->triangles; trianglesCount = attachment->trianglesCount; r = attachment->r; g = attachment->g; b = attachment->b; a = attachment->a; break; } default: break; }// END switch (slot->attachment->type) if (texture) { if (slot->data->additiveBlending != additive) { cache->cacheTriangleDrawCall(); cache->blendFunc(GL_ONE, slot->data->additiveBlending ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA); additive = slot->data->additiveBlending; } color.a = mspSkeleton->a * slot->a * a * 255; float multiplier = mPremultipliedAlapha ? color.a : 255; color.r = mspSkeleton->r * slot->r * r * multiplier; color.g = mspSkeleton->g * slot->g * g * multiplier; color.b = mspSkeleton->b * slot->b * b * multiplier; cache->drawTriangles(skeletonRenderer->getGLTexture(texture, window()), mWorldVertices, uvs, verticesCount, triangles, trianglesCount, color); }// END if (texture) }// END for (int i = 0, n = skeleton->slotsCount; i < n; i++) cache->cacheTriangleDrawCall(); if (mDebugSlots || mDebugBones) { cache->bindShader(RenderCmdsCache::ShaderColor); if (mDebugSlots) { // Slots. cache->drawColor(0, 0, 255, 255); cache->lineWidth(1); Point points[4]; for (int i = 0, n = mspSkeleton->slotsCount; i < n; i++) { spSlot* slot = mspSkeleton->drawOrder[i]; if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue; spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment; spRegionAttachment_computeWorldVertices(attachment, slot->bone, mWorldVertices); points[0] = Point(mWorldVertices[0], mWorldVertices[1]); points[1] = Point(mWorldVertices[2], mWorldVertices[3]); points[2] = Point(mWorldVertices[4], mWorldVertices[5]); points[3] = Point(mWorldVertices[6], mWorldVertices[7]); cache->drawPoly(points, 4); } }// END if (mDebugSlots) if (mDebugBones) { // Bone lengths. cache->lineWidth(2); cache->drawColor(255, 0, 0, 255); for (int i = 0, n = mspSkeleton->bonesCount; i < n; i++) { spBone *bone = mspSkeleton->bones[i]; float x = bone->data->length * bone->m00 + bone->worldX; float y = bone->data->length * bone->m10 + bone->worldY; cache->drawLine(Point(bone->worldX, bone->worldY), Point(x, y)); } // Bone origins. cache->pointSize(4.0); cache->drawColor(0, 0, 255, 255); // Root bone is blue. for (int i = 0, n = mspSkeleton->bonesCount; i < n; i++) { spBone *bone = mspSkeleton->bones[i]; cache->drawPoint(Point(bone->worldX, bone->worldY)); if (i == 0) cache->drawColor(0, 255, 0, 255); } }// END if (mDebugBones) }//END if (mDebugSlots || mDebugBones) }