open source
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
@file JCWebGLPlus.cpp
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2019_8_24
|
||||
*/
|
||||
|
||||
#include "../JCWebGLPlus.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "../Log.h"
|
||||
#include "JSWebGLPlus.h"
|
||||
#include "JSArrayBufferRef.h"
|
||||
#include "JSKeyframeNode.h"
|
||||
#include "JSFloatKeyframe.h"
|
||||
#include "JSKeyframeNodeList.h"
|
||||
|
||||
namespace laya
|
||||
{
|
||||
void JCWebGLPlus::exportJS(void* ctx, void* object)
|
||||
{
|
||||
JSWebGLPlus::getInstance()->exportJS(*(v8::Local<v8::Object>*)object);
|
||||
JSArrayBufferRef::exportJS(*(v8::Local<v8::Object>*)object);
|
||||
JSFloatKeyframe::exportJS(*(v8::Local<v8::Object>*)object);
|
||||
JSFloatArrayKeyframe::exportJS(*(v8::Local<v8::Object>*)object);
|
||||
JSKeyframeNode::exportJS(*(v8::Local<v8::Object>*)object);
|
||||
JSKeyframeNodeList::exportJS(*(v8::Local<v8::Object>*)object);
|
||||
}
|
||||
void JCWebGLPlus::clean()
|
||||
{
|
||||
}
|
||||
void JCWebGLPlus::clearAll()
|
||||
{
|
||||
if (JSWebGLPlus::s_pWebGLPlus != NULL)
|
||||
{
|
||||
JSWebGLPlus::s_pWebGLPlus->persistentObject.Reset();
|
||||
}
|
||||
JSArrayBufferRef::persistentObjectTemplate.Reset();
|
||||
JSFloatKeyframe::persistentObjectTemplate.Reset();
|
||||
JSFloatArrayKeyframe::persistentObjectTemplate.Reset();
|
||||
JSKeyframeNode::persistentObjectTemplate.Reset();
|
||||
JSKeyframeNodeList::persistentObjectTemplate.Reset();
|
||||
|
||||
m_pJSArrayBufferManager->clearAll();
|
||||
m_pJSABManagerSyncToRender->clearAll();
|
||||
m_pRArrayBufferManager->clearAll();
|
||||
clean();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
@file JSArrayBufferRef.cpp
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2017_11_29
|
||||
*/
|
||||
|
||||
#include "JSArrayBufferRef.h"
|
||||
#include "../JCWebGLPlus.h"
|
||||
#include "V8Util.h"
|
||||
|
||||
namespace laya
|
||||
{
|
||||
v8::Persistent<v8::ObjectTemplate> JSArrayBufferRef::persistentObjectTemplate;
|
||||
JSArrayBufferRef::JSArrayBufferRef()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->push_back(this);
|
||||
}
|
||||
|
||||
m_nID = 0;
|
||||
m_bSyncToRender = false;
|
||||
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(128);
|
||||
}
|
||||
JSArrayBufferRef::~JSArrayBufferRef()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->delNode(this);
|
||||
}
|
||||
callManagerRemoveArrayBuffer();
|
||||
}
|
||||
void JSArrayBufferRef::callManagerRemoveArrayBuffer()
|
||||
{
|
||||
if (JCWebGLPlus::getInstance()->m_nThreadMODE == THREAD_MODE_DOUBLE)
|
||||
{
|
||||
if (m_bSyncToRender)
|
||||
{
|
||||
JCWebGLPlus::getInstance()->m_pJSABManagerSyncToRender->prepareRemoveArrayBuffer(m_nID);
|
||||
}
|
||||
else
|
||||
{
|
||||
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->removeArrayBuffer(m_nID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->removeArrayBuffer(m_nID);
|
||||
}
|
||||
}
|
||||
int JSArrayBufferRef::getID()
|
||||
{
|
||||
return m_nID;
|
||||
}
|
||||
bool JSArrayBufferRef::getIsSyncToRender()
|
||||
{
|
||||
return m_bSyncToRender;
|
||||
}
|
||||
static void _GetID(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSArrayBufferRef* self = (JSArrayBufferRef*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
int v = self->getID();
|
||||
info.GetReturnValue().Set(v8::Int32::New(isolate, v));
|
||||
}
|
||||
|
||||
static void IsSyncToRender(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSArrayBufferRef *pObj = (JSArrayBufferRef*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
bool value = pObj->getIsSyncToRender();
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, value));
|
||||
}
|
||||
void JSArrayBufferRef::WeakCallback(const v8::WeakCallbackInfo<JSArrayBufferRef>& data)
|
||||
{
|
||||
JSArrayBufferRef* wrap = data.GetParameter();
|
||||
wrap->persistentObject.Reset();
|
||||
delete wrap;
|
||||
}
|
||||
static void New(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
if (args.IsConstructCall())
|
||||
{
|
||||
JSArrayBufferRef* obj = new JSArrayBufferRef();
|
||||
args.This()->SetAlignedPointerInInternalField(0, obj);
|
||||
obj->persistentObject.Reset(isolate, args.This());
|
||||
obj->persistentObject.SetWeak(obj, JSArrayBufferRef::WeakCallback, v8::WeakCallbackType::kParameter);
|
||||
|
||||
args.GetReturnValue().Set(args.This());
|
||||
}
|
||||
}
|
||||
|
||||
void JSArrayBufferRef::exportJS(v8::Local<v8::Object> object)
|
||||
{
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope sc(isolate);
|
||||
v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate, New);
|
||||
functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "ArrayBufferRef", v8::NewStringType::kNormal).ToLocalChecked());
|
||||
v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate();
|
||||
persistentObjectTemplate.Reset(isolate, instanceTemplate);
|
||||
instanceTemplate->SetInternalFieldCount(1);
|
||||
instanceTemplate->SetAccessor(v8::String::NewFromUtf8(isolate, "id"), _GetID, 0, v8::Local<v8::Value>(), v8::DEFAULT, v8::ReadOnly);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "isSyncToRender", IsSyncToRender);
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
object->Set(v8::String::NewFromUtf8(isolate, "ArrayBufferRef"), functionTemplate->GetFunction(context).ToLocalChecked());
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
@file JSArrayBufferRef.h
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2017_11_29
|
||||
*/
|
||||
|
||||
#ifndef __JSArrayBufferRef_H__
|
||||
#define __JSArrayBufferRef_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../JSObjBase.h"
|
||||
#include <v8.h>
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
namespace laya
|
||||
{
|
||||
class JSArrayBufferRef : public JCListNode
|
||||
{
|
||||
public:
|
||||
|
||||
static void exportJS(v8::Local<v8::Object> object);
|
||||
|
||||
JSArrayBufferRef();
|
||||
|
||||
~JSArrayBufferRef();
|
||||
|
||||
void callManagerRemoveArrayBuffer();
|
||||
|
||||
int getID();
|
||||
|
||||
bool getIsSyncToRender();
|
||||
|
||||
public:
|
||||
|
||||
int m_nID;
|
||||
bool m_bSyncToRender;
|
||||
|
||||
public:
|
||||
static void WeakCallback(const v8::WeakCallbackInfo<JSArrayBufferRef>& data);
|
||||
v8::Persistent<v8::Object> persistentObject;
|
||||
static v8::Persistent<v8::ObjectTemplate> persistentObjectTemplate;
|
||||
};
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //__JSArrayBufferRef_H__
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
@file JSFloatArrayKeyframe.cpp
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2018_7_12
|
||||
*/
|
||||
|
||||
#include "JSFloatArrayKeyframe.h"
|
||||
#include <v8.h>
|
||||
#define NDEBUG
|
||||
#include <assert.h>
|
||||
#include "V8Util.h"
|
||||
|
||||
namespace laya
|
||||
{
|
||||
v8::Persistent<v8::ObjectTemplate> JSFloatArrayKeyframe::persistentObjectTemplate;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
JSFloatArrayKeyframe::JSFloatArrayKeyframe()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->push_back(this);
|
||||
}
|
||||
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(1024);
|
||||
//JCMemorySurvey::GetInstance()->newClass("conchFloatArrayKeyframe", 1024, this);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
JSFloatArrayKeyframe::~JSFloatArrayKeyframe()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->delNode(this);
|
||||
}
|
||||
|
||||
//JCMemorySurvey::GetInstance()->releaseClass("conchFloatArrayKeyframe", this);
|
||||
}
|
||||
static void SetInTangent(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char* pArrayBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(args[0], pArrayBuffer, nABLen);
|
||||
if (bIsArrayBuffer)
|
||||
{
|
||||
pObj->m_nInTangent.data = pArrayBuffer;
|
||||
pObj->m_nInTangent.byteSize = nABLen;
|
||||
}
|
||||
}
|
||||
|
||||
static void SetOutTangent(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char* pArrayBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(args[0], pArrayBuffer, nABLen);
|
||||
if (bIsArrayBuffer)
|
||||
{
|
||||
pObj->m_nOutTangent.data = pArrayBuffer;
|
||||
pObj->m_nOutTangent.byteSize = nABLen;
|
||||
}
|
||||
}
|
||||
|
||||
static void SetValue(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char* pArrayBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(args[0], pArrayBuffer, nABLen);
|
||||
if (bIsArrayBuffer)
|
||||
{
|
||||
pObj->m_nValue.data = pArrayBuffer;
|
||||
pObj->m_nValue.byteSize = nABLen;
|
||||
}
|
||||
}
|
||||
static void SetData(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char* pArrayBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(args[0], pArrayBuffer, nABLen);
|
||||
if (bIsArrayBuffer)
|
||||
{
|
||||
pObj->m_pData.data = pArrayBuffer;
|
||||
pObj->m_pData.byteSize = nABLen;
|
||||
}
|
||||
}
|
||||
|
||||
static void SetTime(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
assert(args[0]->IsNumber());
|
||||
float value = args[0]->NumberValue();
|
||||
pObj->setTime(value);
|
||||
}
|
||||
|
||||
static void GetTime(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
float value = pObj->getTime();
|
||||
args.GetReturnValue().Set(v8::Number::New(isolate, value));
|
||||
}
|
||||
static void WeakCallback(const v8::WeakCallbackInfo<JSFloatArrayKeyframe>& data) {
|
||||
JSFloatArrayKeyframe* wrap = data.GetParameter();
|
||||
wrap->persistentObject.Reset();
|
||||
delete wrap;
|
||||
}
|
||||
|
||||
static void New(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
if (args.IsConstructCall())
|
||||
{
|
||||
JSFloatArrayKeyframe* obj = new JSFloatArrayKeyframe();
|
||||
|
||||
args.This()->SetAlignedPointerInInternalField(0, obj);
|
||||
obj->persistentObject.Reset(isolate, args.This());
|
||||
obj->persistentObject.SetWeak(obj, WeakCallback, v8::WeakCallbackType::kParameter);
|
||||
|
||||
args.GetReturnValue().Set(args.This());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JSFloatArrayKeyframe::exportJS(v8::Local<v8::Object> object)
|
||||
{
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope sc(isolate);
|
||||
v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate, New);
|
||||
functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "_conchFloatArrayKeyframe", v8::NewStringType::kNormal).ToLocalChecked());
|
||||
functionTemplate->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
persistentObjectTemplate.Reset(isolate, functionTemplate->InstanceTemplate());
|
||||
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "setTime", SetTime);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getTime", GetTime);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "setInTangent", SetInTangent);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "setOutTangent", SetOutTangent);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "setValue", SetValue);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "setData", SetData);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
object->Set(v8::String::NewFromUtf8(isolate, "_conchFloatArrayKeyframe"), functionTemplate->GetFunction(context).ToLocalChecked());
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
@file JSFloatArrayKeyframe.h
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2018_7_12
|
||||
*/
|
||||
|
||||
#ifndef __JSFloatArrayKeyframe_H__
|
||||
#define __JSFloatArrayKeyframe_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "../JSObjBase.h"
|
||||
#include "../Animation/JCFloatArrayKeyframe.h"
|
||||
#include <v8.h>
|
||||
|
||||
namespace laya
|
||||
{
|
||||
class JSFloatArrayKeyframe : public JCFloatArrayKeyframe, public JCListNode
|
||||
{
|
||||
public:
|
||||
|
||||
static void exportJS(v8::Local<v8::Object> object);
|
||||
|
||||
JSFloatArrayKeyframe();
|
||||
|
||||
~JSFloatArrayKeyframe();
|
||||
|
||||
public:
|
||||
|
||||
v8::Persistent<v8::Object> persistentObject;
|
||||
|
||||
static v8::Persistent<v8::ObjectTemplate> persistentObjectTemplate;
|
||||
|
||||
};
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //__JSFloatArrayKeyframe_H__
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,205 @@
|
||||
/**
|
||||
@file JSFloatKeyframe.cpp
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2018_7_12
|
||||
*/
|
||||
|
||||
#include "JSFloatKeyframe.h"
|
||||
#define NDEBUG
|
||||
#include <assert.h>
|
||||
#include "V8Util.h"
|
||||
|
||||
namespace laya
|
||||
{
|
||||
v8::Persistent<v8::ObjectTemplate> JSFloatKeyframe::persistentObjectTemplate;
|
||||
//------------------------------------------------------------------------------
|
||||
JSFloatKeyframe::JSFloatKeyframe()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->push_back(this);
|
||||
}
|
||||
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(16);
|
||||
//JCMemorySurvey::GetInstance()->newClass("conchFloatKeyframe", 16, this);
|
||||
}
|
||||
JSFloatKeyframe::~JSFloatKeyframe()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->delNode(this);
|
||||
}
|
||||
//JCMemorySurvey::GetInstance()->releaseClass("conchFloatKeyframe", this);
|
||||
}
|
||||
void JSFloatKeyframe::WeakCallback(const v8::WeakCallbackInfo<JSFloatKeyframe>& data) {
|
||||
JSFloatKeyframe* wrap = data.GetParameter();
|
||||
wrap->persistentObject.Reset();
|
||||
delete wrap;
|
||||
}
|
||||
|
||||
static void New(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
if (args.IsConstructCall())
|
||||
{
|
||||
JSFloatKeyframe* obj = new JSFloatKeyframe();
|
||||
|
||||
args.This()->SetAlignedPointerInInternalField(0, obj);
|
||||
obj->persistentObject.Reset(isolate, args.This());
|
||||
obj->persistentObject.SetWeak(obj, JSFloatKeyframe::WeakCallback, v8::WeakCallbackType::kParameter);
|
||||
|
||||
args.GetReturnValue().Set(args.This());
|
||||
}
|
||||
}
|
||||
|
||||
static void Clone(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSFloatKeyframe *self = (JSFloatKeyframe*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
JSFloatKeyframe* pKeyframe = new JSFloatKeyframe();
|
||||
self->_cloneTo(pKeyframe);
|
||||
|
||||
|
||||
v8::Local<v8::ObjectTemplate> objectTemplate = v8::Local<v8::ObjectTemplate>::New(isolate, JSFloatKeyframe::persistentObjectTemplate);
|
||||
v8::Local<v8::Object> pNewIns = objectTemplate->NewInstance();
|
||||
pNewIns->SetAlignedPointerInInternalField(0, pKeyframe);
|
||||
pKeyframe->persistentObject.Reset(isolate, pNewIns);
|
||||
pKeyframe->persistentObject.SetWeak(pKeyframe, JSFloatKeyframe::WeakCallback, v8::WeakCallbackType::kParameter);
|
||||
args.GetReturnValue().Set(pNewIns);
|
||||
}
|
||||
static void CloneTo(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
|
||||
JSFloatKeyframe* self = (JSFloatKeyframe*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
v8::Local<v8::Value> destObj = args[0];
|
||||
|
||||
if (!destObj.IsEmpty() && destObj->IsObject())
|
||||
{
|
||||
JSFloatKeyframe* pKeyFrame = (JSFloatKeyframe*)destObj.As<v8::Object>()->GetAlignedPointerFromInternalField(0);
|
||||
if (pKeyFrame)
|
||||
{
|
||||
self->_cloneTo(pKeyFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void _GetTime(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSFloatKeyframe* self = (JSFloatKeyframe*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
float v = self->getTime();
|
||||
info.GetReturnValue().Set(v8::Number::New(isolate, v));
|
||||
}
|
||||
static void _SetTime(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSFloatKeyframe* self = (JSFloatKeyframe*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsNumber());
|
||||
float v = value->NumberValue();
|
||||
self->setTime(v);
|
||||
}
|
||||
static void _GetInTangent(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSFloatKeyframe* self = (JSFloatKeyframe*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
float v = self->getInTangent();
|
||||
info.GetReturnValue().Set(v8::Number::New(isolate, v));
|
||||
}
|
||||
|
||||
static void _SetInTangent(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSFloatKeyframe* self = (JSFloatKeyframe*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsNumber());
|
||||
float v = value->NumberValue();
|
||||
self->setInTangent(v);
|
||||
}
|
||||
static void _GetOutTangent(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSFloatKeyframe* self = (JSFloatKeyframe*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
float v = self->getOutTangent();
|
||||
info.GetReturnValue().Set(v8::Number::New(isolate, v));
|
||||
}
|
||||
static void _SetOutTangent(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSFloatKeyframe* self = (JSFloatKeyframe*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsNumber());
|
||||
float v = value->NumberValue();
|
||||
self->setOutTangent(v);
|
||||
}
|
||||
static void _GetValue(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSFloatKeyframe* self = (JSFloatKeyframe*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
float v = self->getValue();
|
||||
info.GetReturnValue().Set(v8::Number::New(isolate, v));
|
||||
}
|
||||
static void _SetValue(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSFloatKeyframe* self = (JSFloatKeyframe*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsNumber());
|
||||
float v = value->NumberValue();
|
||||
self->setValue(v);
|
||||
}
|
||||
void JSFloatKeyframe::exportJS(v8::Local<v8::Object> object)
|
||||
{
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope sc(isolate);
|
||||
v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate, New);
|
||||
functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "conchFloatKeyframe", v8::NewStringType::kNormal).ToLocalChecked());
|
||||
functionTemplate->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
persistentObjectTemplate.Reset(isolate, functionTemplate->InstanceTemplate());
|
||||
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "time"), _GetTime, _SetTime);
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "inTangent"), _GetInTangent, _SetInTangent);
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "outTangent"), _GetOutTangent, _SetOutTangent);
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "value"), _GetValue, _SetValue);
|
||||
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "clone", Clone);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "cloneTo", CloneTo);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
object->Set(v8::String::NewFromUtf8(isolate, "conchFloatKeyframe"), functionTemplate->GetFunction(context).ToLocalChecked());
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
@file JSFloatKeyframe.h
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2018_7_12
|
||||
*/
|
||||
|
||||
#ifndef __JSFloatKeyframe_H__
|
||||
#define __JSFloatKeyframe_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "../Animation/JCKeyframeNode.h"
|
||||
#include "../JSObjBase.h"
|
||||
#include <v8.h>
|
||||
|
||||
namespace laya
|
||||
{
|
||||
|
||||
|
||||
class JSFloatKeyframe : public JCListNode, public JCFloatKeyframe
|
||||
{
|
||||
public:
|
||||
static void exportJS(v8::Local<v8::Object> object);
|
||||
|
||||
JSFloatKeyframe();
|
||||
|
||||
~JSFloatKeyframe();
|
||||
|
||||
static void WeakCallback(const v8::WeakCallbackInfo<JSFloatKeyframe>& data);
|
||||
|
||||
public:
|
||||
|
||||
v8::Persistent<v8::Object> persistentObject;
|
||||
|
||||
static v8::Persistent<v8::ObjectTemplate> persistentObjectTemplate;
|
||||
|
||||
};
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //__JSFloatKeyframe_H__
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,536 @@
|
||||
/**
|
||||
@file JSKeyframeNode.cpp
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2018_7_12
|
||||
*/
|
||||
|
||||
#include "JSKeyframeNode.h"
|
||||
#define NDEBUG
|
||||
#include <assert.h>
|
||||
#include "V8Util.h"
|
||||
|
||||
namespace laya
|
||||
{
|
||||
v8::Persistent<v8::ObjectTemplate> JSKeyframeNode::persistentObjectTemplate;
|
||||
std::string JCKeyframeNode::s_sTempString = "";
|
||||
//------------------------------------------------------------------------------
|
||||
JSKeyframeNode::JSKeyframeNode()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->push_back(this);
|
||||
}
|
||||
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(4096);
|
||||
//JCMemorySurvey::GetInstance()->newClass("JSKeyframeNode", 4096, this);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
JSKeyframeNode::~JSKeyframeNode()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->delNode(this);
|
||||
}
|
||||
//JCMemorySurvey::GetInstance()->releaseClass("JSKeyframeNode", this);
|
||||
}
|
||||
|
||||
static void SetFloat32ArrayData(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char* pArrayBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(args[0], pArrayBuffer, nABLen);
|
||||
if (bIsArrayBuffer)
|
||||
{
|
||||
self->m_pDataFloatArray.data = pArrayBuffer;
|
||||
self->m_pDataFloatArray.byteSize = nABLen;
|
||||
}
|
||||
}
|
||||
|
||||
static void SetOwnerPathCount(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
self->_setOwnerPathCount(index);
|
||||
}
|
||||
static void SetOwnerPathByIndex(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
assert(args[1]->IsString());
|
||||
v8::String::Utf8Value utf8str(args[1]->ToString());
|
||||
|
||||
self->_setOwnerPathByIndex(index, *utf8str);
|
||||
}
|
||||
static void JoinOwnerPath(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsString());
|
||||
v8::String::Utf8Value utf8str(args[0]->ToString());
|
||||
|
||||
const char* value = self->_joinOwnerPath(*utf8str);
|
||||
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, value));
|
||||
}
|
||||
static void SetPropertyCount(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
self->_setPropertyCount(index);
|
||||
}
|
||||
static void SetPropertyByIndex(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
assert(args[1]->IsString());
|
||||
v8::String::Utf8Value utf8str(args[1]->ToString());
|
||||
|
||||
self->_setPropertyByIndex(index, *utf8str);
|
||||
}
|
||||
static void JoinProperty(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsString());
|
||||
v8::String::Utf8Value utf8str(args[0]->ToString());
|
||||
|
||||
const char* value = self->_joinProperty(*utf8str);
|
||||
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, value));
|
||||
}
|
||||
static void SetKeyframeByIndex0(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
|
||||
v8::Local<v8::Value> keyframe = args[1];
|
||||
|
||||
if (!keyframe.IsEmpty() && keyframe->IsObject())
|
||||
{
|
||||
JSFloatKeyframe* pNode = (JSFloatKeyframe*)keyframe.As<v8::Object>()->GetAlignedPointerFromInternalField(0);
|
||||
if (pNode)
|
||||
{
|
||||
self->m_vKeyFrames[index] = pNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void SetKeyframeByIndex1(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
|
||||
v8::Local<v8::Value> keyframe = args[1];
|
||||
|
||||
if (!keyframe.IsEmpty() && keyframe->IsObject())
|
||||
{
|
||||
JSFloatArrayKeyframe* pNode = (JSFloatArrayKeyframe*)keyframe.As<v8::Object>()->GetAlignedPointerFromInternalField(0);
|
||||
if (pNode)
|
||||
{
|
||||
self->m_vKeyFrames[index] = pNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void SetKeyframeCount(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int value = args[0]->Int32Value();
|
||||
|
||||
self->_setKeyframeCount(value);
|
||||
}
|
||||
static void GetOwnerPathByIndex(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
return;
|
||||
}
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
|
||||
const char* value = self->getOwnerPathByIndex(index);
|
||||
|
||||
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, value));
|
||||
}
|
||||
static void GetPropertyByIndex(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
return;
|
||||
}
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
|
||||
const char* value = self->getPropertyByIndex(index);
|
||||
|
||||
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, value));
|
||||
}
|
||||
static void GetKeyframeByIndex(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
}
|
||||
static void GetFloatData(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode *pObj = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
float value = pObj->getFloatData();
|
||||
args.GetReturnValue().Set(v8::Number::New(isolate, value));
|
||||
}
|
||||
|
||||
static void GetDataType(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode *pObj = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int value = pObj->getDataType();
|
||||
args.GetReturnValue().Set(v8::Int32::New(v8::Isolate::GetCurrent(), value));
|
||||
}
|
||||
|
||||
void JSKeyframeNode::WeakCallback(const v8::WeakCallbackInfo<JSKeyframeNode>& data) {
|
||||
JSKeyframeNode* wrap = data.GetParameter();
|
||||
wrap->persistentObject.Reset();
|
||||
delete wrap;
|
||||
}
|
||||
|
||||
static void New(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
if (args.IsConstructCall())
|
||||
{
|
||||
JSKeyframeNode* obj = new JSKeyframeNode();
|
||||
|
||||
args.This()->SetAlignedPointerInInternalField(0, obj);
|
||||
obj->persistentObject.Reset(isolate, args.This());
|
||||
obj->persistentObject.SetWeak(obj, JSKeyframeNode::WeakCallback, v8::WeakCallbackType::kParameter);
|
||||
|
||||
args.GetReturnValue().Set(args.This());
|
||||
}
|
||||
}
|
||||
|
||||
static void GetKeyFramesCount(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int value = self->getKeyFramesCount();
|
||||
args.GetReturnValue().Set(v8::Int32::New(isolate, value));
|
||||
}
|
||||
static void GetOwnerPathCount(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int value = self->getOwnerPathCount();
|
||||
args.GetReturnValue().Set(v8::Int32::New(isolate, value));
|
||||
}
|
||||
static void GetPropertyCount(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
laya::JSKeyframeNode* self = (JSKeyframeNode*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int value = self->getPropertyCount();
|
||||
args.GetReturnValue().Set(v8::Int32::New(isolate, value));
|
||||
}
|
||||
static void _GetIndexInList(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
int v = self->getIndexInList();
|
||||
info.GetReturnValue().Set(v8::Int32::New(isolate, v));
|
||||
}
|
||||
static void _SetIndexInList(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsInt32());
|
||||
int v = value->Int32Value();
|
||||
self->setIndexInList(v);
|
||||
}
|
||||
static void _GetType(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
int v = self->getType();
|
||||
info.GetReturnValue().Set(v8::Int32::New(isolate, v));
|
||||
}
|
||||
static void _SetType(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsInt32());
|
||||
int v = value->Int32Value();
|
||||
self->setType(v);
|
||||
}
|
||||
static void _GetOwnerPathCount(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
int v = self->getOwnerPathCount();
|
||||
info.GetReturnValue().Set(v8::Int32::New(isolate, v));
|
||||
}
|
||||
static void _SetOwnerPathCount(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsInt32());
|
||||
int v = value->Int32Value();
|
||||
self->_setOwnerPathCount(v);
|
||||
}
|
||||
static void _GetKeyFramesCount(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
int v = self->getKeyFramesCount();
|
||||
info.GetReturnValue().Set(v8::Int32::New(isolate, v));
|
||||
}
|
||||
static void _SetKeyframeCount(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsInt32());
|
||||
int v = value->Int32Value();
|
||||
self->_setKeyframeCount(v);
|
||||
}
|
||||
static void _GetPropertyCount(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
int v = self->getPropertyCount();
|
||||
info.GetReturnValue().Set(v8::Int32::New(isolate, v));
|
||||
}
|
||||
static void _SetPropertyCount(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsInt32());
|
||||
int v = value->Int32Value();
|
||||
self->_setPropertyCount(v);
|
||||
}
|
||||
static void _GetPropertyOwner(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
const char* v = self->getPropertyOwner();
|
||||
info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, v));
|
||||
}
|
||||
static void _SetPropertyOwner(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsString());
|
||||
v8::String::Utf8Value utf8str(value->ToString());
|
||||
self->setPropertyOwner(*utf8str);
|
||||
}
|
||||
static void _GetFullPath(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
const char* v = self->getFullPath();
|
||||
info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, v));
|
||||
}
|
||||
static void _SetFullPath(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
{
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = info.This();
|
||||
JSKeyframeNode* self = (JSKeyframeNode*)pthis->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
assert(value->IsString());
|
||||
v8::String::Utf8Value utf8str(value->ToString());
|
||||
self->setFullPath(*utf8str);
|
||||
}
|
||||
void JSKeyframeNode::exportJS(v8::Local<v8::Object> object)
|
||||
{
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope sc(isolate);
|
||||
v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate, New);
|
||||
functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "_conchKeyframeNode", v8::NewStringType::kNormal).ToLocalChecked());
|
||||
functionTemplate->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
persistentObjectTemplate.Reset(isolate, functionTemplate->InstanceTemplate());
|
||||
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "_indexInList"), _GetIndexInList, _SetIndexInList);
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "type"), _GetType, _SetType);
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "fullPath"), _GetFullPath, _SetFullPath);
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "propertyOwner"), _GetPropertyOwner, _SetPropertyOwner);
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "ownerPathCount"), _GetOwnerPathCount, _SetOwnerPathCount);
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "keyFramesCount"), _GetKeyFramesCount, _SetKeyframeCount);
|
||||
functionTemplate->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "propertyCount"), _GetPropertyCount, _SetPropertyCount);
|
||||
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getOwnerPathCount", GetOwnerPathCount);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getPropertyCount", GetPropertyCount);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getKeyFramesCount", GetKeyFramesCount);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "_setOwnerPathCount", SetOwnerPathCount);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "_setOwnerPathByIndex", SetOwnerPathByIndex);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "_joinOwnerPath", JoinOwnerPath);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "_setPropertyCount", SetPropertyCount);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "_setPropertyByIndex", SetPropertyByIndex);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "_joinProperty", JoinProperty);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "_setKeyframeCount", SetKeyframeCount);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "_setKeyframeByIndex0", SetKeyframeByIndex0);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "_setKeyframeByIndex1", SetKeyframeByIndex1);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getOwnerPathByIndex", GetOwnerPathByIndex);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getPropertyByIndex", GetPropertyByIndex);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getKeyframeByIndex", GetKeyframeByIndex);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getDataType", GetDataType);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getFloatData", GetFloatData);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "setFloat32ArrayData", SetFloat32ArrayData);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
object->Set(v8::String::NewFromUtf8(isolate, "_conchKeyframeNode"), functionTemplate->GetFunction(context).ToLocalChecked());
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
@file JSKeyframeNode.h
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2018_7_12
|
||||
*/
|
||||
|
||||
#ifndef __JSKeyframeNode_H__
|
||||
#define __JSKeyframeNode_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "../JSObjBase.h"
|
||||
#include <vector>
|
||||
#include "JSFloatKeyframe.h"
|
||||
#include "JSFloatArrayKeyframe.h"
|
||||
#include <v8.h>
|
||||
#include "../Animation/JCKeyframeNode.h"
|
||||
|
||||
namespace laya
|
||||
{
|
||||
class JSKeyframeNode : public JCListNode, public JCKeyframeNode
|
||||
{
|
||||
public:
|
||||
|
||||
static void exportJS(v8::Local<v8::Object> object);
|
||||
|
||||
JSKeyframeNode();
|
||||
|
||||
~JSKeyframeNode();
|
||||
|
||||
public:
|
||||
|
||||
static void WeakCallback(const v8::WeakCallbackInfo<JSKeyframeNode>& data);
|
||||
|
||||
v8::Persistent<v8::Object> persistentObject;
|
||||
|
||||
static v8::Persistent<v8::ObjectTemplate> persistentObjectTemplate;
|
||||
|
||||
};
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //__JSKeyframeNode_H__
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
@file JSKeyframeNodeList.cpp
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2018_7_12
|
||||
*/
|
||||
|
||||
#include "JSKeyframeNodeList.h"
|
||||
#include <v8.h>
|
||||
#define NDEBUG
|
||||
#include <assert.h>
|
||||
#include "V8Util.h"
|
||||
|
||||
namespace laya
|
||||
{
|
||||
v8::Persistent<v8::ObjectTemplate> JSKeyframeNodeList::persistentObjectTemplate;
|
||||
//------------------------------------------------------------------------------
|
||||
JSKeyframeNodeList::JSKeyframeNodeList()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->push_back(this);
|
||||
}
|
||||
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(8192);
|
||||
//JCMemorySurvey::GetInstance()->newClass("JSKeyframeNodeList", 8192, this);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
JSKeyframeNodeList::~JSKeyframeNodeList()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->delNode(this);
|
||||
}
|
||||
//JCMemorySurvey::GetInstance()->releaseClass("JSKeyframeNodeList", this);
|
||||
}
|
||||
|
||||
static void SetCount(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
laya::JSKeyframeNodeList *pObj = (laya::JSKeyframeNodeList*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
assert(args[0]->IsInt32());
|
||||
int value = args[0]->Int32Value();
|
||||
pObj->setCount(value);
|
||||
}
|
||||
|
||||
static void GetCount(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
laya::JSKeyframeNodeList *pObj = (laya::JSKeyframeNodeList*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int value = pObj->getCount();
|
||||
args.GetReturnValue().Set(v8::Int32::New(v8::Isolate::GetCurrent(), value));
|
||||
}
|
||||
|
||||
static void GetNodeByIndex(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 1)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
laya::JSKeyframeNodeList* self = (laya::JSKeyframeNodeList*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
|
||||
JSKeyframeNode* pNode = (JSKeyframeNode*)self->m_vNodes[index];
|
||||
v8::Local<v8::ObjectTemplate> objectTemplate = v8::Local<v8::ObjectTemplate>::New(isolate, JSKeyframeNode::persistentObjectTemplate);
|
||||
v8::Local<v8::Object> pNewIns = objectTemplate->NewInstance();
|
||||
pNewIns->SetAlignedPointerInInternalField(0, pNode);
|
||||
pNode->persistentObject.Reset(isolate, pNewIns);
|
||||
pNode->persistentObject.SetWeak(pNode, JSKeyframeNode::WeakCallback, v8::WeakCallbackType::kInternalFields);
|
||||
}
|
||||
|
||||
static void SetNodeByIndex(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local< v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 2)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSKeyframeNodeList* self = (JSKeyframeNodeList*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int index = args[0]->Int32Value();
|
||||
|
||||
v8::Local<v8::Value> keyframeNode = args[1];
|
||||
|
||||
if (!keyframeNode.IsEmpty() && keyframeNode->IsObject())
|
||||
{
|
||||
JSKeyframeNode* pNode = (JSKeyframeNode*)keyframeNode.As<v8::Object>()->GetAlignedPointerFromInternalField(0);
|
||||
if (pNode)
|
||||
{
|
||||
self->m_vNodes[index] = pNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void WeakCallback(const v8::WeakCallbackInfo<JSKeyframeNodeList>& data) {
|
||||
JSKeyframeNodeList* wrap = data.GetParameter();
|
||||
wrap->persistentObject.Reset();
|
||||
delete wrap;
|
||||
}
|
||||
|
||||
static void New(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
if (args.IsConstructCall())
|
||||
{
|
||||
JSKeyframeNodeList* obj = new JSKeyframeNodeList();
|
||||
|
||||
args.This()->SetAlignedPointerInInternalField(0, obj);
|
||||
obj->persistentObject.Reset(isolate, args.This());
|
||||
obj->persistentObject.SetWeak(obj, WeakCallback, v8::WeakCallbackType::kParameter);
|
||||
|
||||
args.GetReturnValue().Set(args.This());
|
||||
}
|
||||
}
|
||||
|
||||
void JSKeyframeNodeList::exportJS(v8::Local<v8::Object> object)
|
||||
{
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope sc(isolate);
|
||||
v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate, New);
|
||||
functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "_conchKeyframeNodeList", v8::NewStringType::kNormal).ToLocalChecked());
|
||||
functionTemplate->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "setNodeByIndex", SetNodeByIndex);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getNodeByIndex", GetNodeByIndex);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "getCount", GetCount);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "setCount", SetCount);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
object->Set(v8::String::NewFromUtf8(isolate, "_conchKeyframeNodeList"), functionTemplate->GetFunction(context).ToLocalChecked());
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
@file JSKeyframeNodeList.h
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2018_7_12
|
||||
*/
|
||||
|
||||
#ifndef __JSKeyframeNodeList_H__
|
||||
#define __JSKeyframeNodeList_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "../JSObjBase.h"
|
||||
#include "JSKeyframeNode.h"
|
||||
#include <vector>
|
||||
#include <v8.h>
|
||||
#include "../Animation/JCKeyframeNodeList.h"
|
||||
|
||||
namespace laya
|
||||
{
|
||||
class JSKeyframeNodeList : public JCListNode, public JCKeyframeNodeList
|
||||
{
|
||||
public:
|
||||
|
||||
static void exportJS(v8::Local<v8::Object> object);
|
||||
|
||||
JSKeyframeNodeList();
|
||||
|
||||
~JSKeyframeNodeList();
|
||||
|
||||
public:
|
||||
|
||||
v8::Persistent<v8::Object> persistentObject;
|
||||
|
||||
static v8::Persistent<v8::ObjectTemplate> persistentObjectTemplate;
|
||||
|
||||
};
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //__JSKeyframeNodeList_H__
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,589 @@
|
||||
/**
|
||||
@file JSWebGLPlus.cpp
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2019_8_24
|
||||
*/
|
||||
|
||||
#include "JSWebGLPlus.h"
|
||||
#include "../JCWebGLPlus.h"
|
||||
#include "JSArrayBufferRef.h"
|
||||
#include "JSKeyframeNodeList.h"
|
||||
#include "../Log.h"
|
||||
#define NDEBUG
|
||||
#include <assert.h>
|
||||
#include "V8Util.h"
|
||||
//------------------------------------------------------------------------------
|
||||
namespace laya
|
||||
{
|
||||
JSWebGLPlus* JSWebGLPlus::s_pWebGLPlus = NULL;
|
||||
JSWebGLPlus::JSWebGLPlus()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->push_back(this);
|
||||
}
|
||||
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(8192);
|
||||
//JCMemorySurvey::GetInstance()->newClass("webglPlus", 8192, this);
|
||||
}
|
||||
JSWebGLPlus::~JSWebGLPlus()
|
||||
{
|
||||
if (JSObjNode::s_pListJSObj)
|
||||
{
|
||||
JSObjNode::s_pListJSObj->delNode(this);
|
||||
}
|
||||
persistentObject.Reset();
|
||||
s_pWebGLPlus = NULL;
|
||||
//JCMemorySurvey::GetInstance()->releaseClass("webglPlus", this);
|
||||
}
|
||||
JSWebGLPlus* JSWebGLPlus::getInstance()
|
||||
{
|
||||
if (s_pWebGLPlus == NULL)
|
||||
{
|
||||
s_pWebGLPlus = new JSWebGLPlus();
|
||||
}
|
||||
return s_pWebGLPlus;
|
||||
}
|
||||
|
||||
|
||||
static void Culling(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus Culling");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 4)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Int32::New(isolate, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> boundFrustumBuffer = args[0];
|
||||
v8::Local<v8::Value> cullingBuffer = args[1];
|
||||
v8::Local<v8::Value> cullingBufferIndices = args[2];
|
||||
assert(args[3]->IsNumber());
|
||||
int cullingCount = args[3]->Int32Value();
|
||||
v8::Local<v8::Value> cullingBufferResult = args[4];
|
||||
|
||||
char* pFrustumBuffer;
|
||||
char* pCullingBuffer;
|
||||
char* pCullingBufferIndices;
|
||||
char* pCullingBufferResult;
|
||||
int nFrustumLen = 0;
|
||||
int nCullingBufferLen = 0;
|
||||
int nCullingBufferIndicesLen = 0;
|
||||
int nCullingBufferResultLen = 0;
|
||||
|
||||
if (V8Util::extractJSAB(boundFrustumBuffer, pFrustumBuffer, nFrustumLen) == false)
|
||||
{
|
||||
LOGE("culling culling frustum error");
|
||||
args.GetReturnValue().Set(v8::Int32::New(isolate, 0));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(cullingBuffer, pCullingBuffer, nCullingBufferLen) == false)
|
||||
{
|
||||
LOGE("culling culling buffer error");
|
||||
args.GetReturnValue().Set(v8::Int32::New(isolate, 0));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(cullingBufferIndices, pCullingBufferIndices, nCullingBufferIndicesLen) == false)
|
||||
{
|
||||
LOGE("culling culling buffer indices error");
|
||||
args.GetReturnValue().Set(v8::Int32::New(isolate, 0));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(cullingBufferResult, pCullingBufferResult, nCullingBufferResultLen) == false)
|
||||
{
|
||||
LOGE("culling result error");
|
||||
args.GetReturnValue().Set(v8::Int32::New(isolate, 0));
|
||||
return;
|
||||
}
|
||||
int count = JCWebGLPlus::getInstance()->culling3D(cullingCount, pFrustumBuffer, nFrustumLen, pCullingBuffer, nCullingBufferLen, pCullingBufferIndices, nCullingBufferIndicesLen, pCullingBufferResult, nCullingBufferResultLen);
|
||||
args.GetReturnValue().Set(v8::Int32::New(isolate, count));
|
||||
}
|
||||
|
||||
static void UpdateAnimationNodeWorldMatix(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus UpdateAnimationNodeWorldMatix");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 5)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
v8::Local<v8::Value> locPosition = args[0];
|
||||
v8::Local<v8::Value> locRotation = args[1];
|
||||
v8::Local<v8::Value> locScaling = args[2];
|
||||
v8::Local<v8::Value> parentIndices = args[3];
|
||||
v8::Local<v8::Value> outWorldMatrix = args[4];
|
||||
|
||||
|
||||
char* pLocPosition;
|
||||
char* pLocRotation;
|
||||
char* pLocScaling;
|
||||
char* pParentIndices;
|
||||
char* pOutWorldMatrix;
|
||||
int nLocPosLen = 0;
|
||||
int nLocRotLen = 0;
|
||||
int nLocScaLen = 0;
|
||||
int nLocParentLen = 0;
|
||||
int nOutWorldLen = 0;
|
||||
if (V8Util::extractJSAB(locPosition, pLocPosition, nLocPosLen) == false)
|
||||
{
|
||||
LOGE("updateAnimationNodeWorldMatix postion error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(locRotation, pLocRotation, nLocRotLen) == false)
|
||||
{
|
||||
LOGE("updateAnimationNodeWorldMatix rotateion error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(locScaling, pLocScaling, nLocScaLen) == false)
|
||||
{
|
||||
LOGE("updateAnimationNodeWorldMatix scaling error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(parentIndices, pParentIndices, nLocParentLen) == false)
|
||||
{
|
||||
LOGE("updateAnimationNodeWorldMatix parent index error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(outWorldMatrix, pOutWorldMatrix, nOutWorldLen) == false)
|
||||
{
|
||||
LOGE("updateAnimationNodeWorldMatix world marix error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
bool value = JCWebGLPlus::getInstance()->updateAnimationNodeWorldMatix3D(pLocPosition, nLocPosLen, pLocRotation, nLocRotLen, pLocScaling, nLocScaLen,
|
||||
pParentIndices, nLocParentLen, pOutWorldMatrix, nOutWorldLen);
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, value));
|
||||
}
|
||||
|
||||
static void ComputeSubSkinnedData(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus ComputeSubSkinnedData");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 6)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> worldMatrixs = args[0];
|
||||
v8::Local<v8::Value> worldMatrixIndex = args[1];
|
||||
v8::Local<v8::Value> inverseBindPoses = args[2];
|
||||
v8::Local<v8::Value> boneIndices = args[3];
|
||||
v8::Local<v8::Value> bindPoseInices = args[4];
|
||||
v8::Local<v8::Value> resultData = args[5];
|
||||
|
||||
|
||||
char* pWorldMatrixs;
|
||||
char* pWorldMatrixIndex;
|
||||
char* pInverseBindPoses;
|
||||
char* pBoneIndices;
|
||||
char* pBindPoseIndices;
|
||||
char* pResultData;
|
||||
int nWorldMatLen = 0;
|
||||
int nWorldMatIndeLen = 0;
|
||||
int nInverseBindPosesLen = 0;
|
||||
int nBoneIndicesLen = 0;
|
||||
int nBindPoseIndicesLen = 0;
|
||||
int nResultDataLen = 0;
|
||||
if (V8Util::extractJSAB(worldMatrixs, pWorldMatrixs, nWorldMatLen) == false)
|
||||
{
|
||||
LOGE("computeSubSkinnedDataNative world matrix error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(worldMatrixIndex, pWorldMatrixIndex, nWorldMatIndeLen) == false)
|
||||
{
|
||||
LOGE("computeSubSkinnedDataNative world matrix index error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(inverseBindPoses, pInverseBindPoses, nInverseBindPosesLen) == false)
|
||||
{
|
||||
LOGE("computeSubSkinnedDataNative inverse bind poses error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(boneIndices, pBoneIndices, nBoneIndicesLen) == false)
|
||||
{
|
||||
LOGE("computeSubSkinnedDataNative bone indices error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(bindPoseInices, pBindPoseIndices, nBindPoseIndicesLen) == false)
|
||||
{
|
||||
LOGE("computeSubSkinnedDataNative bind pose indices error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
if (V8Util::extractJSAB(resultData, pResultData, nResultDataLen) == false)
|
||||
{
|
||||
LOGE("computeSubSkinnedDataNative data error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
bool value = JCWebGLPlus::getInstance()->computeSubSkinnedData3D(pWorldMatrixs, nWorldMatLen, pWorldMatrixIndex, nWorldMatIndeLen,
|
||||
pInverseBindPoses, nInverseBindPosesLen, pBoneIndices, nBoneIndicesLen,
|
||||
pBindPoseIndices, nBindPoseIndicesLen, pResultData, nResultDataLen);
|
||||
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, value));
|
||||
}
|
||||
|
||||
static void CreateArrayBufferRef(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus CreateArrayBufferRef");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
|
||||
int len = args.Length();
|
||||
if (len < 4)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> pArrayBuffer = args[0];
|
||||
assert(args[1]->IsInt32());
|
||||
int nType = args[1]->Int32Value();
|
||||
assert(args[2]->IsBoolean());
|
||||
bool bSyncToRender = args[2]->BooleanValue();
|
||||
assert(args[3]->IsInt32());
|
||||
int nRefType = args[3]->Int32Value();
|
||||
|
||||
|
||||
char* pBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(pArrayBuffer, pBuffer, nABLen);
|
||||
if (bIsArrayBuffer)
|
||||
{
|
||||
JSArrayBufferRef* pArrayBufferRef = new JSArrayBufferRef();
|
||||
pArrayBufferRef->m_bSyncToRender = bSyncToRender;
|
||||
if (JCWebGLPlus::getInstance()->m_nThreadMODE == THREAD_MODE_DOUBLE)
|
||||
{
|
||||
if (bSyncToRender)
|
||||
{
|
||||
pArrayBufferRef->m_nID = JCWebGLPlus::getInstance()->m_pJSABManagerSyncToRender->createArrayBuffer(pBuffer, nABLen, (JCArrayBufferManager::ARRAY_BUFFER_TYPE)nType, (JCArrayBufferManager::ARRAY_BUFFER_REF_TYPE)nRefType);
|
||||
}
|
||||
else
|
||||
{
|
||||
pArrayBufferRef->m_nID = JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->createArrayBuffer(pBuffer, nABLen, (JCArrayBufferManager::ARRAY_BUFFER_TYPE)nType, (JCArrayBufferManager::ARRAY_BUFFER_REF_TYPE)nRefType);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pArrayBufferRef->m_nID = JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->createArrayBuffer(pBuffer, nABLen, (JCArrayBufferManager::ARRAY_BUFFER_TYPE)nType, (JCArrayBufferManager::ARRAY_BUFFER_REF_TYPE)nRefType);
|
||||
}
|
||||
v8::Local<v8::ObjectTemplate> objectTemplate = v8::Local<v8::ObjectTemplate>::New(isolate, JSArrayBufferRef::persistentObjectTemplate);
|
||||
v8::Local<v8::Object> pNewIns = objectTemplate->NewInstance();
|
||||
pNewIns->SetAlignedPointerInInternalField(0, pArrayBufferRef);
|
||||
pArrayBufferRef->persistentObject.Reset(isolate, pNewIns);
|
||||
pArrayBufferRef->persistentObject.SetWeak(pArrayBufferRef, JSArrayBufferRef::WeakCallback, v8::WeakCallbackType::kParameter);
|
||||
args.GetReturnValue().Set(pNewIns);
|
||||
return;
|
||||
}
|
||||
LOGE("JSLayaGL::createArrayBufferRef type error");
|
||||
args.GetReturnValue().Set(v8::Null(isolate));
|
||||
}
|
||||
bool JSWebGLPlus::updateArrayBufferRef(int nID, bool bSyncToRender, v8::Local<v8::Value> pArrayBuffer)
|
||||
{
|
||||
char* pBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(pArrayBuffer, pBuffer, nABLen);
|
||||
if (bIsArrayBuffer)
|
||||
{
|
||||
if (JCWebGLPlus::getInstance()->m_nThreadMODE == THREAD_MODE_DOUBLE)
|
||||
{
|
||||
if (bSyncToRender)
|
||||
{
|
||||
JCWebGLPlus::getInstance()->m_pJSABManagerSyncToRender->updateArrayBuffer(nID, pBuffer, nABLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->updateArrayBuffer(nID, pBuffer, nABLen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->updateArrayBuffer(nID, pBuffer, nABLen);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
LOGE("JSLayaGL::updateArrayBufferRef type error");
|
||||
return false;
|
||||
}
|
||||
static void UpdateArrayBufferRef(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus UpdateArrayBufferRef");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
JSWebGLPlus* self = (JSWebGLPlus*)(pthis->GetAlignedPointerFromInternalField(0));
|
||||
int len = args.Length();
|
||||
if (len < 3)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int nID = args[0]->Int32Value();
|
||||
assert(args[1]->IsBoolean());
|
||||
bool bSyncToRender = args[1]->BooleanValue();
|
||||
v8::Local<v8::Value> pArrayBuffer = args[2];
|
||||
bool value = self->updateArrayBufferRef(nID, bSyncToRender, pArrayBuffer);
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, value));
|
||||
}
|
||||
|
||||
static void SyncArrayBufferDataToRuntime(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus SyncArrayBufferDataToRuntime");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 3)
|
||||
{
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
return;
|
||||
}
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int nID = args[0]->Int32Value();
|
||||
assert(args[1]->IsBoolean());
|
||||
bool bSyncToRender = args[1]->BooleanValue();
|
||||
v8::Local<v8::Value> pArrayBuffer = args[2];
|
||||
|
||||
char* pBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(pArrayBuffer, pBuffer, nABLen);
|
||||
if (bIsArrayBuffer)
|
||||
{
|
||||
if (JCWebGLPlus::getInstance()->m_nThreadMODE == THREAD_MODE_DOUBLE)
|
||||
{
|
||||
if (bSyncToRender)
|
||||
{
|
||||
JCWebGLPlus::getInstance()->m_pJSABManagerSyncToRender->syncArrayBufferDataToRuntime(nID, pBuffer, nABLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->syncArrayBufferDataToRuntime(nID, pBuffer, nABLen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->syncArrayBufferDataToRuntime(nID, pBuffer, nABLen);
|
||||
}
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, true));
|
||||
return;
|
||||
}
|
||||
LOGE("JSLayaGL::syncArrayBufferDataToRuntime type error");
|
||||
args.GetReturnValue().Set(v8::Boolean::New(isolate, false));
|
||||
}
|
||||
|
||||
static void EvaluateClipDatasRealTime(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus EvaluateClipDatasRealTime");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 5)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> nodes = args[0];
|
||||
assert(args[1]->IsNumber());
|
||||
float playCurTime = args[1]->NumberValue();
|
||||
v8::Local<v8::Value> realTimeCurrentFrameIndexs = args[2];
|
||||
assert(args[3]->IsBoolean());
|
||||
bool addtive = args[3]->BooleanValue();
|
||||
assert(args[4]->IsBoolean());
|
||||
bool frontPlay = args[4]->BooleanValue();
|
||||
|
||||
char* pBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(realTimeCurrentFrameIndexs, pBuffer, nABLen);
|
||||
if (!bIsArrayBuffer)
|
||||
{
|
||||
LOGE("evaluateClipDatasRealTime index type error");
|
||||
return;
|
||||
}
|
||||
if (!nodes.IsEmpty() && nodes->IsObject())
|
||||
{
|
||||
JSKeyframeNodeList* pNodes = (JSKeyframeNodeList*)nodes.As<v8::Object>()->GetAlignedPointerFromInternalField(0);
|
||||
if (!pNodes)
|
||||
{
|
||||
LOGE("evaluateClipDatasRealTime nodes type error");
|
||||
return;
|
||||
}
|
||||
JSKeyframeNodeList::evaluateClipDatasRealTime(pNodes, playCurTime, (short*)pBuffer, nABLen / sizeof(unsigned short), addtive, frontPlay);
|
||||
}
|
||||
}
|
||||
|
||||
static void UniformMatrix2fvEx(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus UniformMatrix2fvEx");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert(args[0]->IsUint32());
|
||||
GLuint location = args[0]->Uint32Value();
|
||||
assert(args[1]->IsBoolean());
|
||||
GLboolean transpose = args[1]->BooleanValue();
|
||||
assert(args[2]->IsInt32());
|
||||
int id = args[2]->Int32Value();
|
||||
|
||||
JCWebGLPlus::getInstance()->uniformMatrix2fvEx(location, transpose, id);
|
||||
}
|
||||
|
||||
static void UniformMatrix3fvEx(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus UniformMatrix3fvEx");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert(args[0]->IsUint32());
|
||||
GLuint location = args[0]->Uint32Value();
|
||||
assert(args[1]->IsBoolean());
|
||||
GLboolean transpose = args[1]->BooleanValue();
|
||||
assert(args[2]->IsInt32());
|
||||
int id = args[2]->Int32Value();
|
||||
|
||||
JCWebGLPlus::getInstance()->uniformMatrix3fvEx(location, transpose, id);
|
||||
}
|
||||
|
||||
static void UniformMatrix4fvEx(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus UniformMatrix4fvEx");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert(args[0]->IsUint32());
|
||||
GLuint location = args[0]->Uint32Value();
|
||||
assert(args[1]->IsBoolean());
|
||||
GLboolean transpose = args[1]->BooleanValue();
|
||||
assert(args[2]->IsInt32());
|
||||
int id = args[2]->Int32Value();
|
||||
|
||||
JCWebGLPlus::getInstance()->uniformMatrix4fvEx(location, transpose, id);
|
||||
}
|
||||
|
||||
static void UploadShaderUniforms(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus UploadShaderUniforms");
|
||||
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int nCmdID = args[0]->Int32Value();
|
||||
|
||||
assert(args[1]->IsInt32());
|
||||
int nDataID = args[1]->Int32Value();
|
||||
|
||||
JCWebGLPlus::getInstance()->uploadShaderUniforms(nCmdID, nDataID);
|
||||
}
|
||||
|
||||
static void UploadShaderUniformsBuffer(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
TEST_WEBGLPLUS_LOG("webglplus UploadShaderUniformsBuffer");
|
||||
|
||||
v8::Local<v8::Object> pthis = args.This();
|
||||
int len = args.Length();
|
||||
if (len < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert(args[0]->IsInt32());
|
||||
int nCmdID = args[0]->Int32Value();
|
||||
|
||||
char* pArrayBuffer = NULL;
|
||||
int nABLen = 0;
|
||||
bool bIsArrayBuffer = V8Util::extractJSAB(args[1], pArrayBuffer, nABLen);
|
||||
if (bIsArrayBuffer)
|
||||
{
|
||||
JCWebGLPlus::getInstance()->uploadShaderUniformsBuffer(nCmdID, pArrayBuffer, nABLen);
|
||||
}
|
||||
}
|
||||
|
||||
void JSWebGLPlus::exportJS(v8::Local<v8::Object> object)
|
||||
{
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope sc(isolate);
|
||||
v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate);
|
||||
functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "WebGLPlus"));
|
||||
v8::Local<v8::ObjectTemplate> instancTemp = functionTemplate->InstanceTemplate();
|
||||
v8::Local<v8::Context> pCtx = isolate->GetCurrentContext();
|
||||
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "uploadShaderUniforms", UploadShaderUniforms);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "uploadShaderUniformsBuffer", UploadShaderUniformsBuffer);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "uniformMatrix2fvEx", UniformMatrix2fvEx);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "uniformMatrix3fvEx", UniformMatrix3fvEx);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "uniformMatrix4fvEx", UniformMatrix4fvEx);
|
||||
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "createArrayBufferRef", CreateArrayBufferRef);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "updateArrayBufferRef", UpdateArrayBufferRef);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "syncArrayBufferDataToRuntime", SyncArrayBufferDataToRuntime);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "evaluateClipDatasRealTime", EvaluateClipDatasRealTime);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "updateAnimationNodeWorldMatix", UpdateAnimationNodeWorldMatix);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "computeSubSkinnedData", ComputeSubSkinnedData);
|
||||
V8Util::SET_PROTOTYPE_METHOD(functionTemplate, "culling", Culling);
|
||||
|
||||
v8::EscapableHandleScope handle_scope(isolate);
|
||||
v8::Handle<v8::ObjectTemplate> pTempl = v8::Local<v8::ObjectTemplate>::New(isolate, instancTemp);
|
||||
v8::Handle<v8::Object> pNewIns = pTempl->NewInstance();
|
||||
|
||||
persistentObject.Reset(isolate, pNewIns);
|
||||
|
||||
|
||||
object->Set(v8::String::NewFromUtf8(isolate, "webglPlus"), pNewIns);
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
@file JSWebGLPlus.h
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2019_8_24
|
||||
*/
|
||||
|
||||
#ifndef __JSWebGLPlus_H__
|
||||
#define __JSWebGLPlus_H__
|
||||
#include <v8.h>
|
||||
#include "../JSObjBase.h"
|
||||
#include "../JCWebGLPlus.h"
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
namespace laya
|
||||
{
|
||||
class JSWebGLPlus : public JCListNode
|
||||
{
|
||||
public:
|
||||
|
||||
void exportJS(v8::Local<v8::Object> object);
|
||||
|
||||
static JSWebGLPlus* getInstance();
|
||||
|
||||
JSWebGLPlus();
|
||||
|
||||
~JSWebGLPlus();
|
||||
|
||||
bool updateArrayBufferRef(int nID, bool bSyncToRender, v8::Local<v8::Value> pArrayBuffer);
|
||||
|
||||
public:
|
||||
static JSWebGLPlus* s_pWebGLPlus;
|
||||
v8::Persistent<v8::Object> persistentObject;
|
||||
};
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //__JSWebGLPlus_H__
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
@file V8Util.cpp
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2017_11_29
|
||||
*/
|
||||
|
||||
#include "V8Util.h"
|
||||
|
||||
namespace laya
|
||||
{
|
||||
void V8Util::SET_PROTOTYPE_METHOD(v8::Local<v8::FunctionTemplate> recv, const char* name, v8::FunctionCallback callback)
|
||||
{
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Signature> s = v8::Signature::New(isolate, recv);
|
||||
v8::Local<v8::FunctionTemplate> t =
|
||||
v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), s);
|
||||
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
|
||||
v8::NewStringType::kInternalized).ToLocalChecked();
|
||||
t->SetClassName(fn_name);
|
||||
recv->PrototypeTemplate()->Set(fn_name, t);
|
||||
}
|
||||
|
||||
bool V8Util::extractJSAB(v8::Local<v8::Value> jsval, char*& data, int& len)
|
||||
{
|
||||
v8::Local<v8::ArrayBuffer> ab;
|
||||
if (jsval->IsArrayBufferView())
|
||||
{
|
||||
v8::Local<v8::ArrayBufferView> abv = v8::Local<v8::ArrayBufferView>::Cast(jsval);
|
||||
len = abv->ByteLength();
|
||||
ab = abv->Buffer();
|
||||
v8::ArrayBuffer::Contents contents = ab->GetContents();
|
||||
data = (char*)contents.Data() + abv->ByteOffset();
|
||||
}
|
||||
else if (jsval->IsArrayBuffer())
|
||||
{
|
||||
ab = v8::Local<v8::ArrayBuffer>::Cast(jsval);
|
||||
v8::ArrayBuffer::Contents contents = ab->GetContents();
|
||||
len = contents.ByteLength();
|
||||
data = (char*)contents.Data();
|
||||
}
|
||||
else
|
||||
{
|
||||
data = NULL;
|
||||
len = 0;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
@file V8Util.h
|
||||
@brief
|
||||
@author James
|
||||
@version 1.0
|
||||
@date 2017_11_29
|
||||
*/
|
||||
|
||||
#ifndef __V8Util_H__
|
||||
#define __V8Util_H__
|
||||
|
||||
#include <v8.h>
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
namespace laya
|
||||
{
|
||||
class V8Util
|
||||
{
|
||||
public:
|
||||
|
||||
static bool extractJSAB(v8::Local<v8::Value> jsval, char*& data, int& len);
|
||||
static void SET_PROTOTYPE_METHOD(v8::Local<v8::FunctionTemplate> recv, const char* name, v8::FunctionCallback callback);
|
||||
};
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif //__V8Util_H__
|
||||
|
||||
//-----------------------------END FILE--------------------------------
|
||||
Reference in New Issue
Block a user