open source

This commit is contained in:
lvfulong
2020-11-11 16:17:13 +08:00
parent 4d989f3ecb
commit bc4ca748de
2441 changed files with 623057 additions and 2 deletions
@@ -0,0 +1,63 @@
/**
@file JCFloatArrayKeyframe.h
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#ifndef __JCFloatArrayKeyframe_H__
#define __JCFloatArrayKeyframe_H__
#include <stdio.h>
#include <string>
#include <map>
#include "JCFloatKeyframe.h"
namespace laya
{
class JCFloatArrayKeyframe : public JCKeyFrame
{
public:
struct FloatArrayBuffer
{
char* data;
int byteSize;
FloatArrayBuffer()
{
data = NULL;
byteSize = 0;
}
};
public:
JCFloatArrayKeyframe() {}
virtual ~JCFloatArrayKeyframe() {}
void setTime(float nTime)
{
m_nTime = nTime;
}
float getTime()
{
return m_nTime;
}
public:
FloatArrayBuffer m_nInTangent;
FloatArrayBuffer m_nOutTangent;
FloatArrayBuffer m_nValue;
FloatArrayBuffer m_pData;
};
}
//------------------------------------------------------------------------------
#endif //__JCFloatArrayKeyframe_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,104 @@
/**
@file JCFloatKeyframe.h
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#ifndef __JCFloatKeyframe_H__
#define __JCFloatKeyframe_H__
#include <stdio.h>
#include <string>
#include <map>
namespace laya
{
class JCKeyFrame
{
public:
JCKeyFrame()
{
m_nTime = 0;
}
virtual ~JCKeyFrame()
{
}
float m_nTime;
};
class JCFloatKeyframe : public JCKeyFrame
{
public:
JCFloatKeyframe()
{
m_nInTangent = 0;
m_nOutTangent = 0;
m_nValue = 0;
}
virtual ~JCFloatKeyframe() {}
void setTime(float nTime)
{
m_nTime = nTime;
}
float getTime()
{
return m_nTime;
}
void setInTangent(float nInTangent)
{
m_nInTangent = nInTangent;
}
float getInTangent()
{
return m_nInTangent;
}
void setOutTangent(float nInTangent)
{
m_nOutTangent = nInTangent;
}
float getOutTangent()
{
return m_nOutTangent;
}
void setValue(float nValue)
{
m_nValue = nValue;
}
float getValue()
{
return m_nValue;
}
void _cloneTo(JCFloatKeyframe* pDestObj)
{
pDestObj->m_nTime = m_nTime;
pDestObj->m_nInTangent = m_nInTangent;
pDestObj->m_nOutTangent = m_nOutTangent;
pDestObj->m_nValue = m_nValue;
}
public:
float m_nInTangent;
float m_nOutTangent;
float m_nValue;
};
}
//------------------------------------------------------------------------------
#endif //__JCFloatKeyframe_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,186 @@
/**
@file JCKeyframeNode.h
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#ifndef __JCKeyframeNode_H__
#define __JCKeyframeNode_H__
#include <stdio.h>
#include <string>
#include <map>
#include <vector>
#include "JCFloatKeyframe.h"
#include "JCFloatArrayKeyframe.h"
namespace laya
{
class JCKeyframeNode
{
public:
JCKeyframeNode()
{
m_nIndexInList = 0;
m_nType = 0;
m_nDataType = 0;
m_pDataFloat = 0;
}
virtual ~JCKeyframeNode()
{
m_vOwnerPath.clear();
m_vPropertys.clear();
m_vKeyFrames.clear();
}
int getOwnerPathCount()
{
return m_vOwnerPath.size();
}
int getPropertyCount()
{
return m_vPropertys.size();
}
int getKeyFramesCount()
{
return m_vKeyFrames.size();
}
void _setOwnerPathCount(int value)
{
m_vOwnerPath.resize(value);
}
void _setOwnerPathByIndex(int index, const char* value)
{
m_vOwnerPath[index] = value;
}
const char* _joinOwnerPath(const char* sep)
{
s_sTempString = "";
int nSize = m_vOwnerPath.size() - 1;
for (int i = 0; i < nSize; i++)
{
s_sTempString += m_vOwnerPath[i];
s_sTempString += sep;
}
s_sTempString += m_vOwnerPath[nSize];
return s_sTempString.c_str();
}
void _setPropertyCount(int value)
{
m_vPropertys.resize(value);
}
void _setPropertyByIndex(int index, const char* value)
{
m_vPropertys[index] = value;
}
const char* _joinProperty(const char* sep)
{
s_sTempString = "";
int nSize = m_vPropertys.size() - 1;
for (int i = 0; i < nSize; i++)
{
s_sTempString += m_vPropertys[i];
s_sTempString += sep;
}
s_sTempString += m_vPropertys[nSize];
return s_sTempString.c_str();
}
void _setKeyframeCount(int value)
{
m_vKeyFrames.resize(value);
}
const char* getOwnerPathByIndex(int index)
{
return m_vOwnerPath[index].c_str();
}
const char* getPropertyByIndex(int index)
{
return m_vPropertys[index].c_str();
}
void setIndexInList(int n)
{
m_nIndexInList = n;
}
int getIndexInList()
{
return m_nIndexInList;
}
void setType(int nType)
{
m_nType = nType;
}
int getType()
{
return m_nType;
}
void setFullPath(const char* sPath)
{
m_sFullPath = sPath;
}
const char* getFullPath()
{
return m_sFullPath.c_str();
}
void setPropertyOwner(const char* sBuffer)
{
m_sPropertyOwner = sBuffer;
}
const char* getPropertyOwner()
{
return m_sPropertyOwner.c_str();
}
int getDataType()
{
return m_nDataType;
}
float getFloatData()
{
return m_pDataFloat;
}
public:
static std::string s_sTempString;
std::vector<std::string> m_vOwnerPath;
std::vector<std::string> m_vPropertys;
std::vector<JCKeyFrame*> m_vKeyFrames;
int m_nIndexInList;
int m_nType;
std::string m_sFullPath;
std::string m_sPropertyOwner;
short m_nDataType; //0为float 1为FloatArray
float m_pDataFloat;
JCFloatArrayKeyframe::FloatArrayBuffer m_pDataFloatArray;
};
}
//------------------------------------------------------------------------------
#endif //__JCKeyframeNode_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,265 @@
/**
@file JCKeyframeNodeList.cpp
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#include "JCKeyframeNodeList.h"
#include "../Log.h"
namespace laya
{
//------------------------------------------------------------------------------
JCKeyframeNodeList::JCKeyframeNodeList()
{
}
//------------------------------------------------------------------------------
JCKeyframeNodeList::~JCKeyframeNodeList()
{
m_vNodes.clear();
}
void JCKeyframeNodeList::evaluateClipDatasRealTime(JCKeyframeNodeList* nodes, float playCurTime, short* realTimeCurrentFrameIndexs, int indexSize, bool addtive, bool frontPlay)
{
int nNodeCount = nodes->getCount();
if (nNodeCount != indexSize)
{
LOGE("evaluateClipDatasRealTime error");
return;
}
for (int i = 0; i < nNodeCount; i++) {
JCKeyframeNode* node = nodes->m_vNodes[i];
int type = node->m_nType;
short nextFrameIndex = 0;
std::vector<JCKeyFrame*> keyFrames = node->m_vKeyFrames;
int keyFramesCount = keyFrames.size();
short frameIndex = realTimeCurrentFrameIndexs[i];
if (true)
{
if (frameIndex != -1 && playCurTime < keyFrames[frameIndex]->m_nTime)
{
frameIndex = -1;
realTimeCurrentFrameIndexs[i] = frameIndex;
}
nextFrameIndex = frameIndex + 1;
while (nextFrameIndex < keyFramesCount) {
if (keyFrames[nextFrameIndex]->m_nTime > playCurTime)
break;
frameIndex++;
nextFrameIndex++;
realTimeCurrentFrameIndexs[i] = frameIndex;
}
}
else
{
nextFrameIndex = frameIndex + 1;
if ((nextFrameIndex != keyFramesCount) &&
(playCurTime > keyFrames[nextFrameIndex]->m_nTime))
{
frameIndex = keyFramesCount - 1;
realTimeCurrentFrameIndexs[i] = frameIndex;
}
nextFrameIndex = frameIndex + 1;
while (frameIndex > -1)
{
if (keyFrames[frameIndex]->m_nTime < playCurTime)
break;
frameIndex--;
nextFrameIndex--;
realTimeCurrentFrameIndexs[i] = frameIndex;
}
}
bool isEnd = (nextFrameIndex == keyFramesCount);
switch (type) {
case 0:
{
node->m_nDataType = 0;
JCFloatKeyframe* pKeyframe = (JCFloatKeyframe*)keyFrames[0];
if (frameIndex != -1)
{
JCFloatKeyframe* frame = (JCFloatKeyframe*)keyFrames[frameIndex];
if (isEnd) {//如果nextFrame为空,不修改数据,保持上一帧
node->m_pDataFloat = frame->m_nValue;
}
else {
JCFloatKeyframe* nextFarme = (JCFloatKeyframe*)keyFrames[nextFrameIndex];
float d = nextFarme->m_nTime - frame->m_nTime;
float t;
if (d != 0)
t = (playCurTime - frame->m_nTime) / d;
else
t = 0;
node->m_pDataFloat = _hermiteInterpolate(frame, nextFarme, t, d);
}
}
else {
node->m_pDataFloat = pKeyframe->m_nValue;
}
if (addtive) {
node->m_pDataFloat -= pKeyframe->m_nValue;
}
break;
}
case 1:
case 4:
{
node->m_nDataType = 1;
JCFloatArrayKeyframe::FloatArrayBuffer* clipData = &node->m_pDataFloatArray;
_evaluateFrameNodeArrayDatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, 3, *clipData);
if (addtive) {
JCFloatArrayKeyframe* pKeyframe = (JCFloatArrayKeyframe*)keyFrames[0];
JCFloatArrayKeyframe::FloatArrayBuffer* firstFrameValue = &pKeyframe->m_pData;
float* clipVData = (float*)clipData->data;
float* firstValue = (float*)firstFrameValue->data;
clipVData[0] -= firstValue[6];
clipVData[1] -= firstValue[7];
clipVData[2] -= firstValue[8];
}
break;
}
case 2:
{
node->m_nDataType = 1;
JCFloatArrayKeyframe::FloatArrayBuffer* clipData = &node->m_pDataFloatArray;
_evaluateFrameNodeArrayDatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, 4, *clipData);
if (addtive) {
float temp[4];
JCFloatArrayKeyframe* pKeyframe = (JCFloatArrayKeyframe*)keyFrames[0];
JCFloatArrayKeyframe::FloatArrayBuffer* firstFrameValue = &pKeyframe->m_pData;
quaternionConjugate((float*)firstFrameValue->data,8,temp);
quaternionMultiply(temp, (float*)clipData->data, (float*)clipData->data);
}
break;
}
case 3:
{
node->m_nDataType = 1;
JCFloatArrayKeyframe::FloatArrayBuffer* clipData = &node->m_pDataFloatArray;
_evaluateFrameNodeArrayDatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, 3, *clipData);
if (addtive) {
JCFloatArrayKeyframe* pKeyframe = (JCFloatArrayKeyframe*)keyFrames[0];
JCFloatArrayKeyframe::FloatArrayBuffer* firstFrameValue = &pKeyframe->m_pData;
float* clipVData = (float*)clipData->data;
float* firstValue = (float*)firstFrameValue->data;
clipVData[0] /= firstValue[6];
clipVData[1] /= firstValue[7];
clipVData[2] /= firstValue[8];
}
break;
}
default:
throw "AnimationClip:unknown node type.";
}
}
}
float JCKeyframeNodeList::_hermiteInterpolate(JCFloatKeyframe* frame, JCFloatKeyframe* nextFrame, float t, float dur) {
float t0 = frame->m_nOutTangent, t1 = nextFrame->m_nInTangent;
float t2 = t * t;
float t3 = t2 * t;
float a = (float)(2.0 * t3 - 3.0 * t2 + 1.0);
float b = (float)(t3 - 2.0 * t2 + t);
float c = (float)(t3 - t2);
float d = (float)(-2.0 * t3 + 3.0 * t2);
return a * frame->m_nValue + b * t0 * dur + c * t1 * dur + d * nextFrame->m_nValue;
}
void JCKeyframeNodeList::_evaluateFrameNodeArrayDatasRealTime(std::vector<JCKeyFrame*>& keyFrames, int frameIndex, bool isEnd, float playCurTime, int width, JCFloatArrayKeyframe::FloatArrayBuffer& outDatas)
{
int dataOffset = width * 2;
float* outVData = (float*)outDatas.data;
if (frameIndex != -1)
{
JCFloatArrayKeyframe* frame = (JCFloatArrayKeyframe*)keyFrames[frameIndex];
if (isEnd)
{
float* frameData = (float*)frame->m_pData.data;
for (int j = 0; j < width; j++)
outVData[j] = frameData[dataOffset+j];//不能设为null,会造成跳过当前帧数据
}
else
{
JCFloatArrayKeyframe* nextKeyFrame = (JCFloatArrayKeyframe*)keyFrames[frameIndex + 1];
float t;
float startTime = frame->m_nTime;
float d = nextKeyFrame->m_nTime - startTime;
if (d != 0)
t = (playCurTime - startTime) / d;
else
t = 0;
_hermiteInterpolateArray(frame, nextKeyFrame, t, d, outDatas);
}
}
else
{
JCFloatArrayKeyframe::FloatArrayBuffer* firstFrameDatas = &((JCFloatArrayKeyframe*)keyFrames[0])->m_pData;
float* frameData = (float*)firstFrameDatas->data;
for (int j = 0; j < width; j++)
outVData[j] = frameData[dataOffset+j];
}
}
void JCKeyframeNodeList::_hermiteInterpolateArray(JCFloatArrayKeyframe* frame, JCFloatArrayKeyframe* nextFrame, float t, float dur, JCFloatArrayKeyframe::FloatArrayBuffer& out) {
bool isComputeParams = false;
float a, b, c, d;
float* out_data = (float*)out.data;
float* p0_data = (float*)frame->m_pData.data;
float* p1_data = (float*)nextFrame->m_pData.data;
int nOutTanOffset = out.byteSize / sizeof(float);
int nOffset = nOutTanOffset * 2;
for (int i = 0; i < nOutTanOffset; i++) {
float t0 = p0_data[nOutTanOffset +i], t1 = p1_data[i];
if (!isComputeParams) {
float t2 = t * t;
float t3 = t2 * t;
a = (float)(2.0 * t3 - 3.0 * t2 + 1.0);
b = (float)(t3 - 2.0 * t2 + t);
c = (float)(t3 - t2);
d = (float)(-2.0 * t3 + 3.0 * t2);
isComputeParams = true;
}
out_data[i] = a * p0_data[nOffset+i] + b * t0 * dur + c * t1 * dur + d * p1_data[nOffset+i];
}
}
void JCKeyframeNodeList::quaternionConjugate(float* value,int nOffset, float* result) {
result[0] = -value[nOffset];
result[1] = -value[nOffset+1];
result[2] = -value[nOffset+2];
result[3] = value[nOffset+3];
}
void JCKeyframeNodeList::quaternionMultiply(float* le, float* re, float* oe) {
/*[DISABLE-ADD-VARIABLE-DEFAULT-VALUE]*/
float lx = le[0];
float ly = le[1];
float lz = le[2];
float lw = le[3];
float rx = re[0];
float ry = re[1];
float rz = re[2];
float rw = re[3];
float a = ly * rz - lz * ry;
float b = lz * rx - lx * rz;
float c = lx * ry - ly * rx;
float d = lx * rx + ly * ry + lz * rz;
oe[0] = lx * rw + rx * lw + a;
oe[1] = ly * rw + ry * lw + b;
oe[2] = lz * rw + rz * lw + c;
oe[3] = lw * rw - d;
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,63 @@
/**
@file JCKeyframeNodeList.h
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#ifndef __JCKeyframeNodeList_H__
#define __JCKeyframeNodeList_H__
#include <stdio.h>
#include <string>
#include <map>
#include "JCKeyframeNode.h"
#include <vector>
namespace laya
{
class JCKeyframeNodeList
{
public:
static void evaluateClipDatasRealTime(JCKeyframeNodeList* nodes, float playCurTime, short* realTimeCurrentFrameIndexs,int indexSize, bool addtive, bool frontPlay);
JCKeyframeNodeList();
virtual ~JCKeyframeNodeList();
int getCount()
{
return m_vNodes.size();
}
void setCount(int value)
{
m_vNodes.resize(value);
}
protected:
static float _hermiteInterpolate(JCFloatKeyframe* frame, JCFloatKeyframe* nextFrame, float t, float dur);
static void _evaluateFrameNodeArrayDatasRealTime(std::vector<JCKeyFrame*>& keyFrames, int frameIndex, bool isEnd, float playCurTime, int width, JCFloatArrayKeyframe::FloatArrayBuffer& outDatas);
static void _hermiteInterpolateArray(JCFloatArrayKeyframe* frame, JCFloatArrayKeyframe* nextFrame, float t, float dur, JCFloatArrayKeyframe::FloatArrayBuffer& out);
static void quaternionConjugate(float* value, int offset, float* result);
static void quaternionMultiply(float* le, float* re, float* oe);
public:
std::vector<JCKeyframeNode*> m_vNodes;
};
}
//------------------------------------------------------------------------------
#endif //__JCKeyframeNodeList_H__
//-----------------------------END FILE--------------------------------
+484
View File
@@ -0,0 +1,484 @@
/**
@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 "math/JCBoundingFrustum.h"
#include "math/JCBoundingBox.h"
#include "math/JCBoundingSphere.h"
#include "Log.h"
namespace laya
{
JCWebGLPlus* JCWebGLPlus::s_pWebGLPlus = NULL;
JCWebGLPlus::JCWebGLPlus()
{
m_pJSArrayBufferManager = NULL;
m_pJSABManagerSyncToRender = NULL;
m_pRArrayBufferManager = NULL;
m_nThreadMODE = THREAD_MODE_DOUBLE;
s_pWebGLPlus = this;
}
JCWebGLPlus::~JCWebGLPlus()
{
s_pWebGLPlus = NULL;
if (m_pJSArrayBufferManager)
{
delete m_pJSArrayBufferManager;
m_pJSArrayBufferManager = NULL;
}
if (m_pJSABManagerSyncToRender)
{
delete m_pJSABManagerSyncToRender;
m_pJSABManagerSyncToRender = NULL;
}
if (m_nThreadMODE == THREAD_MODE_DOUBLE)
{
if (m_pRArrayBufferManager)
{
delete m_pRArrayBufferManager;
m_pRArrayBufferManager = NULL;
}
}
else
{
m_pRArrayBufferManager = NULL;
}
clean();
}
JCWebGLPlus* JCWebGLPlus::getInstance()
{
return s_pWebGLPlus ? s_pWebGLPlus : new JCWebGLPlus();
}
void JCWebGLPlus::releaseInstance()
{
if (s_pWebGLPlus)
{
delete s_pWebGLPlus;
s_pWebGLPlus = NULL;
}
}
void JCWebGLPlus::init(int nThreadMode)
{
if (m_pJSArrayBufferManager == NULL)
{
m_nThreadMODE = nThreadMode;
m_pJSArrayBufferManager = new JCArrayBufferManager();
m_pJSABManagerSyncToRender = new JCArrayBufferManager();
if (nThreadMode == THREAD_MODE_SINGLE)
{
m_pRArrayBufferManager = m_pJSArrayBufferManager;
}
else if(nThreadMode == THREAD_MODE_DOUBLE)
{
m_pRArrayBufferManager = new JCArrayBufferManager();
}
else
{
LOGE("JCWebGLPlus::init thread mode error");
m_nThreadMODE = THREAD_MODE_DOUBLE;
m_pRArrayBufferManager = new JCArrayBufferManager();
}
}
}
void JCWebGLPlus::matrix4x4MultiplyFFF(float* a, float* b, float* e)
{
int i = 0;
float ai0, ai1, ai2, ai3;
float b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
float b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7];
float b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11];
float b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
for (i = 0; i < 4; i++)
{
ai0 = a[i];
ai1 = a[i + 4];
ai2 = a[i + 8];
ai3 = a[i + 12];
e[i] = ai0 * b0 + ai1 * b1 + ai2 * b2 + ai3 * b3;
e[i + 4] = ai0 * b4 + ai1 * b5 + ai2 * b6 + ai3 * b7;
e[i + 8] = ai0 * b8 + ai1 * b9 + ai2 * b10 + ai3 * b11;
e[i + 12] = ai0 * b12 + ai1 * b13 + ai2 * b14 + ai3 * b15;
}
}
void JCWebGLPlus::calcMatrix(float* pos, float* scale, float* quat, float* outE) {
float x = quat[0], y = quat[1], z = quat[2], w = quat[3],
x2 = x + x,
y2 = y + y,
z2 = z + z;
float xx = x * x2,
xy = x * y2,
xz = x * z2,
yy = y * y2,
yz = y * z2,
zz = z * z2;
float wx = w * x2,
wy = w * y2,
wz = w * z2,
sx = scale[0],
sy = scale[1],
sz = scale[2];
outE[0] = (1 - (yy + zz)) * sx;
outE[1] = (xy + wz) * sx;
outE[2] = (xz - wy) * sx;
outE[3] = 0;
outE[4] = (xy - wz) * sy;
outE[5] = (1 - (xx + zz)) * sy;
outE[6] = (yz + wx) * sy;
outE[7] = 0;
outE[8] = (xz + wy) * sz;
outE[9] = (yz - wx) * sz;
outE[10] = (1 - (xx + yy)) * sz;
outE[11] = 0;
outE[12] = pos[0];
outE[13] = pos[1];
outE[14] = pos[2];
outE[15] = 1;
}
int JCWebGLPlus::culling3D(int cullingCount, char* pFrustumBuffer, int nFrustumLen, char* pCullingBuffer, int nCullingBufferLen,
char* pCullingBufferIndices, int nCullingBufferIndicesLen, char* pCullingBufferResult, int nCullingBufferResultLen)
{
float* pF32FrustumBuffer = (float*)pFrustumBuffer;
float* pF32CullingBuffer = (float*)pCullingBuffer;
int* pI32CullingBufferIndices = (int*)pCullingBufferIndices;
int* pI32CullingBufferResult = (int*)pCullingBufferResult;
int nResultCount = cullingCount;
JCBoundingFrustum kFrustum;
kFrustum.setValues(pF32FrustumBuffer);
JCBoundingBox kBox;
JCBoundingSphere kSphere;
for (int i = 0; i < cullingCount; i++)
{
int nIndex = pI32CullingBufferIndices[i];
int nType = (int)(pF32CullingBuffer[nIndex]);
bool bSucess = true;
switch (nType)
{
case 0:
bSucess = true;
break;
case 1:
kSphere.setValues(pF32CullingBuffer + nIndex + 1);
bSucess = kFrustum.containsBoundingSphere(kSphere) != CT_DISJOINT;
break;
case 2:
kBox.setValues(pF32CullingBuffer + nIndex + 1);
//bSucess = kFrustum.containsAxisAlignedBouningBox(kBox) != CT_DISJOINT;
bSucess = kFrustum.intersects(kBox);
break;
default:
break;
}
if (bSucess)
{
pI32CullingBufferResult[i] = 1;
}
else
{
pI32CullingBufferResult[i] = 0;
}
}
return nResultCount;
}
bool JCWebGLPlus::updateAnimationNodeWorldMatix3D(char* pLocPosition, int nLocPosLen, char* pLocRotation, int nLocRotLen, char* pLocScaling, int nLocScaLen,
char* pParentIndices, int nLocParentLen, char* pOutWorldMatrix, int nOutWorldLen)
{
float* pfLocPosition = (float*)pLocPosition; //vec3
float* pfLocRotation = (float*)pLocRotation; //
float* pfLocScaling = (float*)pLocScaling;
signed short* pfParentIndices = (signed short*)pParentIndices;
float* pfOutWorldMatrix = (float*)pOutWorldMatrix;
int boneNum = nLocParentLen / sizeof(signed short);
int matOutNum = nOutWorldLen / (sizeof(float) * 16);
if (boneNum > matOutNum)
{
//错误了
LOGE("输出矩阵空间太小,结果会不正确!");
boneNum = matOutNum;
}
float* pCurPos = pfLocPosition;
float* pCurScale = pfLocScaling;
float* pCurQuat = pfLocRotation;
float* pCurMat = pfOutWorldMatrix;
signed short* pCurPar = pfParentIndices;
float tmpMat[16];
for (int i = 0; i < boneNum; i++) {
calcMatrix(pCurPos, pCurScale, pCurQuat, pCurMat);
int par = *(pCurPar++);
if (par >= 0) {
if (par >= boneNum) {
LOGE("boneParent too big!");
}
else {
float* pParMat = pfOutWorldMatrix + par * 16;
matrix4x4MultiplyFFF(pParMat, pCurMat, tmpMat);
memcpy(pCurMat, tmpMat, 16 * sizeof(float));//用一个一个赋值吗
}
}
else {
pCurMat[1] = pCurMat[2] = pCurMat[3] = pCurMat[4] = pCurMat[6] = pCurMat[7] = pCurMat[8] = pCurMat[9] = pCurMat[11] = pCurMat[12] = pCurMat[13] = pCurMat[14] = 0;
pCurMat[0] = pCurMat[5] = pCurMat[10] = pCurMat[15] = 1;
}
pCurPos += 3;
pCurScale += 3;
pCurQuat += 4;
pCurMat += 16;
}
return true;
}
bool JCWebGLPlus::computeSubSkinnedData3D(char* pWorldMatrixs, int nWorldMatLen, char* pWorldMatrixIndex, int nWorldMatIndeLen,
char* pInverseBindPoses, int nInverseBindPosesLen, char* pBoneIndices, int nBoneIndicesLen,
char* pBindPoseIndices, int nBindPoseIndicesLen, char* pResultData, int nResultDataLen)
{
float* pF32WorldMatrixs = (float*)pWorldMatrixs;
unsigned short* pU16WorldMatrixIndex = (unsigned short*)pWorldMatrixIndex;
float* pF32InverseBindPoses = (float*)pInverseBindPoses;
unsigned short* pU16BoneIndices = (unsigned short*)pBoneIndices;
nBoneIndicesLen /= sizeof(unsigned short);
unsigned short* pU16BindPoseIndices = (unsigned short*)pBindPoseIndices;
float* pf32ResultData = (float*)pResultData;
//当前的骨头数量
for (int i = 0; i < nBoneIndicesLen; i++)
{
int nBoneIndex = pU16BoneIndices[i];//骨头的ID
//worldMartix的ID
int nWorldMatrixID = pU16WorldMatrixIndex[nBoneIndex];
//当前world Matrix
float* pCurWorldMatrix = pF32WorldMatrixs + nWorldMatrixID * 16;
//当前bindPoseID
int nBindPoseID = pU16BindPoseIndices[nBoneIndex];
//当前bind Pose Matrix
float* pCurBindMatrix = pF32InverseBindPoses + nBindPoseID * 16;
//计算
float* pResultMatrix = pf32ResultData + i * 16;
matrix4x4MultiplyFFF(pCurWorldMatrix, pCurBindMatrix, pResultMatrix);
}
return true;
}
void JCWebGLPlus::uniformMatrix2fvEx(GLuint location, GLboolean transpose, int id)
{
JCArrayBufferManager::ArrayBufferContent* pData = m_pRArrayBufferManager->getArrayBuffer(id);
if (pData)
{
uniformMatrix2fv(location, pData->m_nLength / sizeof(float) / 4, transpose, (float*)pData->m_pBuffer);
}
}
void JCWebGLPlus::uniformMatrix3fvEx(GLuint location, GLboolean transpose, int id)
{
JCArrayBufferManager::ArrayBufferContent* pData = m_pRArrayBufferManager->getArrayBuffer(id);
if (pData)
{
uniformMatrix3fv(location, pData->m_nLength / sizeof(float) / 9, transpose, (float*)pData->m_pBuffer);
}
}
void JCWebGLPlus::uniformMatrix4fvEx(GLuint location, GLboolean transpose, int id)
{
JCArrayBufferManager::ArrayBufferContent* pData = m_pRArrayBufferManager->getArrayBuffer(id);
if (pData)
{
uniformMatrix4fv(location, pData->m_nLength / sizeof(float) / 16, transpose, (float*)pData->m_pBuffer);
}
}
void JCWebGLPlus::uploadShaderUniforms(int nCmdID, int nDataID)
{
JCArrayBufferManager::ArrayBufferContent* pCmd = m_pRArrayBufferManager->getArrayBuffer(nCmdID);
JCArrayBufferManager::ArrayBufferContent* pData = m_pRArrayBufferManager->getArrayBuffer(nDataID);
if (pCmd && pData)
{
_uploadShaderUniforms(pCmd->getCommandEncoderBuffer(), pData->m_pBuffer, pData->m_nLength);
}
}
void JCWebGLPlus::uploadShaderUniformsBuffer(int nCmdID, char* pData, int nDataSize)
{
JCArrayBufferManager::ArrayBufferContent* pCmd = m_pRArrayBufferManager->getArrayBuffer(nCmdID);
if (pCmd && pData)
{
_uploadShaderUniforms(pCmd->getCommandEncoderBuffer(), pData, nDataSize);
}
}
void JCWebGLPlus::_uploadShaderUniforms(JCCommandEncoderBuffer* pCmd, char* data, int dataSize)
{
if (pCmd == NULL)return;
pCmd->setReadPos(0);
int nLen = pCmd->getDataSize();
while (pCmd->getReadPos() < (size_t)nLen)
{
//i=funID j=uniformFunID k=location l=type m=offset
WEBGLPLUS_iiiiii* pParam = pCmd->popp<WEBGLPLUS_iiiiii>();
UNIFORM_FUN nFun = (UNIFORM_FUN)pParam->c;
int nLocation = pParam->d;
int nType = pParam->e;
int nOffset = pParam->f * 4;
int nTextureLocation = pParam->g;
switch (nFun)
{
case laya::UNIFORM1F:
{
float value = *(float*)(data + nOffset);
this->uniform1f(nLocation, value);
break;
}
case laya::UNIFORM1FV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
this->uniform1fv(nLocation, pBuffer->m_nLength / sizeof(float), (GLfloat*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORM1I:
{
int value = *(int*)(data + nOffset);
this->uniform1i(nLocation, value);
break;
}
case laya::UNIFORM1IV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
this->uniform1iv(nLocation, pBuffer->m_nLength / sizeof(int), (GLint*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORM2F:
case laya::UNIFORM2FV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
this->uniform2fv(nLocation, pBuffer->m_nLength / sizeof(float) / 2, (GLfloat*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORM2I:
case laya::UNIFORM2IV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
this->uniform2iv(nLocation, pBuffer->m_nLength / sizeof(int) / 2, (GLint*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORM3F:
case laya::UNIFORM3FV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
this->uniform3fv(nLocation, pBuffer->m_nLength / sizeof(float) / 3, (GLfloat*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORM3I:
case laya::UNIFORM3IV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
this->uniform3iv(nLocation, pBuffer->m_nLength / sizeof(int) / 3, (GLint*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORM4F:
case laya::UNIFORM4FV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
int nLength = pBuffer->m_nLength > 16 ? pBuffer->m_nLength : 16;
this->uniform4fv(nLocation, nLength / sizeof(float) / 4, (GLfloat*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORM4I:
case laya::UNIFORM4IV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
int nLength = pBuffer->m_nLength > 16 ? pBuffer->m_nLength : 16;
this->uniform4iv(nLocation, nLength / sizeof(int) / 4, (GLint*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORMMATRIX2FV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
this->uniformMatrix2fv(nLocation, pBuffer->m_nLength / sizeof(float) / 4, false, (GLfloat*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORMMATRIX3FV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
this->uniformMatrix3fv(nLocation, pBuffer->m_nLength / sizeof(float) / 9, false, (GLfloat*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORMMATRIX4FV:
{
int value = *(int*)(data + nOffset);
JCArrayBufferManager::ArrayBufferContent* pBuffer = m_pRArrayBufferManager->getArrayBuffer(value);
if (pBuffer)
{
this->uniformMatrix4fv(nLocation, pBuffer->m_nLength / sizeof(float) / 16, false, (GLfloat*)pBuffer->m_pBuffer);
}
break;
}
case laya::UNIFORMSAMPLER_2D:
{
int nGpuTextureID = *(int*)(data + nOffset);
this->activeTexture(nTextureLocation);
this->bindTexture(GL_TEXTURE_2D, nGpuTextureID);
this->uniform1i(nLocation, nTextureLocation - GL_TEXTURE0);
break;
}
case laya::UNIFORMSAMPLER_CUBE:
{
int nGpuTextureID = *(int*)(data + nOffset);
this->activeTexture(nTextureLocation);
this->bindTexture(GL_TEXTURE_CUBE_MAP, nGpuTextureID);
this->uniform1i(nLocation, nTextureLocation - GL_TEXTURE0);
break;
}
default:
break;
}
}
}
}
//-----------------------------END FILE--------------------------------
+152
View File
@@ -0,0 +1,152 @@
/**
@file JCWebGLPlus.h
@brief
@author James
@version 1.0
@date 2019_8_24
*/
#ifndef __JCWebGLPlus_H__
#define __JCWebGLPlus_H__
#if __APPLE__
#include <OpenGLES/ES3/gl.h>
#else
#include <GLES3/gl3.h>
#endif
#include <stdio.h>
#include <vector>
#include <string>
#include <functional>
#include "Manager/JCArrayBufferManager.h"
namespace laya
{
enum THREAD_MODE
{
THREAD_MODE_SINGLE = 1,
THREAD_MODE_DOUBLE,
};
enum UNIFORM_FUN
{
UNIFORM1F = 0,
UNIFORM1FV,
UNIFORM1I,
UNIFORM1IV,
UNIFORM2F,
UNIFORM2FV,
UNIFORM2I,
UNIFORM2IV,
UNIFORM3F,
UNIFORM3FV,
UNIFORM3I,
UNIFORM3IV,
UNIFORM4F,
UNIFORM4FV,
UNIFORM4I,
UNIFORM4IV,
UNIFORMMATRIX2FV,
UNIFORMMATRIX3FV,
UNIFORMMATRIX4FV,
UNIFORMSAMPLER_2D,
UNIFORMSAMPLER_CUBE,
};
struct WEBGLPLUS_iiiiii
{
int b;
int c;
int d;
int e;
int f;
int g;
};
/**
* @brief
*/
class JCWebGLPlus
{
public:
/** @brief构造函数
*/
JCWebGLPlus();
/** @brief析构函数
*/
~JCWebGLPlus();
static JCWebGLPlus* getInstance();
static void releaseInstance();
void init(int nThreadMode);
void exportJS(void* ctx, void* object);
void clearAll();
private:
void clean();
public:
int culling3D(int cullingCount, char* pFrustumBuffer, int nFrustumLen, char* pCullingBuffer, int nCullingBufferLen,
char* pCullingBufferIndices, int nCullingBufferIndicesLen, char* pCullingBufferResult, int nCullingBufferResultLen);
bool updateAnimationNodeWorldMatix3D(char* pLocPosition, int nLocPosLen, char* pLocRotation, int nLocRotLen, char* pLocScaling, int nLocScaLen,
char* pParentIndices, int nLocParentLen, char* pOutWorldMatrix, int nOutWorldLen);
bool computeSubSkinnedData3D(char* pWorldMatrixs, int nWorldMatLen, char* pWorldMatrixIndex, int nWorldMatIndeLen,
char* pInverseBindPoses, int nInverseBindPosesLen, char* pBoneIndices, int nBoneIndicesLen,
char* pBindPoseIndices, int nBindPoseIndicesLen, char* pResultData, int nResultDataLen);
void calcMatrix(float* pos, float* scale, float* quat, float* outE);
void matrix4x4MultiplyFFF(float* a, float* b, float* e);
public:
void uniformMatrix2fvEx(GLuint location, GLboolean transpose, int id);
void uniformMatrix3fvEx(GLuint location, GLboolean transpose, int id);
void uniformMatrix4fvEx(GLuint location, GLboolean transpose, int id);
void uploadShaderUniforms(int nCmdID, int nDataID);
void uploadShaderUniformsBuffer(int nCmdID, char* pData, int nDataSize);
void _uploadShaderUniforms(JCCommandEncoderBuffer* cmd, char* data, int dataSize);
public:
static JCWebGLPlus* s_pWebGLPlus;
JCArrayBufferManager* m_pJSArrayBufferManager; ///<JS线程的ArrayBufferManager
JCArrayBufferManager* m_pJSABManagerSyncToRender; ///<JS线程里面需要同步给渲染线程的ArrayBufferManager
JCArrayBufferManager* m_pRArrayBufferManager; ///<渲染线程的ArrayBufferManager
int m_nThreadMODE;
public:
std::function<void(GLuint location, GLfloat x)> uniform1f;
std::function<void(GLuint location, int count, const GLfloat* v)> uniform1fv;
std::function<void(GLuint location, GLint x)> uniform1i;
std::function<void(GLuint location, int count, const GLint* v)> uniform1iv;
std::function<void(GLuint location, GLfloat x, GLfloat y)> uniform2f;
std::function<void(GLuint location, int count, const GLfloat* v)> uniform2fv;
std::function<void(GLuint location, GLint x, GLint y)> uniform2i;
std::function<void(GLuint location, int count, const GLint* v)> uniform2iv;
std::function<void(GLuint location, GLfloat x, GLfloat y, GLfloat z)> uniform3f;
std::function<void(GLuint location, int count, const GLfloat* v)> uniform3fv;
std::function<void(GLuint location, GLint x, GLint y, GLint z)> uniform3i;
std::function<void(GLuint location, int count, const GLint* v)> uniform3iv;
std::function<void(GLuint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)> uniform4f;
std::function<void(GLuint location, int count, const GLfloat* v)> uniform4fv;
std::function<void(GLuint location, GLint x, GLint y, GLint z, GLint w)> uniform4i;
std::function<void(GLuint location, int count, const GLint* v)> uniform4iv;
std::function<void(GLuint location, int count, GLboolean transpose, GLfloat* value)> uniformMatrix2fv;
std::function<void(GLuint location, int count, GLboolean transpose, GLfloat* value)> uniformMatrix3fv;
std::function<void(GLuint location, int count, GLboolean transpose, GLfloat* value)> uniformMatrix4fv;
std::function<void(GLenum texture)> activeTexture;
std::function<void(GLenum target, GLuint texture)> bindTexture;
};
}
#endif //__JCWebGLPlus_H__
//-----------------------------END FILE--------------------------------
+33
View File
@@ -0,0 +1,33 @@
/**
@file jsobjbase.cpp
@brief
@author James
@version 1.0
@date 2019_8_24
*/
#include "JSObjBase.h"
namespace laya
{
unsigned int gnJSClsID = 1;
JsObjClassInfo JSObjNode::JSCLSINFO = { "JSObjNode",NULL,0 };
JCSimpList* JSObjNode::s_pListJSObj = NULL;
JSObjNode::JSObjNode()
{
if (s_pListJSObj)
{
s_pListJSObj->push_back(this);
}
m_pClsInfo = &JSObjNode::JSCLSINFO;
}
JSObjNode::~JSObjNode()
{
if (s_pListJSObj)
{
s_pListJSObj->delNode(this);
}
}
}
//-----------------------------END FILE--------------------------------
+175
View File
@@ -0,0 +1,175 @@
#ifndef __JSOBJECT_BASE_NODE_H___
#define __JSOBJECT_BASE_NODE_H___
#include <vector>
#include <string>
#include <functional>
namespace laya
{
class JCListNode
{
public:
JCListNode* _Prev;
JCListNode* _Next;
int id; // for debug
JCListNode() {
_Prev = _Next = this;
static int n = 0;
id = n++;
}
virtual ~JCListNode() {
//如果在链表上则删除
JCListNode* pPrev = _Prev;
JCListNode* pNext = _Next;
pPrev->_Next = _Next;
pNext->_Prev = _Prev;
_Next = this;
_Prev = this;
}
inline bool notInChain() {
return _Prev == this && _Next == this;
}
};
/**
* @brief 因为stl的list在删除对象的时候不太方便,需要遍历找到iterator,所以先自己写一个
*/
class JCSimpList
{
protected:
JCListNode* pHead; //pHead只是表示头,不是有效内容
int nSize;
public:
JCSimpList() {
pHead = new JCListNode();
nSize = 0;
}
~JCSimpList() {
delete pHead;
pHead = 0;
nSize = 0;
}
int size() {
return nSize;
}
//这个不要了使用了。因为与stl的标准不一致。
JCListNode* getHead() {
return pHead;
}
//begin是有效值。除非整个list没有内容,那他等于end()
JCListNode* begin() {
return pHead->_Next;
}
//end是无效值。就是指向pHead
JCListNode* end() {
return pHead;
}
void push_back(JCListNode* pNode) {
JCListNode* pTail = pHead->_Prev;
if (pTail == pNode)
return;
pTail->_Next = pNode;
pNode->_Prev = pTail;
pNode->_Next = pHead;
pHead->_Prev = pNode;
nSize++;
}
JCListNode* pop_back() {
JCListNode* pTail = pHead->_Prev;
JCListNode* pPrev = pTail->_Prev;
//pnext = phead
pPrev->_Next = pHead;
pHead->_Prev = pPrev;
pTail->_Next = pTail;
pTail->_Prev = pTail;
nSize--;
if (nSize<0)nSize = 0;
return pTail;
}
void push_front(JCListNode* pNode) {
if (pNode == pHead->_Next)
return;
pNode->_Next = pHead->_Next;
pHead->_Next->_Prev = pNode;
pHead->_Next = pNode;
pNode->_Prev = pHead;
nSize++;
}
JCListNode* pop_front() {
JCListNode* pDel = pHead->_Next;
pDel->_Next->_Prev = pHead;
pHead->_Next = pDel->_Next;
pDel->_Prev = pDel;
pDel->_Next = pDel;
nSize--;
if (nSize<0)nSize = 0;
return pDel;
}
//返回下一个节点
JCListNode* delNode(JCListNode* pNode) {
if (pNode->notInChain())
return NULL;
JCListNode* pPrev = pNode->_Prev;
JCListNode* pNext = pNode->_Next;
pPrev->_Next = pNode->_Next;
pNext->_Prev = pNode->_Prev;
pNode->_Next = pNode;
pNode->_Prev = pNode;
nSize--;
if (nSize<0)nSize = 0;
return pNext;
}
void clear() {
}
};
struct JsObjClassInfo {
const char* ClassName;
const JsObjClassInfo* ParentClass;
const unsigned int ClsID;
void* objTemplate;
};
/*
js对象对应的c端对象。
所有导出给js的对象都要从这个继承
并且在创建和删除的时候进行管理
*/
class JSObjNode :public JCListNode {
public:
static JsObjClassInfo JSCLSINFO;
static JCSimpList* s_pListJSObj; //属于本线程的所有的js对象
JSObjNode();
virtual ~JSObjNode(); //这个会引入虚函数表,不知道有没有问题
const JsObjClassInfo* m_pClsInfo;// const char* m_pClassName;
//cls是不是从自己继承的
bool IsSubClass(JsObjClassInfo* cls) {
const JsObjClassInfo* cur = (const JsObjClassInfo*)cls;
while (cur) {
if (cur->ClsID == m_pClsInfo->ClsID)
return true;
cur = cur->ParentClass;
}
return false;
}
};
extern unsigned int gnJSClsID;
#define ADDJSCLSINFO(cls,par) JsObjClassInfo cls::JSCLSINFO = { #cls,&par::JSCLSINFO,gnJSClsID++,0 };
template<class T>
bool IsSubClass(JsObjClassInfo* cls) {
const JsObjClassInfo* cur = (const JsObjClassInfo*)cls;
while (cur) {
if (cur->ClsID == T::JSCLSINFO.ClsID)
return true;
cur = cur->ParentClass;
}
return false;
}
}
#endif
//-----------------------------END FILE--------------------------------
+49
View File
@@ -0,0 +1,49 @@
/**
@file JSLog.h
@brief
@author James
@version 1.0
@date 2013_11_12
*/
#ifndef __Log_H__
#define __Log_H__
#include <stdio.h>
#include <stdint.h>
#pragma warning(disable:4996)
#ifdef WIN32
#pragma execution_character_set("utf-8")
#endif
#ifdef __APPLE__
void CToObjectCLogI( const char* szFormat,...);
void CToObjectCLogW(const char* szFormat, ...);
void CToObjectCLogE(const char* szFormat, ...);
void CToObjectCLogIExt(const char* str);
#define LOGIExt(str) {CToObjectCLogIExt(str);}
#define LOGI(...) {CToObjectCLogI(__VA_ARGS__);}
#define LOGW(...) {CToObjectCLogW(__VA_ARGS__);}
#define LOGE(...) {CToObjectCLogE(__VA_ARGS__);}
#define TEST_WEBGLPLUS_LOG(...)
//#define TEST_WEBGLPLUS_LOG(...) {CToObjectCLogI(__VA_ARGS__);}
#elif ANDROID
#include <jni.h>
#include <android/log.h>
#define LOG_TAG "LayaBox"
#define LOGI(...) {__android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__);}
#define LOGW(...) {__android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__);}
#define LOGE(...) {__android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__);}
#define TEST_WEBGLPLUS_LOG(...)
//#define TEST_WEBGLPLUS_LOG(...) {__android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__);}
#elif WIN32
#define LOGI(...) { printf(__VA_ARGS__);printf("\n");}
#define LOGW(...) { printf(__VA_ARGS__);printf("\n");}
#define LOGE(...) { printf(__VA_ARGS__);printf("\n");}
#define TEST_WEBGLPLUS_LOG(...)
//#define TEST_WEBGLPLUS_LOG(...) { printf(__VA_ARGS__);printf("\n");}
#endif
#endif //__Log_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,137 @@
/**
@file JCArrayBufferManager.cpp
@brief
@author James
@version 1.0
@date 2017_11_29
*/
#include "JCArrayBufferManager.h"
#include "../Log.h"
namespace laya
{
JCArrayBufferManager::JCArrayBufferManager()
{
m_nGlobalID=1;
m_vPrepareDelIDs.reserve(1024);
}
JCArrayBufferManager::~JCArrayBufferManager()
{
clearAll();
}
void JCArrayBufferManager::clearAll()
{
for (int i = 0, n = m_vBuffers.size(); i < n; i++)
{
if (m_vBuffers[i])
{
delete m_vBuffers[i];
m_vBuffers[i] = NULL;
}
}
m_vBuffers.clear();
m_vPrepareDelIDs.clear();
m_nGlobalID = 1;
}
int JCArrayBufferManager::getID()
{
for (int i = 1, n = m_vBuffers.size(); i < n; i++)
{
if (m_vBuffers[i] == NULL)
{
return i;
}
}
return m_nGlobalID++;
}
void JCArrayBufferManager::removeArrayBuffer(int nID)
{
if ((size_t)nID < m_vBuffers.size())
{
if (m_vBuffers[nID])
{
delete m_vBuffers[nID];
m_vBuffers[nID] = NULL;
}
}
}
int JCArrayBufferManager::createArrayBuffer(char* pBuffer, int nLength,ARRAY_BUFFER_TYPE nType, ARRAY_BUFFER_REF_TYPE nRefType)
{
int nID = getID();
int nSize = m_vBuffers.size();
JCArrayBufferManager::ArrayBufferContent* pBufferContent = NULL;
if (nRefType == ARRAY_BUFFER_REF_TYPE_REFERENCE)
{
pBufferContent = new JCArrayBufferManager::ArrayBufferContent(pBuffer, nLength, nType, false);
}
else
{
pBufferContent = new JCArrayBufferManager::ArrayBufferContent(nType, true);
pBufferContent->mallocBuffer(pBuffer, nLength, nType);
}
if (nID == nSize)
{
m_vBuffers.push_back(pBufferContent);
}
else if (nID < nSize)
{
if (m_vBuffers[nID] != NULL)
{
LOGE("JCArrayBufferManager::createArrayBuffer error");
}
m_vBuffers[nID] = pBufferContent;
}
else
{
m_vBuffers.resize(nID + 1);
m_vBuffers[nID] = pBufferContent;
}
return nID;
}
bool JCArrayBufferManager::updateArrayBuffer(int nID, char* pBuffer, int nLength)
{
if ((size_t)nID >= m_vBuffers.size()) return false;
if (m_vBuffers[nID])
{
m_vBuffers[nID]->setBuffer(pBuffer, nLength);
return true;
}
else
{
LOGE("JCArrayBufferManager::updateArrayBuffer error");
return false;
}
return true;
}
bool JCArrayBufferManager::syncArrayBufferDataToRuntime(int nID, char* pBuffer, int nLength)
{
if ((size_t)nID >= m_vBuffers.size()) return false;
if (m_vBuffers[nID])
{
JCArrayBufferManager::ArrayBufferContent* pBufferContext = m_vBuffers[nID];
if (nLength == pBufferContext->m_nLength)
{
memcpy(pBufferContext->m_pBuffer, pBuffer, nLength);
}
else
{
LOGE("JCArrayBufferManager::syncArrayBufferDataToRuntime length error");
return false;
}
}
else
{
LOGE("JCArrayBufferManager::syncArrayBufferDataToRuntime error");
return false;
}
return true;
}
void JCArrayBufferManager::prepareRemoveArrayBuffer(int nID)
{
m_vPrepareDelIDs.push_back(nID);
}
}
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,217 @@
/**
@file JCArrayBufferManager.h
@brief
@author James
@version 1.0
@date 2017_11_29
*/
#ifndef __JCArrayBufferManager_H__
#define __JCArrayBufferManager_H__
#include "../buffer/JCCommandEncoderBuffer.h"
#include <vector>
#include <unordered_map>
namespace laya
{
class JCArrayBufferManager
{
public:
enum ARRAY_BUFFER_TYPE
{
ARRAY_BUFFER_TYPE_DATA,
ARRAY_BUFFER_TYPE_CMD,
};
enum ARRAY_BUFFER_REF_TYPE
{
ARRAY_BUFFER_REF_TYPE_REFERENCE,
ARRAY_BUFFER_REF_TYPE_COPY,
};
class ArrayBufferContent
{
public:
ArrayBufferContent(char* pBuffer, int nLength, ARRAY_BUFFER_TYPE nType,bool bNeedDelBuffer )
{
m_bNeedDelBuffer = bNeedDelBuffer;
m_nType = nType;
m_pBuffer = pBuffer;
m_nLength = nLength;
m_nNoteSize = 0;
m_pCommandEncoderBuffer = NULL;
if (m_nType == ARRAY_BUFFER_TYPE_CMD)
{
m_pCommandEncoderBuffer = new JCCommandEncoderBuffer(0, 0);
m_nNoteSize = *(int*)m_pBuffer;
if (m_nNoteSize > 0)
{
m_pCommandEncoderBuffer->setShareBuffer(m_pBuffer + 4, (m_nNoteSize - 1) * 4);
}
}
}
ArrayBufferContent(ARRAY_BUFFER_TYPE nType,bool bNeedDelBuffer )
{
m_bNeedDelBuffer = bNeedDelBuffer;
m_nType = nType;
m_pBuffer = NULL;
m_nLength = 0;
m_nNoteSize = 0;
m_pCommandEncoderBuffer = NULL;
if (m_nType == ARRAY_BUFFER_TYPE_CMD)
{
m_pCommandEncoderBuffer = new JCCommandEncoderBuffer(0, 0);
}
}
void mallocBuffer(char* pBuffer, int nLength, ARRAY_BUFFER_TYPE nType)
{
if (m_pBuffer)
{
delete m_pBuffer;
}
m_nLength = nLength;
m_pBuffer = new char[m_nLength];
memcpy(m_pBuffer, pBuffer, nLength);
if (m_nType == ARRAY_BUFFER_TYPE_CMD)
{
m_pCommandEncoderBuffer = new JCCommandEncoderBuffer(0, 0);
m_nNoteSize = *(int*)m_pBuffer;
if (m_nNoteSize > 0)
{
m_pCommandEncoderBuffer->setShareBuffer(m_pBuffer + 4, (m_nNoteSize - 1) * 4);
}
}
}
~ArrayBufferContent()
{
if (m_bNeedDelBuffer)
{
delete m_pBuffer;
m_pBuffer = NULL;
}
if (m_pCommandEncoderBuffer)
{
delete m_pCommandEncoderBuffer;
m_pCommandEncoderBuffer = NULL;
}
}
void syncContent(ArrayBufferContent* pContent)
{
if (m_pBuffer)
{
if (m_nLength == pContent->m_nLength)
{
memcpy(m_pBuffer, pContent->m_pBuffer, m_nLength);
}
else
{
delete m_pBuffer;
m_nLength = pContent->m_nLength;
m_pBuffer = new char[m_nLength];
memcpy(m_pBuffer, pContent->m_pBuffer, m_nLength);
}
}
else
{
m_nLength = pContent->m_nLength;
m_pBuffer = new char[m_nLength];
memcpy(m_pBuffer, pContent->m_pBuffer, m_nLength);
}
//同步MemClass
if (pContent->m_pCommandEncoderBuffer)
{
if (m_pCommandEncoderBuffer == NULL)
{
m_pCommandEncoderBuffer = new JCCommandEncoderBuffer(0, 0);
}
m_nNoteSize = *(int*)m_pBuffer;
if (m_nNoteSize > 0)
{
m_pCommandEncoderBuffer->setShareBuffer(m_pBuffer + 4, (m_nNoteSize - 1) * 4);
}
}
else
{
if (m_pCommandEncoderBuffer)
{
delete m_pCommandEncoderBuffer;
m_pCommandEncoderBuffer = NULL;
}
}
}
void setBuffer(char* pBuffer, int nLength)
{
m_pBuffer = pBuffer;
m_nLength = nLength;
if (m_pCommandEncoderBuffer)
{
m_nNoteSize = *(int*)m_pBuffer;
if (m_nNoteSize > 0)
{
m_pCommandEncoderBuffer->setShareBuffer(m_pBuffer + 4, (m_nNoteSize - 1) * 4);
}
}
}
JCCommandEncoderBuffer* getCommandEncoderBuffer()
{
if (*(int*)m_pBuffer != m_nNoteSize )
{
m_nNoteSize = *(int*)m_pBuffer;
if (m_nNoteSize > 0)
{
m_pCommandEncoderBuffer->setShareBuffer(m_pBuffer + 4, (m_nNoteSize - 1) * 4);
}
}
return m_pCommandEncoderBuffer;
}
public:
char* m_pBuffer;
int m_nLength;
bool m_bNeedDelBuffer;
ARRAY_BUFFER_TYPE m_nType;
public:
int m_nNoteSize; //记录buffer中的第0个值,为了快速判断用
JCCommandEncoderBuffer* m_pCommandEncoderBuffer; //为了解流使用
};
typedef std::vector<ArrayBufferContent*> VectorBuffer;
public:
JCArrayBufferManager();
~JCArrayBufferManager();
void clearAll();
inline ArrayBufferContent* getArrayBuffer(int nID)
{
return nID < m_vBuffers.size() ? m_vBuffers[nID] : NULL;
}
int getID();
void removeArrayBuffer(int nID);
int createArrayBuffer(char* pBuffer, int nLength, ARRAY_BUFFER_TYPE nType, ARRAY_BUFFER_REF_TYPE nRefType);
bool updateArrayBuffer(int nID, char* pBuffer, int nLength);
bool syncArrayBufferDataToRuntime(int nID, char* pBuffer, int nLength);
void prepareRemoveArrayBuffer(int nID);
public:
int m_nGlobalID;
VectorBuffer m_vBuffers;
std::vector<int> m_vPrepareDelIDs;
};
}
//------------------------------------------------------------------------------
#endif //__JCArrayBufferManager_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,76 @@
/**
@file JCCommandEncoderBuffer.cpp
@brief
@author James
@version 1.0
@date 2019_8_24
*/
#include "JCCommandEncoderBuffer.h"
namespace laya
{
JCCommandEncoderBuffer::JCCommandEncoderBuffer( unsigned int nSize, unsigned int nAdjustSize)
{
m_bNeedDelBuffer = true;
m_pBuffer=NULL;
m_nBufSize=0;
m_nDataSize=0;
m_nAdjustSize= nAdjustSize;
m_nReadPos=0;
m_bChanged=true;
if (nSize > 0)
{
expand(nSize);
}
}
JCCommandEncoderBuffer::~JCCommandEncoderBuffer()
{
if ( m_bNeedDelBuffer && m_pBuffer )
{
delete[] m_pBuffer;
m_pBuffer = 0;
}
}
void JCCommandEncoderBuffer::setBufferExpandStep(int nAdjustSize)
{
m_nAdjustSize = nAdjustSize;
}
void JCCommandEncoderBuffer::setAlign(bool bAlign)
{
m_bAlign = bAlign;
}
void JCCommandEncoderBuffer::setBufferSize(int nBufferSize)
{
if (nBufferSize < 0)
{
return;
}
if (nBufferSize >= (int)m_nBufSize)
{
expand(nBufferSize - m_nBufSize);
}
}
void JCCommandEncoderBuffer::expand(int nExpandSize)
{
if (nExpandSize<1 ) return;
unsigned long nSize= nExpandSize+m_nBufSize+m_nAdjustSize; //ÐèÒª°´4¶ÔÆëô
char* pBuf=new char[nSize];
if (!pBuf)
{
return;
}
if (m_pBuffer)
{
memcpy(pBuf, m_pBuffer,m_nBufSize);
delete [] m_pBuffer;
}
m_nBufSize=nSize;
m_pBuffer=pBuf;
m_bChanged=true;
}
};
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,351 @@
/**
@file JCCommandEncoderBuffer.h
@brief
@author James
@version 1.0
@date 2019_8_24
*/
#ifndef __JCCommandEncoderBuffer_H__
#define __JCCommandEncoderBuffer_H__
#include <memory>
namespace laya
{
/**
* @brief 内存快速的buffer操作
*/
class JCCommandEncoderBuffer
{
public:
/** @brief 构造函数
* @param[in] 初始化size的大小
* @param[in] 当大小不够的时候,每次增加的大小
*/
JCCommandEncoderBuffer( unsigned int nSize,unsigned int nAdjustSize);
/** @brief 析构函数
*/
~JCCommandEncoderBuffer();
/** @brief 设置每次扩充buffer的size
* @param[in] 扩充的size
*/
void setBufferExpandStep(int nAdjustSize);
/** @brief 是否需要对其
* @param[in] 是否需要对其
*/
void setAlign(bool bAlign);
/** @brief 获得buffer
* @return 返回buffer
*/
char* getBuffer()
{
return m_pBuffer;
}
/** @brief 获得读取到当前的位置
* @return 返回buffer的指针
*/
char* getReadPtr()
{
if( m_nReadPos>= m_nDataSize )
return 0;
else
return m_pBuffer+m_nReadPos;
}
/** @brief 设置buffer的大小。只分配空间,但是getDataSize依然是原来的值
* @param[in] 要设置的大小
*/
void setBufferSize(int nBufferSize);
/** @brief 读取buffer,注意:不是4字节对其
* @param[in] 需要传入读取的长度
* @return 返回buffer指针
*/
char* readBuffer(int nLength)
{
char* pRet = m_pBuffer + m_nReadPos;
m_nReadPos += nLength;
return pRet;
}
/** @brief 读取buffer4字节对其
* @param[in] 需要传入读取的长度
* @return 返回buffer指针
*/
char* readBufferAlign(int nLength)
{
nLength = alignValue(nLength);
char* pRet = m_pBuffer + m_nReadPos;
m_nReadPos += nLength;
return pRet;
}
/** @brief 从当前读指针返回一个对象指针。并且前进,注意:不是4字节对其
*/
template<class T>
T* popp()
{
T* ret = (T*)(m_pBuffer+m_nReadPos);
m_nReadPos+=sizeof(T);
return ret;
}
/** @brief 从当前读指针返回一个对象指针。并且前进。(4对齐)
*/
template<class T>
T* poppAlign()
{
T* ret = (T*)(m_pBuffer + m_nReadPos);
m_nReadPos += alignValue(sizeof(T));
return ret;
}
/** @brief 获得数据长度
* @return 返回数据长度大小
*/
unsigned int getDataSize()
{
return m_nDataSize;
}
/** @brief append 数据,比如一个结构体,注意不是4字节对其
* @param[in] 数据
*/
template<class T>
void append(T& v)
{
int size = sizeof(T);
expand(m_nDataSize+size-m_nBufSize);
*(T*)(m_pBuffer+m_nDataSize)=v;
m_nDataSize+=size;
m_bChanged=true;
}
/** @brief append 数据,比如一个结构体
* @param[in] 数据
*/
template<class T>
void appendAlign(T& v)
{
int size = alignValue(sizeof(T));
expand(m_nDataSize + size - m_nBufSize);
*(T*)(m_pBuffer + m_nDataSize) = v;
m_nDataSize += size;
m_bChanged = true;
}
/** @brief append一个int值
* @param[in] int值
*/
void append(int v)
{
expand(m_nDataSize+sizeof(int)-m_nBufSize);
*(int*)(m_pBuffer+m_nDataSize)=v;
m_nDataSize+=sizeof(int);
m_bChanged=true;
}
/** @brief append一个long值
* @param[in] long值
*/
void append(long v)
{
expand(m_nDataSize + sizeof(long) - m_nBufSize);
*(long*)(m_pBuffer + m_nDataSize) = v;
m_nDataSize += sizeof(long);
m_bChanged = true;
}
void appendInt(int v)
{
expand(m_nDataSize + sizeof(int) - m_nBufSize);
*(int*)(m_pBuffer + m_nDataSize) = v;
m_nDataSize += sizeof(int);
m_bChanged = true;
}
void appendFloat(float v)
{
expand(m_nDataSize + sizeof(float) - m_nBufSize);
*(float*)(m_pBuffer + m_nDataSize) = v;
m_nDataSize += sizeof(float);
m_bChanged = true;
}
/** @brief append buffer函数
* @param[in] buffer指针
* @param[in] buffer大小
*/
char* append(const void* pBufffer, int nSize)
{
if (!pBufffer) return NULL;
int alignedsz = alignValue(nSize);
expand(m_nDataSize + alignedsz - m_nBufSize);
char* pLastBuffer = m_pBuffer + m_nDataSize;
memcpy(m_pBuffer + m_nDataSize, pBufffer, nSize);
m_nDataSize += alignedsz;
m_bChanged = true;
return pLastBuffer;
}
/** @brief 假装添加数据,其实就是修改数据大小。如果调用者希望直接针对指针修改数据,通过这个来通知buffer 数据已经改变了。
* @param[in] sz 大小,字节。
* @return 扩展前的位置。
*/
void* appendEmpty(int nSize)
{
expand(m_nDataSize + nSize - m_nBufSize);
void* oldpos = m_pBuffer + m_nDataSize;
m_nDataSize += nSize;
m_bChanged = true;
return oldpos;
}
/** @brief 假装添加数据,其实就是修改数据大小。如果调用者希望直接针对指针修改数据,通过这个来通知buffer 数据已经改变了。
* @param[in] sz 大小,字节。
* @return 扩展前的位置。
*/
void* appendEmptyAlign(int nSize)
{
int alignedsz = alignValue(nSize);
expand(m_nDataSize + alignedsz - m_nBufSize);
void* oldpos = m_pBuffer + m_nDataSize;
m_nDataSize += nSize;
m_bChanged = true;
return oldpos;
}
/*
* 慎用,只有非常明白的人才可以使用
*/
void _setDataSize(int nSize)
{
m_nDataSize = nSize;
}
/** @brief 清空数据,但是不删除buffer
* @return
*/
inline void clearData()
{
m_nDataSize=m_nReadPos=0;
}
/** @brief 是否为Emplty,如果没有数据,就认为是null
* @return
*/
inline bool isEmpty()
{
return m_nDataSize==0;
}
/** @brief 设置内容是否改变
* @param[in] 是否改变
*/
inline void setChangedFlag(bool bChanged)
{
m_bChanged = bChanged;
};
/** @brief 获得内容是否改变了
* @return
*/
inline bool getChangedFlag()
{
return m_bChanged;
}
/** @brief 设置读取read的pos
* @param[in] pos
*/
inline void setReadPos(int nPos)
{
m_nReadPos = nPos;
}
/** @brief 设置写入的数据的位置,也就是相当于data的size
* @param[in] 输入size
*/
inline void setWritePos(int nSize)
{
m_nDataSize = nSize;
}
public:
void setExternalBuffer( char* pBuffer,int nSize )
{
m_pBuffer = pBuffer;
m_nDataSize = m_nBufSize = nSize;
m_nReadPos = 0;
}
void setShareBuffer(char* pBuffer, int nSize)
{
m_pBuffer = pBuffer;
m_nDataSize = m_nBufSize = nSize;
m_nReadPos = 0;
m_bNeedDelBuffer = false;
}
unsigned int getReadPos()
{
return m_nReadPos;
}
char* getCurrentWriteBuffer()
{
return m_pBuffer + m_nDataSize;
}
private:
/** @brief 返回bufferSize
* @return 返回buffer数据大小
*/
unsigned int getBuffSize()
{
return m_nBufSize;
}
/** @brief 扩充buffer
* @param[in] 需要扩充的size
*/
void expand(int nExpandSize);
/** @brief 对其数据函数
* @param[in] 输入的值
* @return 获得对其后的值
*/
inline int alignValue(int nValue)
{
return m_bAlign ? (nValue + 3) & 0xfffffffc : nValue;
}
private:
char* m_pBuffer; ///<buffer
unsigned int m_nBufSize; ///<buffer的总大小,内存开辟的空间大小
unsigned int m_nDataSize; ///<里面数据的总大小,buffer中的真实数据大小
unsigned int m_nReadPos; ///<当前读取的位置
unsigned int m_nAdjustSize; ///<每次扩容的时候,增加的大小
bool m_bChanged; ///<内容是否发生了改变
bool m_bNeedDelBuffer; ///<是否需要删除buffer
public:
bool m_bAlign = true;
};
};
//------------------------------------------------------------------------------
#endif //__JCCommandEncoderBuffer_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,51 @@
/**
@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"
#include "JSCUtil.h"
namespace laya
{
void JCWebGLPlus::exportJS(void* ctx, void* object)
{
JSWebGLPlus::getInstance()->exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSArrayBufferRef::exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSFloatKeyframe::exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSFloatArrayKeyframe::exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSKeyframeNode::exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSKeyframeNodeList::exportJS((JSContextRef)ctx, (JSObjectRef)object);
}
void JCWebGLPlus::clean()
{
//JSWebGLPlus::getInstance()->releaseInstance();
JSCBinder<JSWebGLPlus>::ReleaseInstance();
JSCBinder<JSArrayBufferRef>::ReleaseInstance();
JSCBinder<JSFloatKeyframe>::ReleaseInstance();
JSCBinder<JSFloatArrayKeyframe>::ReleaseInstance();
JSCBinder<JSKeyframeNode>::ReleaseInstance();
JSCBinder<JSKeyframeNodeList>::ReleaseInstance();
}
void JCWebGLPlus::clearAll()
{
m_pJSArrayBufferManager->clearAll();
m_pJSABManagerSyncToRender->clearAll();
m_pRArrayBufferManager->clearAll();
clean();
}
}
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,81 @@
/**
@file JSArrayBufferRef.cpp
@brief
@author James
@version 1.0
@date 2017_11_29
*/
#include "JSArrayBufferRef.h"
#include "../JCWebGLPlus.h"
#include "JSCUtil.h"
namespace laya
{
//ADDJSCLSINFO(JSArrayBufferRef, JSObjNode);
JSArrayBufferRef::JSArrayBufferRef()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
m_nID = 0;
m_bSyncToRender = false;
}
JSArrayBufferRef::~JSArrayBufferRef()
{
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 JSValueRef _GetID(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSArrayBufferRef* self = (JSArrayBufferRef*)JSObjectGetPrivate(object);
int v = self->getID();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef IsSyncToRender(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSArrayBufferRef *pObj = (JSArrayBufferRef*)JSObjectGetPrivate(thisObject);
bool value = pObj->getIsSyncToRender();
return JSValueMakeBoolean(ctx, value);
}
void JSArrayBufferRef::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSArrayBufferRef>* binder = JSCBinder<JSArrayBufferRef>::GetInstance();
binder->begin(ctx);
binder->addProperty("id", _GetID);
binder->addMethod("isSyncToRender", IsSyncToRender);
binder->end(object, "ArrayBufferRef");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,48 @@
/**
@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 <JavaScriptCore/JavaScriptCore.h>
/**
* @brief
*/
namespace laya
{
class JSArrayBufferRef : public JCListNode
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSArrayBufferRef();
~JSArrayBufferRef();
void callManagerRemoveArrayBuffer();
int getID();
bool getIsSyncToRender();
public:
int m_nID;
bool m_bSyncToRender;
};
}
//------------------------------------------------------------------------------
#endif //__JSArrayBufferRef_H__
//-----------------------------END FILE--------------------------------
+64
View File
@@ -0,0 +1,64 @@
/**
@file JSCUtil.cpp
@brief
@author James
@version 1.0
@date 2017_11_29
*/
#include "JSCUtil.h"
#include <JavaScriptCore/JavaScriptCore.h>
#include <vector>
namespace laya
{
JSContextRef JSCUtil::s_ctx = NULL;
char* JSCUtil::toCString(JSContextRef ctx,JSStringRef value)
{
int len = JSStringGetMaximumUTF8CStringSize(value);
static std::vector<char> utf8str;
utf8str.resize(len);
JSStringGetUTF8CString(value, &utf8str[0], len);
return &utf8str[0];
}
char* JSCUtil::toCString(JSContextRef ctx,JSValueRef value)
{
assert(JSValueIsString(ctx, value));
JSStringRef str = JSValueToStringCopy(ctx, value, nullptr);
char* ret = toCString(ctx, str);
JSStringRelease(str);
return ret;
}
bool JSCUtil::extractJSAB(JSContextRef ctx,JSValueRef ab, char*& data, int& len)
{
JSObjectRef arrayObj = JSValueToObject(ctx, ab, NULL);
JSTypedArrayType arrayType = JSValueGetTypedArrayType(ctx, ab, NULL);
switch (arrayType)
{
case kJSTypedArrayTypeNone:
{
data = NULL;
len = 0;
return false;
}
break;
case kJSTypedArrayTypeArrayBuffer:
{
data = (char*)JSObjectGetArrayBufferBytesPtr(ctx, arrayObj, NULL);
len = (int)JSObjectGetArrayBufferByteLength(ctx, arrayObj, NULL);
return true;
}
break;
default:
{
data = (char*)JSObjectGetTypedArrayBytesPtr(ctx, arrayObj, NULL) + JSObjectGetTypedArrayByteOffset(ctx, arrayObj, NULL);
len = (int)JSObjectGetTypedArrayByteLength(ctx, arrayObj, NULL);
return true;
}
break;
}
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
+344
View File
@@ -0,0 +1,344 @@
#ifndef _JSCUtil_h
#define _JSCUtil_h
#include <unordered_map>
#include <string>
#include <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSCUtil
{
public:
static JSContextRef s_ctx;
static bool extractJSAB(JSContextRef ctx,JSValueRef jsval, char*& data, int& len);
static char* toCString(JSContextRef ctx,JSValueRef value);
static char* toCString(JSContextRef ctx,JSStringRef value);
};
template<typename T>
class JSCBinder
{
public:
inline unsigned int __hash_BKDR(const char *p_str)
{
if(0 == p_str)
return 0;
unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
unsigned int hash = 0;
for(;0!=*p_str;)
{
hash = hash * seed + (*p_str++);
}
return (hash & 0x7FFFFFFF);
}
JSCBinder()
{
m_bIsGlobal = false;
m_ClassDefine = kJSClassDefinitionEmpty;
m_ClassObject = nullptr;
m_iTypeID = __hash_BKDR(typeid(T).name());
}
~JSCBinder()
{
_reset();
}
unsigned int getTypeID()
{
return m_iTypeID;
}
void addProperty(const std::string& name, JSObjectGetPropertyCallback getter, JSObjectSetPropertyCallback setter = NULL)
{
assert(!name.empty());
if (getter)
{
GetPropertyMapRes rs = m_GetPropertyMap.insert(GetPropertyMapValue(name, getter));
assert(rs.second);
}
if (setter)
{
SetPropertyMapRes rs = m_SetPropertyMap.insert(SetPropertyMapValue(name, setter));
assert(rs.second);
}
}
void begin(JSContextRef ctx)
{
JSCUtil::s_ctx = ctx;
}
void addMethod(const std::string& name, JSObjectCallAsFunctionCallback method)
{
JSStringRef pName = JSStringCreateWithUTF8CString(name.c_str());
JSContextRef pCtx = JSCUtil::s_ctx;
JSValueRef callAsFunction = JSObjectMakeFunctionWithCallback(pCtx, pName, method);
JSStringRelease(pName);
JSValueProtect(pCtx, callAsFunction);
FunctionMapRes rsf = m_FunctionMap.insert(FunctionMapValue(name, callAsFunction));
assert(rsf.second);
}
void end(JSObjectRef object, const std::string& name)
{
m_bIsGlobal = false;
endImpl(object, name, nullptr);
}
void endToGlobal(JSObjectRef object, const std::string& name, T* pIns)
{
assert(pIns != nullptr);
m_bIsGlobal = false;
endImpl(object, name, pIns);
m_bIsGlobal = true;
}
JSObjectRef transferObjPtrToJS(JSContextRef pCtx, T* p_pIns)
{
assert( !m_bIsGlobal );
JSObjectRef pRet = JSObjectMake(pCtx, m_ClassObject, p_pIns);
JSValueRef pProperty = JSValueMakeNumber(pCtx, (double)getTypeID());
JSStringRef pszName = JSStringCreateWithUTF8CString("jsc__cppclstypeid");
JSObjectSetProperty(pCtx, pRet, pszName, pProperty, kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete, 0);
JSStringRelease(pszName);
return pRet;
}
static JSCBinder<T>* GetInstance()
{
if (!s_instance)
{
s_instance = new JSCBinder<T>();
}
return s_instance;
}
static void ReleaseInstance()
{
if (s_instance)
{
delete s_instance;
s_instance = NULL;
}
}
private:
static JSObjectRef newWrap(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if( JSCBinder<T>::GetInstance()->m_bIsGlobal )
{
return NULL;
}
return JSCBinder<T>::GetInstance()->transferObjPtrToJS(ctx, new T);
}
static void destroyWrap(JSObjectRef object)
{
T *p = (T *)JSObjectGetPrivate(object);
delete p;
}
static bool isInstanceOf(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
{
if(!JSValueIsObject(ctx, possibleInstance))
{
return false;
}
JSObjectRef p_pObj = JSValueToObject(ctx, possibleInstance ,NULL);
JSStringRef pszName = JSStringCreateWithUTF8CString("jsc__cppclstypeid");
JSValueRef pProperty = JSObjectGetProperty(ctx, p_pObj, pszName, 0);
JSStringRelease(pszName);
if(0 == pProperty)
{
return false;
}
else
{
int nID = (int)JSValueToNumber(ctx,pProperty, 0);
return (nID == (JSCBinder<T>::GetInstance()->getTypeID()));
}
}
static bool hasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
{
char* strPropertyName = JSCUtil::toCString(ctx, propertyName);
if (JSCBinder<T>::GetInstance()->findFunction(strPropertyName))
{
return true;
}
if (JSCBinder<T>::GetInstance()->findGetProperty(strPropertyName))
{
return true;
}
if (JSCBinder<T>::GetInstance()->findSetProperty(strPropertyName))
{
return true;
}
return false;
}
static JSValueRef getProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
T* pThis = (T*)JSObjectGetPrivate(object);
if(NULL == pThis )
{
return NULL;
}
char* strPropertyName = JSCUtil::toCString(ctx, propertyName);
JSObjectGetPropertyCallback callAsFunction = JSCBinder<T>::GetInstance()->findGetProperty(strPropertyName);
if(callAsFunction)
{
return callAsFunction(ctx, object, propertyName, exception);
}
return JSCBinder<T>::GetInstance()->findFunction(strPropertyName);
}
static bool setProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
T* pThis = (T*)JSObjectGetPrivate(object);
if(0 == pThis)
{
return false;
}
char* strPropertyName = JSCUtil::toCString(ctx, propertyName);
JSObjectSetPropertyCallback callAsFunction = JSCBinder<T>::GetInstance()->findSetProperty(strPropertyName);
if( NULL == callAsFunction)
{
return false;
}
JSValueRef arguments[1];
arguments[0] = value;
callAsFunction(ctx, object, propertyName, value, exception);
return true;
}
private:
void _reset()
{
JSContextRef ctx = JSCUtil::s_ctx;
for (FunctionMapItr itr = m_FunctionMap.begin(); itr != m_FunctionMap.end(); itr++)
{
JSValueUnprotect(ctx, itr->second);
}
m_FunctionMap.clear();
m_SetPropertyMap.clear();
m_GetPropertyMap.clear();
m_bIsGlobal = false;
m_ClassDefine = kJSClassDefinitionEmpty;
if (m_ClassObject != nullptr)
{
JSClassRelease(m_ClassObject);
m_ClassObject = nullptr;
}
}
void endImpl(JSObjectRef object, const std::string& name, T *p_pIns)
{
assert(!name.empty());
m_ClassDefine = kJSClassDefinitionEmpty;
m_ClassDefine.attributes = kJSClassAttributeNone;
m_ClassDefine.className = name.c_str();
m_ClassDefine.callAsConstructor = JSCBinder<T>::newWrap;
m_ClassDefine.finalize = JSCBinder<T>::destroyWrap;
m_ClassDefine.hasProperty = JSCBinder<T>::hasProperty;
m_ClassDefine.hasInstance = JSCBinder<T>::isInstanceOf;
m_ClassDefine.getProperty = JSCBinder<T>::getProperty;
m_ClassDefine.setProperty = JSCBinder<T>::setProperty;
//m_ClassDefine.callAsFunction = JSCBinder<T>::callAsFunctionCallback;
m_ClassObject = JSClassCreate(&m_ClassDefine);
JSContextRef pCtx = JSCUtil::s_ctx;
JSStringRef jsName = JSStringCreateWithUTF8CString(name.c_str());
JSObjectRef myObject;
if( 0 != p_pIns )
{
myObject = transferObjPtrToJS(pCtx, p_pIns);
}
else
{
myObject = JSObjectMake(pCtx, m_ClassObject, 0);
}
JSObjectSetProperty( pCtx, object, jsName, myObject, kJSPropertyAttributeNone, NULL );
JSStringRelease(jsName);
}
JSValueRef findFunction(const std::string& name)
{
FunctionMapItr iter = m_FunctionMap.find(name);
if(iter == m_FunctionMap.end())
{
return nullptr;
}
else
{
return (*iter).second;
}
}
JSObjectGetPropertyCallback findGetProperty(const std::string& name)
{
GetPropertyMapItr iter = m_GetPropertyMap.find(name);
if(iter == m_GetPropertyMap.end())
{
return nullptr;
}
else
{
return (*iter).second;
}
}
JSObjectSetPropertyCallback findSetProperty(const std::string& name)
{
SetPropertyMapItr iter = m_SetPropertyMap.find(name);
if(iter == m_SetPropertyMap.end())
{
return nullptr;
}
else
{
return (*iter).second;
}
}
private:
typedef std::unordered_map<std::string, JSObjectGetPropertyCallback> GetPropertyMap;
typedef typename GetPropertyMap::value_type GetPropertyMapValue;
typedef typename GetPropertyMap::iterator GetPropertyMapItr;
typedef std::pair<GetPropertyMapItr, bool> GetPropertyMapRes;
GetPropertyMap m_GetPropertyMap;
typedef std::unordered_map<std::string, JSObjectSetPropertyCallback> SetPropertyMap;
typedef typename SetPropertyMap::value_type SetPropertyMapValue;
typedef typename SetPropertyMap::iterator SetPropertyMapItr;
typedef std::pair<SetPropertyMapItr, bool> SetPropertyMapRes;
SetPropertyMap m_SetPropertyMap;
typedef std::unordered_map<std::string, JSValueRef> FunctionMap;
typedef typename FunctionMap::value_type FunctionMapValue;
typedef typename FunctionMap::iterator FunctionMapItr;
typedef std::pair<FunctionMapItr, bool> FunctionMapRes;
FunctionMap m_FunctionMap;
bool m_bIsGlobal;
JSClassDefinition m_ClassDefine;
JSClassRef m_ClassObject;
unsigned int m_iTypeID;
static JSCBinder<T>* s_instance;
};
template<typename T> JSCBinder<T>* JSCBinder<T>::s_instance = NULL;
}
#endif
@@ -0,0 +1,138 @@
/**
@file JSFloatArrayKeyframe.cpp
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#include "JSFloatArrayKeyframe.h"
#define NDEBUG
#include <assert.h>
#include "JSCUtil.h"
namespace laya
{
//ADDJSCLSINFO(JSFloatArrayKeyframe, JSObjNode);
//------------------------------------------------------------------------------
JSFloatArrayKeyframe::JSFloatArrayKeyframe()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
//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 JSValueRef SetInTangent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
pObj->m_nInTangent.data = pArrayBuffer;
pObj->m_nInTangent.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetOutTangent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
pObj->m_nOutTangent.data = pArrayBuffer;
pObj->m_nOutTangent.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetValue(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
pObj->m_nValue.data = pArrayBuffer;
pObj->m_nValue.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetData(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
pObj->m_pData.data = pArrayBuffer;
pObj->m_pData.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetTime(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe* pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
float value = JSValueToNumber(ctx, arguments[0], 0);
pObj->setTime(value);
return JSValueMakeUndefined(ctx);
}
static JSValueRef GetTime(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
float value = pObj->getTime();
return JSValueMakeNumber(ctx, value);
}
void JSFloatArrayKeyframe::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSFloatArrayKeyframe>* binder = JSCBinder<JSFloatArrayKeyframe>::GetInstance();
binder->begin(ctx);
binder->addMethod("setTime", SetTime);
binder->addMethod("getTime", GetTime);
binder->addMethod("setInTangent", SetInTangent);
binder->addMethod("setOutTangent", SetOutTangent);
binder->addMethod("setValue", SetValue);
binder->addMethod("setData", SetData);
binder->end(object, "_conchFloatArrayKeyframe");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,38 @@
/**
@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 <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSFloatArrayKeyframe : public JCFloatArrayKeyframe, public JCListNode
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSFloatArrayKeyframe();
~JSFloatArrayKeyframe();
};
}
//------------------------------------------------------------------------------
#endif //__JSFloatArrayKeyframe_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,136 @@
/**
@file JSFloatKeyframe.cpp
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#include "JSFloatKeyframe.h"
#include "JSCUtil.h"
namespace laya
{
//ADDJSCLSINFO(JSFloatKeyframe, JSObjNode);
//------------------------------------------------------------------------------
JSFloatKeyframe::JSFloatKeyframe()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
/*m_nTime = 0;
m_nInTangent = 0;
m_nOutTangent = 0;
m_nValue = 0;
AdjustAmountOfExternalAllocatedMemory(16);
JCMemorySurvey::GetInstance()->newClass("conchFloatKeyframe", 16, this);*/
}
JSFloatKeyframe::~JSFloatKeyframe()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->delNode(this);
}
//JCMemorySurvey::GetInstance()->releaseClass("conchFloatKeyframe", this);
}
static JSValueRef Clone(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(thisObject);
JSFloatKeyframe* pKeyframe = new JSFloatKeyframe();
self->_cloneTo(pKeyframe);
return JSCBinder<JSFloatKeyframe>::GetInstance()->transferObjPtrToJS(ctx, pKeyframe);
}
static JSValueRef CloneTo(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(thisObject);
JSValueRef destObj = arguments[0];
if (JSValueIsObject(ctx, destObj))
{
JSFloatKeyframe* pKeyFrame = (JSFloatKeyframe*)JSObjectGetPrivate(JSValueToObject(ctx, destObj, NULL));
if (pKeyFrame)
{
self->_cloneTo(pKeyFrame);
}
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef _GetTime(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
float v = self->getTime();
return JSValueMakeNumber(ctx, v);
}
static bool _SetTime(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
float v = JSValueToNumber(ctx, value, 0);
self->setTime(v);
return true;
}
static JSValueRef _GetInTangent(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
float v = self->getInTangent();
return JSValueMakeNumber(ctx, v);
}
static bool _SetInTangent(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
float v = JSValueToNumber(ctx, value, 0);
self->setInTangent(v);
return true;
}
static JSValueRef _GetOutTangent(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
float v = self->getOutTangent();
return JSValueMakeNumber(ctx, v);
}
static bool _SetOutTangent(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
float v = JSValueToNumber(ctx, value, 0);
self->setOutTangent(v);
return true;
}
static JSValueRef _GetValue(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
float v = self->getValue();
return JSValueMakeNumber(ctx, v);
}
static bool _SetValue(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
float v = JSValueToNumber(ctx, value, 0);
self->setValue(v);
return true;
}
void JSFloatKeyframe::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSFloatKeyframe>* binder = JSCBinder<JSFloatKeyframe>::GetInstance();
binder->begin(ctx);
binder->addProperty("time", _GetTime, _SetTime);
binder->addProperty("inTangent", _GetInTangent, _SetInTangent);
binder->addProperty("outTangent", _GetOutTangent, _SetOutTangent);
binder->addProperty("value", _GetValue, _SetValue);
binder->addMethod("clone", Clone);
binder->addMethod("cloneTo", CloneTo);
binder->end(object, "conchFloatKeyframe");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,38 @@
/**
@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 <JavaScriptCore/JavaScriptCore.h>
#include <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSFloatKeyframe : public JCListNode, public JCFloatKeyframe
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSFloatKeyframe();
~JSFloatKeyframe();
};
}
//------------------------------------------------------------------------------
#endif //__JSFloatKeyframe_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,406 @@
/**
@file JSKeyframeNode.cpp
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#include "JSKeyframeNode.h"
#define NDEBUG
#include <assert.h>
#include "JSCUtil.h"
namespace laya
{
std::string JCKeyframeNode::s_sTempString = "";//TODO
//ADDJSCLSINFO(JSKeyframeNode, JSObjNode);
//------------------------------------------------------------------------------
JSKeyframeNode::JSKeyframeNode()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
/*m_nIndexInList = 0;
m_nType = 0;
m_nDataType = 0;
m_pDataFloat = 0;
AdjustAmountOfExternalAllocatedMemory(4096);
JCMemorySurvey::GetInstance()->newClass("JSKeyframeNode", 4096, this);*/
}
//------------------------------------------------------------------------------
JSKeyframeNode::~JSKeyframeNode()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->delNode(this);
}
/* m_vOwnerPath.clear();
m_vPropertys.clear();
m_vKeyFrames.clear();
JCMemorySurvey::GetInstance()->releaseClass("JSKeyframeNode", this); */
}
static JSValueRef SetFloat32ArrayData(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
self->m_pDataFloatArray.data = pArrayBuffer;
self->m_pDataFloatArray.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetOwnerPathCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
self->_setOwnerPathCount(index);
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetOwnerPathByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
self->_setOwnerPathByIndex(index, JSCUtil::toCString(ctx, arguments[1]));
return JSValueMakeUndefined(ctx);
}
static JSValueRef JoinOwnerPath(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
const char* v = self->_joinOwnerPath(JSCUtil::toCString(ctx, arguments[0]));
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static JSValueRef SetPropertyCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
self->_setPropertyCount(index);
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetPropertyByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
self->_setPropertyByIndex(index, JSCUtil::toCString(ctx, arguments[1]));
return JSValueMakeUndefined(ctx);
}
static JSValueRef JoinProperty(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
const char* v = self->_joinProperty(JSCUtil::toCString(ctx, arguments[0]));
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static JSValueRef SetKeyframeByIndex0(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
JSValueRef keyframe = arguments[1];
if (JSValueIsObject(ctx, keyframe))
{
JSFloatKeyframe* pNode = (JSFloatKeyframe*)JSObjectGetPrivate(JSValueToObject(ctx, keyframe, NULL));
if (pNode)
{
self->m_vKeyFrames[index] = pNode;
}
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetKeyframeByIndex1(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
JSValueRef keyframe = arguments[1];
if (JSValueIsObject(ctx, keyframe))
{
JSFloatArrayKeyframe* pNode = (JSFloatArrayKeyframe*)JSObjectGetPrivate(JSValueToObject(ctx, keyframe, NULL));
if (pNode)
{
self->m_vKeyFrames[index] = pNode;
}
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetKeyframeCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int value = JSValueToNumber(ctx, arguments[0], 0);
self->_setKeyframeCount(value);
return JSValueMakeUndefined(ctx);
}
static JSValueRef GetOwnerPathByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
const char* v = self->getOwnerPathByIndex(index);
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static JSValueRef GetPropertyByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
const char* v = self->getPropertyByIndex(index);
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static JSValueRef GetKeyframeByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
return JSValueMakeNull(ctx);
}
static JSValueRef GetFloatData(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode *pObj = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
float v = pObj->getFloatData();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef GetDataType(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode *pObj = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
int v = pObj->getDataType();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef GetKeyFramesCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
int v = self->getKeyFramesCount();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef GetOwnerPathCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
int v = self->getOwnerPathCount();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef GetPropertyCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
laya::JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
int v = self->getPropertyCount();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef _GetIndexInList(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getIndexInList();
return JSValueMakeNumber(ctx, v);
}
static bool _SetIndexInList(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->setIndexInList(v);
return true;
}
static JSValueRef _GetType(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getType();
return JSValueMakeNumber(ctx, v);
}
static bool _SetType(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->setType(v);
return true;
}
static JSValueRef _GetOwnerPathCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getOwnerPathCount();
return JSValueMakeNumber(ctx, v);
}
static bool _SetOwnerPathCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->_setOwnerPathCount(v);
return true;
}
static JSValueRef _GetKeyFramesCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getKeyFramesCount();
return JSValueMakeNumber(ctx, v);
}
static bool _SetKeyframeCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->_setKeyframeCount(v);
return true;
}
static JSValueRef _GetPropertyCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getPropertyCount();
return JSValueMakeNumber(ctx, v);
}
static bool _SetPropertyCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->_setPropertyCount(v);
return true;
}
static JSValueRef _GetPropertyOwner(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
const char* v = self->getPropertyOwner();
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static bool _SetPropertyOwner(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
self->setPropertyOwner(JSCUtil::toCString(ctx, value));
return true;
}
static JSValueRef _GetFullPath(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
const char* v = self->getFullPath();
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static bool _SetFullPath(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
self->setFullPath(JSCUtil::toCString(ctx, value));
return true;
}
void JSKeyframeNode::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSKeyframeNode>* binder = JSCBinder<JSKeyframeNode>::GetInstance();
binder->begin(ctx);
binder->addProperty("_indexInList", _GetIndexInList, _SetIndexInList);
binder->addProperty("type", _GetType, _SetType);
binder->addProperty("fullPath", _GetFullPath, _SetFullPath);
binder->addProperty("propertyOwner", _GetPropertyOwner, _SetPropertyOwner);
binder->addProperty("ownerPathCount", _GetOwnerPathCount, _SetOwnerPathCount);
binder->addProperty("keyFramesCount", _GetKeyFramesCount, _SetKeyframeCount);
binder->addProperty("propertyCount", _GetPropertyCount, _SetPropertyCount);
binder->addMethod("getOwnerPathCount", GetOwnerPathCount);
binder->addMethod("getPropertyCount", GetPropertyCount);
binder->addMethod("getKeyFramesCount", GetKeyFramesCount);
binder->addMethod("_setOwnerPathCount", SetOwnerPathCount);
binder->addMethod("_setOwnerPathByIndex", SetOwnerPathByIndex);
binder->addMethod("_joinOwnerPath", JoinOwnerPath);
binder->addMethod("_setPropertyCount", SetPropertyCount);
binder->addMethod("_setPropertyByIndex", SetPropertyByIndex);
binder->addMethod("_joinProperty", JoinProperty);
binder->addMethod("_setKeyframeCount", SetKeyframeCount);
binder->addMethod("_setKeyframeByIndex0", SetKeyframeByIndex0);
binder->addMethod("_setKeyframeByIndex1", SetKeyframeByIndex1);
binder->addMethod("getOwnerPathByIndex", GetOwnerPathByIndex);
binder->addMethod("getPropertyByIndex", GetPropertyByIndex);
binder->addMethod("getKeyframeByIndex", GetKeyframeByIndex);
binder->addMethod("getDataType", GetDataType);
binder->addMethod("getFloatData", GetFloatData);
binder->addMethod("setFloat32ArrayData", SetFloat32ArrayData);
binder->end(object, "_conchKeyframeNode");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,41 @@
/**
@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 "../Animation/JCKeyframeNode.h"
#include <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSKeyframeNode : public JCListNode, public JCKeyframeNode
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSKeyframeNode();
~JSKeyframeNode();
};
}
//------------------------------------------------------------------------------
#endif //__JSKeyframeNode_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,101 @@
/**
@file JSKeyframeNodeList.cpp
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#include "JSKeyframeNodeList.h"
#define NDEBUG
#include <assert.h>
#include "JSCUtil.h"
namespace laya
{
//ADDJSCLSINFO(JSKeyframeNodeList, JSObjNode);
//------------------------------------------------------------------------------
JSKeyframeNodeList::JSKeyframeNodeList()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
//AdjustAmountOfExternalAllocatedMemory(8192);
//JCMemorySurvey::GetInstance()->newClass("JSKeyframeNodeList", 8192, this);
}
//------------------------------------------------------------------------------
JSKeyframeNodeList::~JSKeyframeNodeList()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->delNode(this);
}
//m_vNodes.clear();
//JCMemorySurvey::GetInstance()->releaseClass("JSKeyframeNodeList", this);
}
static JSValueRef SetCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNodeList *pObj = (JSKeyframeNodeList*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int value = JSValueToNumber(ctx, arguments[0], 0);
pObj->setCount(value);
return JSValueMakeUndefined(ctx);
}
static JSValueRef GetCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNodeList *pObj = (JSKeyframeNodeList*)JSObjectGetPrivate(thisObject);
int value = pObj->getCount();
return JSValueMakeNumber(ctx, value);
}
static JSValueRef GetNodeByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNodeList* self = (JSKeyframeNodeList*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
JSKeyframeNode* pNode = (JSKeyframeNode*)self->m_vNodes[index];
return JSCBinder<JSKeyframeNode>::GetInstance()->transferObjPtrToJS(ctx, pNode);
}
static JSValueRef SetNodeByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNodeList* self = (JSKeyframeNodeList*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
JSValueRef keyframeNode = arguments[1];
if (JSValueIsObject(ctx, keyframeNode))
{
JSKeyframeNode* pNode = (JSKeyframeNode*)JSObjectGetPrivate(JSValueToObject(ctx, keyframeNode, NULL));
if (pNode)
{
self->m_vNodes[index] = pNode;
}
}
return JSValueMakeUndefined(ctx);
}
void JSKeyframeNodeList::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSKeyframeNodeList>* binder = JSCBinder<JSKeyframeNodeList>::GetInstance();
binder->begin(ctx);
binder->addMethod("setNodeByIndex", SetNodeByIndex);
binder->addMethod("getNodeByIndex", GetNodeByIndex);
binder->addMethod("getCount", GetCount);
binder->addMethod("setCount", SetCount);
binder->end(object, "_conchKeyframeNodeList");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,40 @@
/**
@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 "../Animation/JCKeyframeNodeList.h"
#include <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSKeyframeNodeList : public JCListNode, public JCKeyframeNodeList
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSKeyframeNodeList();
~JSKeyframeNodeList();
};
}
//------------------------------------------------------------------------------
#endif //__JSKeyframeNodeList_H__
//-----------------------------END FILE--------------------------------
+499
View File
@@ -0,0 +1,499 @@
/**
@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 "JSCUtil.h"
//------------------------------------------------------------------------------
namespace laya
{
JSWebGLPlus* JSWebGLPlus::s_pWebGLPlus = NULL;
//ADDJSCLSINFO(JSWebGLPlus, JSObjNode);
JSWebGLPlus::JSWebGLPlus()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
//AdjustAmountOfExternalAllocatedMemory(8192);
//JCMemorySurvey::GetInstance()->newClass("webglPlus", 8192, this);
}
JSWebGLPlus::~JSWebGLPlus()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->delNode(this);
}
//JCMemorySurvey::GetInstance()->releaseClass("webglPlus", this);
s_pWebGLPlus = NULL;
}
JSWebGLPlus* JSWebGLPlus::getInstance()
{
if (s_pWebGLPlus == NULL)
{
s_pWebGLPlus = new JSWebGLPlus();
}
return s_pWebGLPlus;
}
static JSValueRef Culling(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus Culling");
if (argumentCount < 4)
{
return JSValueMakeNumber(ctx, 0);
}
JSValueRef boundFrustumBuffer = arguments[0];
JSValueRef cullingBuffer = arguments[1];
JSValueRef cullingBufferIndices = arguments[2];
assert(JSValueIsNumber(ctx, arguments[3]));
int cullingCount = JSValueToNumber(ctx, arguments[3], 0);
JSValueRef cullingBufferResult = arguments[4];
char* pFrustumBuffer;
char* pCullingBuffer;
char* pCullingBufferIndices;
char* pCullingBufferResult;
int nFrustumLen = 0;
int nCullingBufferLen = 0;
int nCullingBufferIndicesLen = 0;
int nCullingBufferResultLen = 0;
if (JSCUtil::extractJSAB(ctx, boundFrustumBuffer, pFrustumBuffer, nFrustumLen) == false)
{
LOGE("culling culling frustum error");
return JSValueMakeNumber(ctx, 0);
}
if (JSCUtil::extractJSAB(ctx, cullingBuffer, pCullingBuffer, nCullingBufferLen) == false)
{
LOGE("culling culling buffer error");
return JSValueMakeNumber(ctx, 0);
}
if (JSCUtil::extractJSAB(ctx, cullingBufferIndices, pCullingBufferIndices, nCullingBufferIndicesLen) == false)
{
LOGE("culling culling buffer indices error");
return JSValueMakeNumber(ctx, 0);
}
if (JSCUtil::extractJSAB(ctx, cullingBufferResult, pCullingBufferResult, nCullingBufferResultLen) == false)
{
LOGE("culling result error");
return JSValueMakeNumber(ctx, 0);
}
int count = JCWebGLPlus::getInstance()->culling3D(cullingCount, pFrustumBuffer, nFrustumLen, pCullingBuffer, nCullingBufferLen, pCullingBufferIndices, nCullingBufferIndicesLen, pCullingBufferResult, nCullingBufferResultLen);
return JSValueMakeNumber(ctx, count);
}
static JSValueRef UpdateAnimationNodeWorldMatix(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UpdateAnimationNodeWorldMatix");
if (argumentCount < 5)
{
return JSValueMakeBoolean(ctx, false);
}
JSValueRef locPosition = arguments[0];
JSValueRef locRotation = arguments[1];
JSValueRef locScaling = arguments[2];
JSValueRef parentIndices = arguments[3];
JSValueRef outWorldMatrix = arguments[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 (JSCUtil::extractJSAB(ctx, locPosition, pLocPosition, nLocPosLen) == false)
{
LOGE("updateAnimationNodeWorldMatix postion error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, locRotation, pLocRotation, nLocRotLen) == false)
{
LOGE("updateAnimationNodeWorldMatix rotateion error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, locScaling, pLocScaling, nLocScaLen) == false)
{
LOGE("updateAnimationNodeWorldMatix scaling error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, parentIndices, pParentIndices, nLocParentLen) == false)
{
LOGE("updateAnimationNodeWorldMatix parent index error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, outWorldMatrix, pOutWorldMatrix, nOutWorldLen) == false)
{
LOGE("updateAnimationNodeWorldMatix world marix error");
return JSValueMakeBoolean(ctx, false);
}
bool value = JCWebGLPlus::getInstance()->updateAnimationNodeWorldMatix3D(pLocPosition, nLocPosLen, pLocRotation, nLocRotLen, pLocScaling, nLocScaLen,
pParentIndices, nLocParentLen, pOutWorldMatrix, nOutWorldLen);
return JSValueMakeBoolean(ctx, value);
}
static JSValueRef ComputeSubSkinnedData(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus ComputeSubSkinnedData");
if (argumentCount < 6)
{
return JSValueMakeBoolean(ctx, false);
}
JSValueRef worldMatrixs = arguments[0];
JSValueRef worldMatrixIndex = arguments[1];
JSValueRef inverseBindPoses = arguments[2];
JSValueRef boneIndices = arguments[3];
JSValueRef bindPoseInices = arguments[4];
JSValueRef resultData = arguments[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 (JSCUtil::extractJSAB(ctx, worldMatrixs, pWorldMatrixs, nWorldMatLen) == false)
{
LOGE("computeSubSkinnedDataNative world matrix error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, worldMatrixIndex, pWorldMatrixIndex, nWorldMatIndeLen) == false)
{
LOGE("computeSubSkinnedDataNative world matrix index error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, inverseBindPoses, pInverseBindPoses, nInverseBindPosesLen) == false)
{
LOGE("computeSubSkinnedDataNative inverse bind poses error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, boneIndices, pBoneIndices, nBoneIndicesLen) == false)
{
LOGE("computeSubSkinnedDataNative bone indices error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, bindPoseInices, pBindPoseIndices, nBindPoseIndicesLen) == false)
{
LOGE("computeSubSkinnedDataNative bind pose indices error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, resultData, pResultData, nResultDataLen) == false)
{
LOGE("computeSubSkinnedDataNative data error");
return JSValueMakeBoolean(ctx, false);
}
bool value = JCWebGLPlus::getInstance()->computeSubSkinnedData3D(pWorldMatrixs, nWorldMatLen, pWorldMatrixIndex, nWorldMatIndeLen,
pInverseBindPoses, nInverseBindPosesLen, pBoneIndices, nBoneIndicesLen,
pBindPoseIndices, nBindPoseIndicesLen, pResultData, nResultDataLen);
return JSValueMakeBoolean(ctx, value);
}
static JSValueRef CreateArrayBufferRef(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus CreateArrayBufferRef");
if (argumentCount < 4)
{
return JSValueMakeNull(ctx);
}
JSValueRef pArrayBuffer = arguments[0];
assert(JSValueIsNumber(ctx, arguments[1]));
int nType = JSValueToNumber(ctx, arguments[1], 0);
assert(JSValueIsBoolean(ctx, arguments[2]));
bool bSyncToRender = JSValueToBoolean(ctx, arguments[2]);
assert(JSValueIsNumber(ctx, arguments[3]));
int nRefType = JSValueToNumber(ctx, arguments[3], 0);
char* pBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, 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);
}
return JSCBinder<JSArrayBufferRef>::GetInstance()->transferObjPtrToJS(ctx, pArrayBufferRef);
}
LOGE("JSLayaGL::createArrayBufferRef type error");
return JSValueMakeNull(ctx);
}
bool JSWebGLPlus::updateArrayBufferRef(int nID, bool bSyncToRender, JSValueRef pArrayBuffer)
{
char* pBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(JSCUtil::s_ctx, 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 JSValueRef UpdateArrayBufferRef(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UpdateArrayBufferRef");
JSWebGLPlus* self = (JSWebGLPlus*)JSObjectGetPrivate(thisObject);
if (argumentCount < 3)
{
return JSValueMakeBoolean(ctx, false);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int nID = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
bool bSyncToRender = JSValueToBoolean(ctx, arguments[1]);
JSValueRef pArrayBuffer = arguments[2];
bool value = self->updateArrayBufferRef(nID, bSyncToRender, pArrayBuffer);
return JSValueMakeBoolean(ctx, value);
}
static JSValueRef SyncArrayBufferDataToRuntime(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus SyncArrayBufferDataToRuntime");
if (argumentCount < 3)
{
return JSValueMakeBoolean(ctx, false);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int nID = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
bool bSyncToRender = JSValueToBoolean(ctx, arguments[1]);
JSValueRef pArrayBuffer = arguments[2];
char* pBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, 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);
}
return JSValueMakeBoolean(ctx, true);
}
LOGE("JSLayaGL::syncArrayBufferDataToRuntime type error");
return JSValueMakeBoolean(ctx, false);
}
static JSValueRef EvaluateClipDatasRealTime(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus EvaluateClipDatasRealTime");
if (argumentCount < 5)
{
return JSValueMakeUndefined(ctx);
}
JSValueRef nodes = arguments[0];
assert(JSValueIsNumber(ctx, arguments[1]));
float playCurTime = JSValueToNumber(ctx, arguments[1], 0);
JSValueRef realTimeCurrentFrameIndexs = arguments[2];
assert(JSValueIsBoolean(ctx, arguments[3]));
bool addtive = JSValueToBoolean(ctx, arguments[3]);
assert(JSValueIsBoolean(ctx, arguments[4]));
bool frontPlay = JSValueToBoolean(ctx, arguments[4]);
char* pBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, realTimeCurrentFrameIndexs, pBuffer, nABLen);
if (!bIsArrayBuffer)
{
LOGE("evaluateClipDatasRealTime index type error");
return JSValueMakeUndefined(ctx);
}
if (JSValueIsObject(ctx, nodes))
{
JSKeyframeNodeList* pNodes = (JSKeyframeNodeList*)JSObjectGetPrivate(JSValueToObject(ctx, nodes, NULL));
if (!pNodes)
{
LOGE("evaluateClipDatasRealTime nodes type error");
return JSValueMakeUndefined(ctx);
}
JSKeyframeNodeList::evaluateClipDatasRealTime(pNodes, playCurTime, (short*)pBuffer, nABLen / sizeof(unsigned short), addtive, frontPlay);
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef UniformMatrix2fvEx(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UniformMatrix2fvEx");
if (argumentCount < 3)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
GLuint location = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
GLboolean transpose = JSValueToBoolean(ctx, arguments[1]);
assert(JSValueIsNumber(ctx, arguments[2]));
int id = JSValueToNumber(ctx, arguments[2], 0);
JCWebGLPlus::getInstance()->uniformMatrix2fvEx(location, transpose, id);
return JSValueMakeUndefined(ctx);
}
static JSValueRef UniformMatrix3fvEx(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UniformMatrix3fvEx");
if (argumentCount < 3)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
GLuint location = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
GLboolean transpose = JSValueToBoolean(ctx, arguments[1]);
assert(JSValueIsNumber(ctx, arguments[2]));
int id = JSValueToNumber(ctx, arguments[2], 0);
JCWebGLPlus::getInstance()->uniformMatrix3fvEx(location, transpose, id);
return JSValueMakeUndefined(ctx);
}
static JSValueRef UniformMatrix4fvEx(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UniformMatrix4fvEx");
if (argumentCount < 3)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
GLuint location = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
GLboolean transpose = JSValueToBoolean(ctx, arguments[1]);
assert(JSValueIsNumber(ctx, arguments[2]));
int id = JSValueToNumber(ctx, arguments[2], 0);
JCWebGLPlus::getInstance()->uniformMatrix4fvEx(location, transpose, id);
return JSValueMakeUndefined(ctx);
}
static JSValueRef UploadShaderUniforms(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UploadShaderUniforms");
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int nCmdID = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsNumber(ctx, arguments[1]));
int nDataID = JSValueToNumber(ctx, arguments[1], 0);
JCWebGLPlus::getInstance()->uploadShaderUniforms(nCmdID, nDataID);
return JSValueMakeUndefined(ctx);
}
static JSValueRef UploadShaderUniformsBuffer(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UploadShaderUniformsBuffer");
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int nCmdID = JSValueToNumber(ctx, arguments[0], 0);
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[1], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
JCWebGLPlus::getInstance()->uploadShaderUniformsBuffer(nCmdID, pArrayBuffer, nABLen);
}
return JSValueMakeUndefined(ctx);
}
void JSWebGLPlus::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSWebGLPlus>* binder = JSCBinder<JSWebGLPlus>::GetInstance();
binder->begin(ctx);
binder->addMethod("uploadShaderUniforms", UploadShaderUniforms);
binder->addMethod("uploadShaderUniformsBuffer", UploadShaderUniformsBuffer);
binder->addMethod("uniformMatrix2fvEx", UniformMatrix2fvEx);
binder->addMethod("uniformMatrix3fvEx", UniformMatrix3fvEx);
binder->addMethod("uniformMatrix4fvEx", UniformMatrix4fvEx);
binder->addMethod("createArrayBufferRef", CreateArrayBufferRef);
binder->addMethod("updateArrayBufferRef", UpdateArrayBufferRef);
binder->addMethod("syncArrayBufferDataToRuntime", SyncArrayBufferDataToRuntime);
binder->addMethod("evaluateClipDatasRealTime", EvaluateClipDatasRealTime);
binder->addMethod("updateAnimationNodeWorldMatix", UpdateAnimationNodeWorldMatix);
binder->addMethod("computeSubSkinnedData", ComputeSubSkinnedData);
binder->addMethod("culling", Culling);
binder->endToGlobal(object, "webglPlus", JSWebGLPlus::getInstance());
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
+45
View File
@@ -0,0 +1,45 @@
/**
@file JSWebGLPlus.h
@brief
@author James
@version 1.0
@date 2019_8_24
*/
#ifndef __JSWebGLPlus_H__
#define __JSWebGLPlus_H__
#include "../JSObjBase.h"
#include <JavaScriptCore/JavaScriptCore.h>
/**
* @brief
*/
namespace laya
{
class JSWebGLPlus : public JCListNode
{
public:
void exportJS(JSContextRef ctx, JSObjectRef object);
static JSWebGLPlus* getInstance();
JSWebGLPlus();
~JSWebGLPlus();
public:
bool updateArrayBufferRef(int nID, bool bSyncToRender, JSValueRef pArrayBuffer);
public:
static JSWebGLPlus* s_pWebGLPlus;
};
}
//------------------------------------------------------------------------------
#endif //__JSWebGLPlus_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,93 @@
/**
@file JCBoundingBox.cpp
@brief
@author James
@version 1.0
@date 2016_10_31
*/
#include "JCBoundingBox.h"
namespace laya
{
//------------------------------------------------------------------------------
JCBoundingBox::JCBoundingBox(const Vector3& min, const Vector3& max)
{
m_kMin = min;
m_kMax = max;
}
void JCBoundingBox::getCorners(Vector3* kOutCorners)
{
float minX = m_kMin.x;
float minY = m_kMin.y;
float minZ = m_kMin.z;
float maxX = m_kMax.x;
float maxY = m_kMax.y;
float maxZ = m_kMax.z;
kOutCorners[0] = Vector3(minX, maxY, maxZ);
kOutCorners[1] = Vector3(maxX, maxY, maxZ);
kOutCorners[2] = Vector3(maxX, minY, maxZ);
kOutCorners[3] = Vector3(minX, minY, maxZ);
kOutCorners[4] = Vector3(minX, maxY, minZ);
kOutCorners[5] = Vector3(maxX, maxY, minZ);
kOutCorners[6] = Vector3(maxX, minY, minZ);
kOutCorners[7] = Vector3(minX, minY, minZ);
}
void JCBoundingBox::getDebugLinePoint(Vector3* kOutCorners)
{
float minX = m_kMin.x;
float minY = m_kMin.y;
float minZ = m_kMin.z;
float maxX = m_kMax.x;
float maxY = m_kMax.y;
float maxZ = m_kMax.z;
Vector3 v0 =Vector3(minX, maxY, maxZ);
Vector3 v1 =Vector3(maxX, maxY, maxZ);
Vector3 v2 =Vector3(maxX, minY, maxZ);
Vector3 v3 =Vector3(minX, minY, maxZ);
Vector3 v4 =Vector3(minX, maxY, minZ);
Vector3 v5 =Vector3(maxX, maxY, minZ);
Vector3 v6 =Vector3(maxX, minY, minZ);
Vector3 v7 =Vector3(minX, minY, minZ);
kOutCorners[0] = v0;
kOutCorners[1] = v1;
kOutCorners[2] = v1;
kOutCorners[3] = v2;
kOutCorners[4] = v2;
kOutCorners[5] = v3;
kOutCorners[6] = v3;
kOutCorners[7] = v0;
kOutCorners[8] = v4;
kOutCorners[9] = v5;
kOutCorners[10] = v5;
kOutCorners[11] = v6;
kOutCorners[12] = v6;
kOutCorners[13] = v7;
kOutCorners[14] = v7;
kOutCorners[15] = v4;
kOutCorners[16] = v4;
kOutCorners[17] = v0;
kOutCorners[18] = v7;
kOutCorners[19] = v3;
kOutCorners[20] = v5;
kOutCorners[21] = v1;
kOutCorners[22] = v6;
kOutCorners[23] = v2;
}
JCBoundingBox::~JCBoundingBox()
{
}
void JCBoundingBox::setValues(float* value)
{
m_kMin.x = value[0];
m_kMin.y = value[1];
m_kMin.z = value[2];
m_kMax.x = value[3];
m_kMax.y = value[4];
m_kMax.z = value[5];
}
//------------------------------------------------------------------------------
}
//-----------------------------END FILE--------------------------------
+112
View File
@@ -0,0 +1,112 @@
/**
@file JCBoundingBox.h
@brief
@author James
@version 1.0
@date 2016_10_31
*/
#ifndef __JCBoundingBox_H__
#define __JCBoundingBox_H__
#include <vector>
#include "Vector3.h"
namespace laya
{
enum CONTAINMENT_TYPE
{
CT_DISJOINT = 0, //不相交
CT_CONTAINS = 1, //全部包含
CT_INTERSECTS = 2, //相交
};
/**
* @brief
*/
class JCBoundingBox
{
public:
/** @brief构造函数
*/
JCBoundingBox(const Vector3& min = { -0.5f,-0.5f,-0.5f }, const Vector3& max = { 0.5f,0.5f,0.5f });
/** @brief 返回八个点
* @param[out] 返回vector每个点
* @return
*/
void getCorners(Vector3* kOutCorners);
/** @brief 返回绘制线框的点数 24个点
* @param[out] 返回24个点
* @return
*/
void getDebugLinePoint(Vector3* kOutCorners);
/** @brief析构函数
*/
~JCBoundingBox();
/** @brief 两个盒子是否相交
* @param[in] 其他盒子
* @return
*/
bool intersectsWithBox(JCBoundingBox& pOther)
{
return (m_kMin <= pOther.m_kMax) && (m_kMax >= pOther.m_kMin);
}
/** @brief 是否完全在包含其中
* @param[in] 其他盒子
* @return
*/
bool isFullInside(JCBoundingBox& pOther)
{
return m_kMin >= pOther.m_kMin && m_kMax <= pOther.m_kMax;
}
bool isContain(JCBoundingBox& pOther)
{
return pOther.m_kMin >= m_kMin && pOther.m_kMax <= m_kMax;
}
Vector3 getCenter() const
{
return (m_kMin + m_kMax) * 0.5f;
}
void setCenter( const Vector3& kCenter )
{
Vector3 kMove = kCenter - getCenter();
m_kMin += kMove;
m_kMax += kMove;
}
/** @brief 获得size
* @return
*/
Vector3 getSize()
{
return m_kMax - m_kMin;
}
Vector3 getHalfSize()
{
return (m_kMax - m_kMin)*0.5;
}
void setValues(float* value);
public:
Vector3 m_kMin;
Vector3 m_kMax;
};
}
#endif //__JCBoundingBox_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,278 @@
/**
@file JCBoundingFrustum.cpp
@brief
@author James
@version 1.0
@date 2016_10_31
*/
#include "JCBoundingFrustum.h"
#include <stddef.h>
namespace laya
{
JCBoundingFrustum::JCBoundingFrustum()
{
}
JCBoundingFrustum::~JCBoundingFrustum()
{
}
JCPlane* JCBoundingFrustum::getPlane(int index)
{
switch (index) {
case 0:
return &m_kNear;
case 1:
return &m_kFar;
case 2:
return &m_kLeft;
case 3:
return &m_kRight;
case 4:
return &m_kTop;
case 5:
return &m_kBottom;
default:
return NULL;
}
return NULL;
}
Vector3 JCBoundingFrustum::get3PlaneInterPoint(JCPlane* p1, JCPlane* p2, JCPlane* p3)
{
Vector3& p1Nor = p1->m_kNormal;
Vector3& p2Nor = p2->m_kNormal;
Vector3& p3Nor = p3->m_kNormal;
Vector3 temp1 = p2Nor.cross(p3Nor);
Vector3 temp2 = p3Nor.cross(p1Nor);
Vector3 temp3 = p1Nor.cross(p2Nor);
float a = p1Nor.dot(temp1);
float b = p2Nor.dot(temp2);
float c = p3Nor.dot(temp3);
temp1 *= -p1->m_nDistance / a;
temp2 *= -p2->m_nDistance / b;
temp3 *= -p3->m_nDistance / c;
return temp1 + temp2 + temp3;
}
void JCBoundingFrustum::getCorners(std::vector<Vector3>& pOutCorners)
{
pOutCorners.resize(8);
pOutCorners[0] = get3PlaneInterPoint(&m_kNear, &m_kBottom, &m_kRight);
pOutCorners[1] = get3PlaneInterPoint(&m_kNear, &m_kTop, &m_kRight);
pOutCorners[2] = get3PlaneInterPoint(&m_kNear, &m_kTop, &m_kLeft);
pOutCorners[3] = get3PlaneInterPoint(&m_kNear, &m_kBottom, &m_kLeft);
pOutCorners[4] = get3PlaneInterPoint(&m_kFar, &m_kBottom, &m_kRight);
pOutCorners[5] = get3PlaneInterPoint(&m_kFar, &m_kTop, &m_kRight);
pOutCorners[6] = get3PlaneInterPoint(&m_kFar, &m_kTop, &m_kLeft);
pOutCorners[7] = get3PlaneInterPoint(&m_kFar, &m_kBottom, &m_kLeft);
}
CONTAINMENT_TYPE JCBoundingFrustum::containsAxisAlignedBouningBox(JCBoundingBox& box)
{
static const int NUM_PLANES = 6;
const JCPlane* pPlanes[NUM_PLANES] = { &m_kNear, &m_kLeft, &m_kRight, &m_kBottom, &m_kTop, &m_kFar };
Vector3 p, n;
Vector3 boxMin = box.m_kMin;
Vector3 boxMax = box.m_kMax;
for (int i = 0; i < NUM_PLANES; i++)
{
JCPlane* pPlane = (JCPlane*)(pPlanes[i]);
const Vector3& planeNor = pPlane->m_kNormal;
if (planeNor.x >= 0) {
p.x = boxMax.x;
n.x = boxMin.x;
}
else {
p.x = boxMin.x;
n.x = boxMax.x;
}
if (planeNor.y >= 0) {
p.y = boxMax.y;
n.y = boxMin.y;
}
else {
p.y = boxMin.y;
n.y = boxMax.y;
}
if (planeNor.z >= 0) {
p.z = boxMax.z;
n.z = boxMin.z;
}
else {
p.z = boxMin.z;
n.z = boxMax.z;
}
if (pPlane->intersectsPoint(p) == PIT_BACK)
return CT_DISJOINT;
if (pPlane->intersectsPoint(n) == PIT_BACK)
return CT_INTERSECTS;
}
return CT_CONTAINS;
}
CONTAINMENT_TYPE JCBoundingFrustum::containsBoundingBox(JCBoundingBox& box)
{
static const int NUM_PLANES = 6;
const JCPlane* pPlanes[NUM_PLANES] = { &m_kNear, &m_kLeft, &m_kRight, &m_kBottom, &m_kTop, &m_kFar };
Vector3 kBoxCorners[8];
box.getCorners(kBoxCorners);
int nTotalIn = 0;
for (int p = 0; p < NUM_PLANES; p++)
{
int nInCount = 8;
int nPointIn = 1;
JCPlane* pPlane = (JCPlane*)(pPlanes[p]);
for (int i = 0; i < 8; ++i)
{
if (pPlane->intersectsPoint(kBoxCorners[i]) == PIT_BACK)
{
nPointIn=0;
nInCount--;
}
}
if(nInCount == 0)
return CT_DISJOINT;
nTotalIn += nPointIn;
}
if (nTotalIn == 6)
return CT_CONTAINS;
return CT_INTERSECTS;
}
CONTAINMENT_TYPE JCBoundingFrustum::containsBoundingSphere(JCBoundingSphere& sphere)
{
PLANE_INTERSECTION_TYPE result = PIT_FRONT;
PLANE_INTERSECTION_TYPE planeResult = PIT_FRONT;
for (int i = 0; i < 6; i++)
{
switch (i)
{
case 0:
planeResult = m_kNear.intersectsSphere(sphere);
break;
case 1:
planeResult = m_kFar.intersectsSphere(sphere);
break;
case 2:
planeResult = m_kLeft.intersectsSphere(sphere);
break;
case 3:
planeResult = m_kRight.intersectsSphere(sphere);
break;
case 4:
planeResult = m_kTop.intersectsSphere(sphere);
break;
case 5:
planeResult = m_kBottom.intersectsSphere(sphere);
break;
}
switch (planeResult)
{
case PIT_BACK:
return CT_DISJOINT;
case PIT_INTERSECTING:
result = PIT_INTERSECTING;
break;
}
}
switch (result) {
case PIT_INTERSECTING:
return CT_INTERSECTS;
default:
return CT_CONTAINS;
}
}
void JCBoundingFrustum::getDebugLinePoint(Vector3* kOutPoints)
{
std::vector<Vector3> kOutCorners;
getCorners(kOutCorners);
kOutPoints[0] = kOutCorners[0];
kOutPoints[1] = kOutCorners[1];
kOutPoints[2] = kOutCorners[1];
kOutPoints[3] = kOutCorners[2];
kOutPoints[4] = kOutCorners[2];
kOutPoints[5] = kOutCorners[3];
kOutPoints[6] = kOutCorners[3];
kOutPoints[7] = kOutCorners[0];
kOutPoints[8] = kOutCorners[4];
kOutPoints[9] = kOutCorners[5];
kOutPoints[10] = kOutCorners[5];
kOutPoints[11] = kOutCorners[6];
kOutPoints[12] = kOutCorners[6];
kOutPoints[13] = kOutCorners[7];
kOutPoints[14] = kOutCorners[7];
kOutPoints[15] = kOutCorners[4];
kOutPoints[16] = kOutCorners[4];
kOutPoints[17] = kOutCorners[0];
kOutPoints[18] = kOutCorners[7];
kOutPoints[19] = kOutCorners[3];
kOutPoints[20] = kOutCorners[5];
kOutPoints[21] = kOutCorners[1];
kOutPoints[22] = kOutCorners[6];
kOutPoints[23] = kOutCorners[2];
}
void JCBoundingFrustum::setValues(float* value)
{
Vector3* pNormal = &m_kNear.m_kNormal;
pNormal->x = value[0]; pNormal->y = value[1]; pNormal->z = value[2]; m_kNear.m_nDistance = value[3];
pNormal = &m_kFar.m_kNormal;
pNormal->x = value[4]; pNormal->y = value[5]; pNormal->z = value[6]; m_kFar.m_nDistance = value[7];
pNormal = &m_kLeft.m_kNormal;
pNormal->x = value[8]; pNormal->y = value[9]; pNormal->z = value[10]; m_kLeft.m_nDistance = value[11];
pNormal = &m_kRight.m_kNormal;
pNormal->x = value[12]; pNormal->y = value[13]; pNormal->z = value[14]; m_kRight.m_nDistance = value[15];
pNormal = &m_kTop.m_kNormal;
pNormal->x = value[16]; pNormal->y = value[17]; pNormal->z = value[18]; m_kTop.m_nDistance = value[19];
pNormal = &m_kBottom.m_kNormal;
pNormal->x = value[20]; pNormal->y = value[21]; pNormal->z = value[22]; m_kBottom.m_nDistance = value[23];
}
bool JCBoundingFrustum::intersects(const JCBoundingBox& box)
{
const Vector3& min = box.m_kMin;
const Vector3& max = box.m_kMax;
float minX = min.x;
float minY = min.y;
float minZ = min.z;
float maxX = max.x;
float maxY = max.y;
float maxZ = max.z;
Vector3 nearNormal = this->m_kNear.m_kNormal;
if (this->m_kNear.m_nDistance + (nearNormal.x * (nearNormal.x < 0 ? minX : maxX)) + (nearNormal.y * (nearNormal.y < 0 ? minY : maxY)) + (nearNormal.z * (nearNormal.z < 0 ? minZ : maxZ)) < 0)
return false;
Vector3 leftNormal = this->m_kLeft.m_kNormal;
if (this->m_kLeft.m_nDistance + (leftNormal.x * (leftNormal.x < 0 ? minX : maxX)) + (leftNormal.y * (leftNormal.y < 0 ? minY : maxY)) + (leftNormal.z * (leftNormal.z < 0 ? minZ : maxZ)) < 0)
return false;
Vector3 rightNormal = this->m_kRight.m_kNormal;
if (this->m_kRight.m_nDistance + (rightNormal.x * (rightNormal.x < 0 ? minX : maxX)) + (rightNormal.y * (rightNormal.y < 0 ? minY : maxY)) + (rightNormal.z * (rightNormal.z < 0 ? minZ : maxZ)) < 0)
return false;
Vector3 bottomNormal = this->m_kBottom.m_kNormal;
if (this->m_kBottom.m_nDistance + (bottomNormal.x * (bottomNormal.x < 0 ? minX : maxX)) + (bottomNormal.y * (bottomNormal.y < 0 ? minY : maxY)) + (bottomNormal.z * (bottomNormal.z < 0 ? minZ : maxZ)) < 0)
return false;
Vector3 topNormal = this->m_kTop.m_kNormal;
if (this->m_kTop.m_nDistance + (topNormal.x * (topNormal.x < 0 ? minX : maxX)) + (topNormal.y * (topNormal.y < 0 ? minY : maxY)) + (topNormal.z * (topNormal.z < 0 ? minZ : maxZ)) < 0)
return false;
// Can ignore far plane when distant object culling is handled by another mechanism
Vector3 farNormal = this->m_kFar.m_kNormal;
if (this->m_kFar.m_nDistance + (farNormal.x * (farNormal.x < 0 ? minX : maxX)) + (farNormal.y * (farNormal.y < 0 ? minY : maxY)) + (farNormal.z * (farNormal.z < 0 ? minZ : maxZ)) < 0)
return false;
return true;
}
}
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,67 @@
/**
@file JCBoundingFrustum.h
@brief
@author James
@version 1.0
@date 2016_10_31
*/
#ifndef __JCBoundingFrustum_H__
#define __JCBoundingFrustum_H__
#include "JCBoundingBox.h"
#include "JCBoundingSphere.h"
#include "JCPlane.h"
#include "Vector3.h"
namespace laya
{
/**
* @brief
*/
class JCBoundingFrustum
{
public:
/** @brief构造函数
*/
JCBoundingFrustum();
/** @brief析构函数
*/
~JCBoundingFrustum();
JCPlane* getPlane(int index);
Vector3 get3PlaneInterPoint( JCPlane* p1, JCPlane* p2, JCPlane* p3 );
void getCorners(std::vector<Vector3>& pOutCorners);
CONTAINMENT_TYPE containsAxisAlignedBouningBox(JCBoundingBox& box);
CONTAINMENT_TYPE containsBoundingBox(JCBoundingBox& box );
CONTAINMENT_TYPE containsBoundingSphere(JCBoundingSphere& sphere);
void getDebugLinePoint(Vector3* kOutPoints);
void setValues(float* value);
bool intersects(const JCBoundingBox& box);
public:
JCPlane m_kNear;
JCPlane m_kFar;
JCPlane m_kLeft;
JCPlane m_kRight;
JCPlane m_kTop;
JCPlane m_kBottom;
};
}
#endif //__JCBoundingFrustum_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,39 @@
/**
@file JCBoundingSphere.cpp
@brief
@author James
@version 1.0
@date 2016_10_31
*/
#include "JCBoundingSphere.h"
namespace laya
{
JCBoundingSphere::JCBoundingSphere()
{
m_nRadius = 0;
}
//------------------------------------------------------------------------------
JCBoundingSphere::JCBoundingSphere(const Vector3& center, float nRadius)
{
m_kCenter = center;
m_nRadius = nRadius;
}
void JCBoundingSphere::setValues(float* value)
{
m_kCenter.x = value[0];
m_kCenter.y = value[1];
m_kCenter.z = value[2];
m_nRadius = value[3];
}
JCBoundingSphere::~JCBoundingSphere()
{
}
//------------------------------------------------------------------------------
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,48 @@
/**
@file JCBoundingSphere.h
@brief
@author James
@version 1.0
@date 2016_10_31
*/
#ifndef __JCBoundingSphere_H__
#define __JCBoundingSphere_H__
#include <vector>
#include "Vector3.h"
namespace laya
{
/**
* @brief
*/
class JCBoundingSphere
{
public:
JCBoundingSphere();
/** @brief构造函数
*/
JCBoundingSphere( const Vector3& center,float nRadius );
/** @brief析构函数
*/
~JCBoundingSphere();
void setValues(float* value);
public:
Vector3 m_kCenter;
float m_nRadius;
};
}
//------------------------------------------------------------------------------
#endif //__JCBoundingSphere_H__
//-----------------------------END FILE--------------------------------
+79
View File
@@ -0,0 +1,79 @@
/**
@file JCPlane.cpp
@brief
@author James
@version 1.0
@date 2016_10_31
*/
#include "JCPlane.h"
#include "JCBoundingSphere.h"
#include <math.h>
namespace laya
{
JCPlane::JCPlane()
{
m_nDistance = 0;
}
JCPlane::JCPlane(const Vector3& normal, float nDistance)
{
m_kNormal = normal;
m_nDistance = nDistance;
}
JCPlane::JCPlane(const Vector3& point1, const Vector3& point2, const Vector3& point3)
{
float x1 = point2.x - point1.x;
float y1 = point2.y - point1.y;
float z1 = point2.z - point1.z;
float x2 = point3.x - point1.x;
float y2 = point3.y - point1.y;
float z2 = point3.z - point1.z;
float yz = (y1 * z2) - (z1 * y2);
float xz = (z1 * x2) - (x1 * z2);
float xy = (x1 * y2) - (y1 * x2);
float invPyth = 1 / (sqrtf((yz * yz) + (xz * xz) + (xy * xy)));
float x = yz * invPyth;
float y = xz * invPyth;
float z = xy * invPyth;
m_kNormal.x = x;
m_kNormal.y = y;
m_kNormal.z = z;
m_nDistance = -((x * point1.x) + (y * point1.y) + (z * point1.z));
}
JCPlane::~JCPlane()
{
}
void JCPlane::normalize()
{
float fMagnitude = 1 / sqrtf(m_kNormal.x * m_kNormal.x + m_kNormal.y * m_kNormal.y + m_kNormal.z * m_kNormal.z);
m_kNormal.x *= fMagnitude;
m_kNormal.y *= fMagnitude;
m_kNormal.z *= fMagnitude;
m_nDistance *= fMagnitude;
}
PLANE_INTERSECTION_TYPE JCPlane::intersectsPoint(const Vector3& point)
{
float distance = m_kNormal.dot(point) + m_nDistance;
if (distance > 0)
return PIT_FRONT;
else if (distance < 0)
return PIT_BACK;
else
return PIT_INTERSECTING;
}
PLANE_INTERSECTION_TYPE JCPlane::intersectsSphere( const JCBoundingSphere& sphere)
{
float sphereR = sphere.m_nRadius;
float distance = m_kNormal.dot(sphere.m_kCenter) + m_nDistance;
if (distance > sphereR)
return PIT_FRONT;
else if (distance < -sphereR)
return PIT_BACK;
else
return PIT_INTERSECTING;
}
}
//-----------------------------END FILE--------------------------------
+75
View File
@@ -0,0 +1,75 @@
/**
@file JCPlane.h
@brief
@author James
@version 1.0
@date 2016_10_31
*/
#ifndef __JCPlane_H__
#define __JCPlane_H__
#include "JCBoundingSphere.h"
#include "Vector3.h"
namespace laya
{
enum PLANE_INTERSECTION_TYPE
{
PIT_BACK = 0,
PIT_FRONT,
PIT_INTERSECTING,
};
/**
* @brief
*/
class JCPlane
{
public:
/** @brief构造函数
*/
JCPlane();
/** @brief构造函数
*/
JCPlane( const Vector3& normal,float nDistance);
/** @brief构造函数
*/
JCPlane(const Vector3& point1, const Vector3& point2, const Vector3& point3);
/** @brief析构函数
*/
~JCPlane();
/** @brief normallize
* @return
*/
void normalize();
/** @brief 点和平面的关系
* @param[in] 点的信息
* @return
*/
PLANE_INTERSECTION_TYPE intersectsPoint( const Vector3& point );
/** @brief 点和包围球的关系
* @param[in] 包围球
* @return
*/
PLANE_INTERSECTION_TYPE intersectsSphere(const JCBoundingSphere& sphere);
public:
Vector3 m_kNormal;
float m_nDistance;
};
}
#endif //__JCPlane_H__
//-----------------------------END FILE--------------------------------
+91
View File
@@ -0,0 +1,91 @@
#ifndef __Vector3__H__
#define __Vector3__H__
class Vector3
{
public:
Vector3() : x(0.0f),y(0.0f),z(0.0f)
{}
Vector3(float x, float y, float z) : x(x), y(y),z(z)
{}
friend Vector3 operator*(Vector3 const & v, float scalar)
{
return Vector3(v.x * scalar, v.y * scalar, v.z * scalar);
}
friend Vector3 operator*(float scalar, Vector3 const & v)
{
return Vector3(scalar * v.x, scalar * v.y,scalar * v.z);
}
Vector3& operator*=(float scalar)
{
this->x *= scalar;
this->y *= scalar;
this->z *= scalar;
return *this;
}
Vector3& operator+=(const Vector3& b)
{
x += b.x;
y += b.y;
z += b.z;
return *this;
}
Vector3& operator-=(const Vector3& b)
{
x -= b.x;
y -= b.y;
z -= b.z;
return *this;
}
Vector3 operator+(const Vector3& b) const
{
Vector3 ret = *this;
ret += b;
return ret;
}
Vector3 operator-(const Vector3& b) const
{
Vector3 ret = *this;
ret -= b;
return ret;
}
bool operator<=(Vector3 const & v)
{
return x <= v.x && y <= v.y && z <= v.z;
}
bool operator>=(Vector3 const & v)
{
return x >= v.x && y >= v.y && z >= v.z;
}
Vector3 cross(const Vector3& rkVector) const
{
return Vector3(
y * rkVector.z - z * rkVector.y,
z * rkVector.x - x * rkVector.z,
x * rkVector.y - y * rkVector.x);
}
float dot(const Vector3& vec) const
{
return x * vec.x + y * vec.y + z * vec.z;
}
public:
float x;
float y;
float z;
};
#endif
@@ -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--------------------------------
+589
View 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--------------------------------
+43
View 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--------------------------------
+56
View 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--------------------------------
+32
View 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--------------------------------