Combine Studio change for 3d components

This commit is contained in:
XiaoFeng 2015-11-13 17:44:23 +08:00
parent a0c7e10a82
commit eb644ee79f
11 changed files with 130 additions and 3 deletions

View File

@ -1048,7 +1048,9 @@ bool Bundle3D::loadJson(const std::string& path)
if (_jsonReader.ParseInsitu<0>(_jsonBuffer).HasParseError())
{
clear();
#ifndef CC_STUDIO_ENABLED_VIEW // for cocostudio only
CCASSERT(false, "Parse json failed");
#endif
return false;
}

View File

@ -80,7 +80,11 @@ void Mesh::resetLightUniformValues()
_spotLightUniformColorValues.assign(maxSpotLight, Vec3::ZERO);
_spotLightUniformPositionValues.assign(maxSpotLight, Vec3::ZERO);
_spotLightUniformDirValues.assign(maxSpotLight, Vec3::ZERO);
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
_spotLightUniformInnerAngleCosValues.assign(maxSpotLight, 0.0f);
#else
_spotLightUniformInnerAngleCosValues.assign(maxSpotLight, 1.0f);
#endif // CC_STUDIO_ENABLED_VIEW
_spotLightUniformOuterAngleCosValues.assign(maxSpotLight, 0.0f);
_spotLightUniformRangeInverseValues.assign(maxSpotLight, 0.0f);
}
@ -117,6 +121,7 @@ Mesh::Mesh()
, _visibleChanged(nullptr)
, _blendDirty(true)
, _force2DQueue(false)
, _texFile("")
{
}
@ -253,6 +258,7 @@ bool Mesh::isVisible() const
void Mesh::setTexture(const std::string& texPath)
{
_texFile = texPath;
auto tex = Director::getInstance()->getTextureCache()->addImage(texPath);
setTexture(tex);
}
@ -284,6 +290,8 @@ void Mesh::setTexture(Texture2D* tex)
}
bindMeshCommand();
_texFile = _texture->getPath();
}
Texture2D* Mesh::getTexture() const
@ -657,4 +665,23 @@ GLuint Mesh::getIndexBuffer() const
{
return _meshIndexData->getIndexBuffer()->getVBO();
}
GLuint Mesh::checkTextureName()
{
if (TextureCache::getInstance()->isDirty())
{
Texture2D* cacheTex = TextureCache::getInstance()->getTextureForKey(_texFile);
_texture = cacheTex;
}
if (_texture == nullptr || !_texture->isValid())
{
_texture = nullptr;
Texture2D* dummyTex = getDummyTexture();
return dummyTex->getName();
}
return _texture->getName();
}
NS_CC_END

View File

@ -194,6 +194,8 @@ public:
*/
void setForce2DQueue(bool force2D) { _force2DQueue = force2D; }
GLuint checkTextureName();
CC_CONSTRUCTOR_ACCESS:
Mesh();
@ -234,6 +236,8 @@ protected:
std::vector<float> _spotLightUniformInnerAngleCosValues;
std::vector<float> _spotLightUniformOuterAngleCosValues;
std::vector<float> _spotLightUniformRangeInverseValues;
std::string _texFile;
};
// end of 3d group

View File

@ -92,4 +92,17 @@ PointSide Plane::getSide(const Vec3& point) const
return PointSide::IN_PLANE;
}
PointSide Plane::getSide(const Vec3& point, const Vec3& halfSize) const
{
float dist = dist2Plane(point);
float maxAbsDist = fabs(_normal.x * halfSize.x) + fabs(_normal.y * halfSize.y) + fabs(_normal.z * halfSize.z);
if (dist > maxAbsDist)
return PointSide::FRONT_PLANE;
else if (dist < -maxAbsDist)
return PointSide::BEHIND_PLANE;
else
return PointSide::IN_PLANE;
}
NS_CC_END

View File

@ -100,6 +100,11 @@ public:
*/
PointSide getSide(const Vec3& point) const;
/**
* Return the side where the point is.
*/
PointSide getSide(const Vec3& point, const Vec3& halfSize) const;
protected:
Vec3 _normal; // the normal line of the plane
float _dist; // original displacement of the normal

View File

@ -895,6 +895,35 @@ void Sprite3D::setForce2DQueue(bool force2D)
}
}
const AABB& Sprite3D::getAABB(bool world) const
{
_aabbDirty = true;
Mat4 nodeToWorldTransform(getNodeToWorldTransform());
// If nodeToWorldTransform matrix isn't changed, we don't need to transform aabb.
if (memcmp(_nodeToWorldTransform.m, nodeToWorldTransform.m, sizeof(Mat4)) == 0 && !_aabbDirty)
{
return _aabb;
}
else
{
_aabb.reset();
Mat4 transform(nodeToWorldTransform);
for (const auto& it : _meshes) {
if (it->isVisible())
_aabb.merge(it->getAABB());
}
if (world)
_aabb.transform(transform);
_nodeToWorldTransform = nodeToWorldTransform;
}
return _aabb;
}
///////////////////////////////////////////////////////////////////////////////////
Sprite3DCache* Sprite3DCache::_cacheInstance = nullptr;
Sprite3DCache* Sprite3DCache::getInstance()

View File

@ -200,6 +200,9 @@ public:
*/
void setForce2DQueue(bool force2D);
Vector<Mesh*>& getMeshes() { return _meshes; }
const AABB& getAABB(bool world) const;
CC_CONSTRUCTOR_ACCESS:
Sprite3D();

View File

@ -177,7 +177,7 @@ private:
/*
*terrain vertices internal data format
**/
struct TerrainVertexData
struct CC_DLL TerrainVertexData
{
/*constructor*/
TerrainVertexData(){};
@ -192,7 +192,7 @@ private:
cocos2d::Vec3 _normal;
};
struct QuadTree;
struct CC_DLL QuadTree;
/*
*the terminal node of quad, use to subdivision terrain mesh and LOD
**/
@ -267,7 +267,7 @@ private:
*QuadTree
* @breif use to hierarchically frustum culling and set LOD
**/
struct QuadTree
struct CC_DLL QuadTree
{
/**constructor*/
QuadTree(int x, int y, int width, int height, Terrain * terrain);

View File

@ -406,6 +406,15 @@ public:
/** Get a shader program from the texture.*/
GLProgram* getGLProgram() const;
void setValid(bool valid) { _valid = valid; }
bool isValid() const { return _valid; }
std::string getPath()const { return _filePath; }
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
// Following function must be use carefully, it may cause resource management issue.
// So it limited to use as cocostudio internal.
void setPath(std::string file) { _filePath = file; }
#endif
public:
/** Get pixel info map, the key-value pairs is PixelFormat and PixelFormatInfo.*/
@ -540,6 +549,9 @@ protected:
friend class SpriteFrameCache;
friend class TextureCache;
friend class ui::Scale9Sprite;
bool _valid;
std::string _filePath;
};

View File

@ -598,6 +598,28 @@ std::string TextureCache::getCachedTextureInfo() const
return buffer;
}
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
void TextureCache::renameTextureWithKey(std::string srcName, std::string dstName)
{
std::string key = srcName;
auto it = _textures.find(key);
if( it == _textures.end() ) {
key = FileUtils::getInstance()->fullPathForFilename(srcName);
it = _textures.find(key);
}
if( it != _textures.end() ) {
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(dstName);
Texture2D* tex = it->second;
tex->setPath(key);
_textures.insert(std::make_pair(fullpath, tex));
_textures.erase(it);
this->setDirty(true);
}
}
#endif
#if CC_ENABLE_CACHE_TEXTURE_DATA
std::list<VolatileTexture*> VolatileTextureMgr::_textures;

View File

@ -204,6 +204,14 @@ public:
*/
const std::string getTextureFilePath(Texture2D* texture)const;
void setDirty(bool dirty) { _dirty = dirty; }
bool isDirty() const { return _dirty; }
#ifdef CC_STUDIO_ENABLED_VIEW // for cocostudio only
// This function use Texture2D::setPath function, which set to use in
// CococsStudio internal only, so this function also been set internal only
void renameTextureWithKey(std::string srcName, std::string dstName);
#endif
private:
void addImageAsyncCallBack(float dt);
void loadImage();
@ -228,6 +236,8 @@ protected:
int _asyncRefCount;
std::unordered_map<std::string, Texture2D*> _textures;
bool _dirty;
};
#if CC_ENABLE_CACHE_TEXTURE_DATA