pull/858/head
Kim Kulling 2016-05-14 10:10:33 +02:00
commit 71c2b91b98
23 changed files with 8248 additions and 80 deletions

View File

@ -87,6 +87,7 @@ namespace Grammar {
static const std::string ColorType = "Color";
static const std::string ParamType = "Param";
static const std::string TextureType = "Texture";
static const std::string AttenType = "Atten";
static const std::string DiffuseColorToken = "diffuse";
static const std::string SpecularColorToken = "specular";
@ -119,8 +120,9 @@ namespace Grammar {
IndexArrayToken,
MaterialToken,
ColorToken,
Paramtype,
ParamToken,
TextureToken,
AttenToken
};
static const std::string ValidMetricToken[ 4 ] = {
@ -163,8 +165,13 @@ namespace Grammar {
return CameraNodeToken;
} else if ( LightNodeType == tokenType ) {
return LightNodeToken;
} else if( GeometryObjectType == tokenType ) {
}
else if ( GeometryObjectType == tokenType ) {
return GeometryObjectToken;
} else if ( CameraObjectType == tokenType ) {
return CameraObjectToken;
} else if ( LightObjectType == tokenType ) {
return LightObjectToken;
} else if( TransformType == tokenType ) {
return TransformToken;
} else if( MeshType == tokenType ) {
@ -175,10 +182,14 @@ namespace Grammar {
return IndexArrayToken;
} else if( MaterialType == tokenType ) {
return MaterialToken;
} else if( ColorType == tokenType ) {
} else if ( ColorType == tokenType ) {
return ColorToken;
} else if ( ParamType == tokenType ) {
return ParamToken;
} else if( TextureType == tokenType ) {
return TextureToken;
} else if ( AttenType == tokenType ) {
return AttenToken;
}
return NoneType;
@ -191,6 +202,21 @@ namespace OpenGEX {
USE_ODDLPARSER_NS
//------------------------------------------------------------------------------------------------
static void propId2StdString( Property *prop, std::string &name, std::string &key ) {
name = key = "";
if ( NULL == prop ) {
return;
}
if ( NULL != prop->m_key ) {
name = prop->m_key->m_buffer;
if ( Value::ddl_string == prop->m_value->m_type ) {
key = prop->m_value->getString();
}
}
}
//------------------------------------------------------------------------------------------------
OpenGEXImporter::VertexContainer::VertexContainer()
: m_numVerts( 0 )
@ -238,6 +264,8 @@ OpenGEXImporter::OpenGEXImporter()
, m_currentVertices()
, m_currentMesh( NULL )
, m_currentMaterial( NULL )
, m_currentLight( NULL )
, m_currentCamera( nullptr )
, m_tokenType( Grammar::NoneType )
, m_materialCache()
, m_cameraCache()
@ -287,6 +315,8 @@ void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pSce
}
copyMeshes( pScene );
copyCameras( pScene );
copyLights( pScene );
resolveReferences();
createNodeTree( pScene );
}
@ -348,6 +378,14 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
handleGeometryObject( *it, pScene );
break;
case Grammar::CameraObjectToken:
handleCameraObject( *it, pScene );
break;
case Grammar::LightObjectToken:
handleLightObject( *it, pScene );
break;
case Grammar::TransformToken:
handleTransformNode( *it, pScene );
break;
@ -372,6 +410,10 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
handleColorNode( *it, pScene );
break;
case Grammar::ParamToken:
handleParamNode( *it, pScene );
break;
case Grammar::TextureToken:
handleTextureNode( *it, pScene );
break;
@ -469,11 +511,15 @@ void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
std::vector<std::string> objRefNames;
getRefNames( node, objRefNames );
// when we are dealing with a geometry node prepare the mesh cache
if ( m_tokenType == Grammar::GeometryNodeToken ) {
m_currentNode->mNumMeshes = objRefNames.size();
m_currentNode->mMeshes = new unsigned int[ objRefNames.size() ];
if( !objRefNames.empty() ) {
if ( !objRefNames.empty() ) {
m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MeshRef, objRefNames ) );
}
}
}
//------------------------------------------------------------------------------------------------
@ -506,7 +552,18 @@ void OpenGEXImporter::handleCameraNode( DDLNode *node, aiScene *pScene ) {
aiCamera *camera( new aiCamera );
const size_t camIdx( m_cameraCache.size() );
m_cameraCache.push_back( camera );
m_currentCamera = camera;
aiNode *newNode = new aiNode;
pushNode( newNode, pScene );
m_tokenType = Grammar::CameraNodeToken;
m_currentNode = newNode;
handleNodes( node, pScene );
popNode();
m_currentCamera->mName.Set( newNode->mName.C_Str() );
}
//------------------------------------------------------------------------------------------------
@ -514,6 +571,7 @@ void OpenGEXImporter::handleLightNode( ODDLParser::DDLNode *node, aiScene *pScen
aiLight *light( new aiLight );
const size_t lightIdx( m_lightCache.size() );
m_lightCache.push_back( light );
m_currentLight = light;
aiNode *newNode = new aiNode;
m_tokenType = Grammar::LightNodeToken;
@ -524,7 +582,7 @@ void OpenGEXImporter::handleLightNode( ODDLParser::DDLNode *node, aiScene *pScen
popNode();
light->mName.Set( newNode->mName.C_Str() );
m_currentLight->mName.Set( newNode->mName.C_Str() );
}
//------------------------------------------------------------------------------------------------
@ -536,12 +594,27 @@ void OpenGEXImporter::handleGeometryObject( DDLNode *node, aiScene *pScene ) {
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleCameraObject( ODDLParser::DDLNode *node, aiScene *pScene ) {
// parameters will be parsed normally in the tree, so just go for it
handleNodes( node, pScene );
handleNodes( node, pScene );
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleLightObject( ODDLParser::DDLNode *node, aiScene *pScene ) {
Property *prop( node->findPropertyByName( "type" ) );
if ( nullptr != prop ) {
if ( NULL != prop->m_value ) {
std::string typeStr( prop->m_value->getString() );
if ( "point" == typeStr ) {
m_currentLight->mType = aiLightSource_POINT;
} else if ( "spot" == typeStr ) {
m_currentLight->mType = aiLightSource_SPOT;
} else if ( "infinite" == typeStr ) {
m_currentLight->mType = aiLightSource_DIRECTIONAL;
}
}
}
// parameters will be parsed normally in the tree, so just go for it
handleNodes( node, pScene );
}
@ -599,21 +672,6 @@ void OpenGEXImporter::handleTransformNode( ODDLParser::DDLNode *node, aiScene *p
}
}
//------------------------------------------------------------------------------------------------
static void propId2StdString( Property *prop, std::string &name, std::string &key ) {
name = key = "";
if( NULL == prop ) {
return;
}
if( NULL != prop->m_key ) {
name = prop->m_key->m_buffer;
if( Value::ddl_string == prop->m_value->m_type ) {
key = prop->m_value->getString();
}
}
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
m_currentMesh = new aiMesh;
@ -777,9 +835,16 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
m_currentMesh->mFaces = new aiFace[ numItems ];
m_currentMesh->mNumVertices = numItems * 3;
m_currentMesh->mVertices = new aiVector3D[ m_currentMesh->mNumVertices ];
bool hasNormalCoords( false );
if ( m_currentVertices.m_numNormals > 0 ) {
m_currentMesh->mNormals = new aiVector3D[ m_currentMesh->mNumVertices ];
m_currentMesh->mNumUVComponents[ 0 ] = 3;
hasNormalCoords = true;
}
bool hasTexCoords( false );
if ( m_currentVertices.m_numUVComps[ 0 ] > 0 ) {
m_currentMesh->mTextureCoords[ 0 ] = new aiVector3D[ m_currentMesh->mNumVertices ];
hasTexCoords = true;
}
unsigned int index( 0 );
for( size_t i = 0; i < m_currentMesh->mNumFaces; i++ ) {
@ -790,15 +855,17 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
for( size_t indices = 0; indices < current.mNumIndices; indices++ ) {
const int idx( next->getUnsignedInt32() );
ai_assert( static_cast<size_t>( idx ) <= m_currentVertices.m_numVerts );
aiVector3D &pos = ( m_currentVertices.m_vertices[ idx ] );
aiVector3D &normal = ( m_currentVertices.m_normals[ idx ] );
aiVector3D &tex = ( m_currentVertices.m_textureCoords[ 0 ][ idx ] );
ai_assert( index < m_currentMesh->mNumVertices );
aiVector3D &pos = ( m_currentVertices.m_vertices[ idx ] );
m_currentMesh->mVertices[ index ].Set( pos.x, pos.y, pos.z );
if ( hasNormalCoords ) {
aiVector3D &normal = ( m_currentVertices.m_normals[ idx ] );
m_currentMesh->mNormals[ index ].Set( normal.x, normal.y, normal.z );
m_currentMesh->mTextureCoords[0][ index ].Set( tex.x, tex.y, tex.z );
}
if ( hasTexCoords ) {
aiVector3D &tex = ( m_currentVertices.m_textureCoords[ 0 ][ idx ] );
m_currentMesh->mTextureCoords[ 0 ][ index ].Set( tex.x, tex.y, tex.z );
}
current.mIndices[ indices ] = index;
index++;
@ -828,7 +895,8 @@ enum ColorType {
NoneColor = 0,
DiffuseColor,
SpecularColor,
EmissionColor
EmissionColor,
LightColor
};
//------------------------------------------------------------------------------------------------
@ -843,6 +911,8 @@ static ColorType getColorType( Text *id ) {
return SpecularColor;
} else if( *id == Grammar::EmissionColorToken ) {
return EmissionColor;
} else if ( *id == "light" ) {
return LightColor;
}
return NoneColor;
@ -878,6 +948,8 @@ void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScen
m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_SPECULAR );
} else if( EmissionColor == colType ) {
m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_EMISSIVE );
} else if ( LightColor == colType ) {
m_currentLight->mColorDiffuse = col;
}
}
}
@ -903,10 +975,8 @@ void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pSc
} else if( prop->m_value->getString() == Grammar::EmissionTextureToken ) {
m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_EMISSIVE( 0 ) );
} else if( prop->m_value->getString() == Grammar::OpacyTextureToken ) {
m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_OPACITY( 0 ) );
} else if( prop->m_value->getString() == Grammar::TransparencyTextureToken ) {
// ToDo!
// m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
@ -920,8 +990,53 @@ void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pSc
}
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleParamNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if ( NULL == node ) {
return;
}
Property *prop = node->findPropertyByName( "attrib" );
if ( nullptr != prop ) {
if ( NULL != prop->m_value ) {
Value *val( node->getValue() );
const float floatVal( val->getFloat() );
if ( NULL != val && prop->m_value != NULL ) {
if ( "fov" == prop->m_value->getString() ) {
m_currentCamera->mHorizontalFOV = floatVal;
} else if ( "near" == prop->m_value->getString() ) {
m_currentCamera->mClipPlaneNear = floatVal;
} else if ( "far" == prop->m_value->getString() ) {
m_currentCamera->mClipPlaneFar = floatVal;
}
}
}
}
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleAttenNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if ( nullptr == node ) {
return;
}
Property *prop = node->findPropertyByName( "curve" );
if ( nullptr != prop ) {
if ( nullptr != prop->m_value ) {
Value *val( node->getValue() );
const float floatVal( val->getFloat() );
if ( "scale" == prop->m_value->getString() ) {
m_currentLight->mAttenuationQuadratic = floatVal;
}
}
}
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::copyMeshes( aiScene *pScene ) {
ai_assert( nullptr != pScene );
if( m_meshCache.empty() ) {
return;
}
@ -931,6 +1046,32 @@ void OpenGEXImporter::copyMeshes( aiScene *pScene ) {
std::copy( m_meshCache.begin(), m_meshCache.end(), pScene->mMeshes );
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::copyCameras( aiScene *pScene ) {
ai_assert( nullptr != pScene );
if ( m_cameraCache.empty() ) {
return;
}
pScene->mNumCameras = m_cameraCache.size();
pScene->mCameras = new aiCamera*[ pScene->mNumCameras ];
std::copy( m_cameraCache.begin(), m_cameraCache.end(), pScene->mCameras );
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::copyLights( aiScene *pScene ) {
ai_assert( nullptr != pScene );
if ( m_lightCache.empty() ) {
return;
}
pScene->mNumLights = m_lightCache.size();
pScene->mLights = new aiLight*[ pScene->mNumLights ];
std::copy( m_lightCache.begin(), m_lightCache.end(), pScene->mLights );
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::resolveReferences() {
if( m_unresolvedRefStack.empty() ) {
@ -944,7 +1085,7 @@ void OpenGEXImporter::resolveReferences() {
aiNode *node( currentRefInfo->m_node );
if( RefInfo::MeshRef == currentRefInfo->m_type ) {
for( size_t i = 0; i < currentRefInfo->m_Names.size(); i++ ) {
const std::string &name(currentRefInfo->m_Names[ i ] );
const std::string &name( currentRefInfo->m_Names[ i ] );
ReferenceMap::const_iterator it( m_mesh2refMap.find( name ) );
if( m_mesh2refMap.end() != it ) {
unsigned int meshIdx = m_mesh2refMap[ name ];
@ -979,7 +1120,10 @@ void OpenGEXImporter::createNodeTree( aiScene *pScene ) {
void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
ai_assert( NULL != pScene );
if( NULL != node ) {
if ( NULL == node ) {
return;
}
ChildInfo *info( NULL );
if( m_nodeStack.empty() ) {
node->mParent = pScene->mRootNode;
@ -1006,7 +1150,6 @@ void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
info->m_children.push_back( node );
}
m_nodeStack.push_back( node );
}
}
//------------------------------------------------------------------------------------------------

View File

@ -125,7 +125,12 @@ protected:
void handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pScene );
void handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene );
void handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene );
void handleParamNode( ODDLParser::DDLNode *node, aiScene *pScene );
void handleAttenNode( ODDLParser::DDLNode *node, aiScene *pScene );
void copyMeshes( aiScene *pScene );
void copyCameras( aiScene *pScene );
void copyLights( aiScene *pScene );
void resolveReferences();
void pushNode( aiNode *node, aiScene *pScene );
aiNode *popNode();
@ -186,6 +191,8 @@ private:
VertexContainer m_currentVertices;
aiMesh *m_currentMesh;
aiMaterial *m_currentMaterial;
aiLight *m_currentLight;
aiCamera *m_currentCamera;
int m_tokenType;
std::vector<aiMaterial*> m_materialCache;
std::vector<aiCamera*> m_cameraCache;

View File

@ -355,6 +355,10 @@ namespace glTF
{ return false; }
virtual ~Object() {}
//! Maps special IDs to another ID, where needed. Subclasses may override it (statically)
static const char* TranslateId(Asset& r, const char* id)
{ return id; }
};
@ -484,6 +488,8 @@ namespace glTF
bool IsSpecial() const
{ return mIsSpecial; }
static const char* TranslateId(Asset& r, const char* id);
};

View File

@ -184,6 +184,8 @@ Ref<T> LazyDict<T>::Get(unsigned int i)
template<class T>
Ref<T> LazyDict<T>::Get(const char* id)
{
id = T::TranslateId(mAsset, id);
typename Dict::iterator it = mObjsById.find(id);
if (it != mObjsById.end()) { // already created?
return Ref<T>(mObjs, it->second);
@ -191,7 +193,7 @@ Ref<T> LazyDict<T>::Get(const char* id)
// read it from the JSON object
if (!mDict) {
return Ref<T>(); // section is missing
throw DeadlyImportError("GLTF: Missing section \"" + std::string(mDictId) + "\"");
}
Value::MemberIterator obj = mDict->FindMember(id);
@ -242,6 +244,15 @@ inline Buffer::Buffer()
: byteLength(0), type(Type_arraybuffer), mIsSpecial(false)
{ }
inline const char* Buffer::TranslateId(Asset& r, const char* id)
{
// Compatibility with old spec
if (r.extensionsUsed.KHR_binary_glTF && strcmp(id, "KHR_binary_glTF") == 0) {
return "binary_glTF";
}
return id;
}
inline void Buffer::Read(Value& obj, Asset& r)
{
@ -266,10 +277,16 @@ inline void Buffer::Read(Value& obj, Asset& r)
this->mData.reset(data);
if (statedLength > 0 && this->byteLength != statedLength) {
throw DeadlyImportError("GLTF: buffer length mismatch");
throw DeadlyImportError("GLTF: buffer \"" + id + "\", expected " + std::to_string(statedLength) +
" bytes, but found " + std::to_string(dataURI.dataLength));
}
}
else { // assume raw data
if (statedLength != dataURI.dataLength) {
throw DeadlyImportError("GLTF: buffer \"" + id + "\", expected " + std::to_string(statedLength) +
" bytes, but found " + std::to_string(dataURI.dataLength));
}
this->mData.reset(new uint8_t[dataURI.dataLength]);
memcmp(dataURI.data, this->mData.get(), dataURI.dataLength);
}
@ -589,14 +606,16 @@ inline void Material::Read(Value& material, Asset& r)
else if (strcmp(t, "CONSTANT") == 0) technique = Technique_CONSTANT;
}
ReadMaterialProperty(r, *ext, "ambient", this->ambient);
ReadMaterialProperty(r, *ext, "diffuse", this->diffuse);
ReadMaterialProperty(r, *ext, "specular", this->specular);
if (Value* values = FindObject(*ext, "values")) {
ReadMaterialProperty(r, *values, "ambient", this->ambient);
ReadMaterialProperty(r, *values, "diffuse", this->diffuse);
ReadMaterialProperty(r, *values, "specular", this->specular);
ReadMember(*ext, "doubleSided", doubleSided);
ReadMember(*ext, "transparent", transparent);
ReadMember(*ext, "transparency", transparency);
ReadMember(*ext, "shininess", shininess);
ReadMember(*values, "doubleSided", doubleSided);
ReadMember(*values, "transparent", transparent);
ReadMember(*values, "transparency", transparency);
ReadMember(*values, "shininess", shininess);
}
}
}
}

View File

@ -214,14 +214,14 @@ void glTFImporter::ImportMaterials(glTF::Asset& r)
}
inline void SetFace(aiFace& face, int a)
static inline void SetFace(aiFace& face, int a)
{
face.mNumIndices = 1;
face.mIndices = new unsigned int[1];
face.mIndices[0] = a;
}
inline void SetFace(aiFace& face, int a, int b)
static inline void SetFace(aiFace& face, int a, int b)
{
face.mNumIndices = 2;
face.mIndices = new unsigned int[2];
@ -229,7 +229,7 @@ inline void SetFace(aiFace& face, int a, int b)
face.mIndices[1] = b;
}
inline void SetFace(aiFace& face, int a, int b, int c)
static inline void SetFace(aiFace& face, int a, int b, int c)
{
face.mNumIndices = 3;
face.mIndices = new unsigned int[3];
@ -238,6 +238,18 @@ inline void SetFace(aiFace& face, int a, int b, int c)
face.mIndices[2] = c;
}
static inline bool CheckValidFacesIndices(aiFace* faces, unsigned nFaces, unsigned nVerts)
{
for (unsigned i = 0; i < nFaces; ++i) {
for (unsigned j = 0; j < faces[i].mNumIndices; ++j) {
unsigned idx = faces[i].mIndices[j];
if (idx >= nVerts)
return false;
}
}
return true;
}
void glTFImporter::ImportMeshes(glTF::Asset& r)
{
std::vector<aiMesh*> meshes;
@ -294,6 +306,11 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
for (size_t tc = 0; tc < attr.texcoord.size() && tc <= AI_MAX_NUMBER_OF_TEXTURECOORDS; ++tc) {
attr.texcoord[tc]->ExtractData(aim->mTextureCoords[tc]);
aim->mNumUVComponents[tc] = attr.texcoord[tc]->GetNumComponents();
aiVector3D* values = aim->mTextureCoords[tc];
for (unsigned int i = 0; i < aim->mNumVertices; ++i) {
values[i].y = 1 - values[i].y; // Flip Y coords
}
}
@ -304,7 +321,7 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
unsigned int count = prim.indices->count;
Accessor::Indexer data = prim.indices->GetIndexer();
assert(data.IsValid());
ai_assert(data.IsValid());
switch (prim.mode) {
case PrimitiveMode_POINTS: {
@ -369,6 +386,7 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
if (faces) {
aim->mFaces = faces;
aim->mNumFaces = nFaces;
ai_assert(CheckValidFacesIndices(faces, nFaces, aim->mNumVertices));
}
}
@ -466,7 +484,7 @@ aiNode* ImportNode(aiScene* pScene, glTF::Asset& r, std::vector<unsigned int>& m
}
}
aiMatrix4x4 matrix = ainode->mTransformation;
aiMatrix4x4& matrix = ainode->mTransformation;
if (node.matrix.isPresent) {
CopyValue(node.matrix.value, matrix);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,116 @@
Metric (key = "distance") {float {1.0}}
Metric (key = "angle") {float {1.0}}
Metric (key = "time") {float {1.0}}
Metric (key = "up") {string {"z"}}
GeometryNode $node1
{
Name {string {"Cube"}}
ObjectRef {ref {$geometry1}}
MaterialRef (index = 0) {ref {$material1}}
Transform
{
float[16]
{
{1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0}
}
}
}
LightNode $node2
{
Name {string {"Lamp"}}
ObjectRef {ref {$light1}}
Transform
{
float[16]
{
{-0.29086464643478394, 0.9551711678504944, -0.05518905818462372, 0.0,
-0.7711008191108704, -0.1998833566904068, 0.6045247316360474, 0.0,
0.5663931965827942, 0.21839119493961334, 0.7946722507476807, 0.0,
4.076245307922363, 1.0054539442062378, 5.903861999511719, 1.0}
}
}
}
CameraNode $node3
{
Name {string {"Camera"}}
ObjectRef {ref {$camera1}}
Transform
{
float[16]
{
{0.6858805418014526, 0.7276337742805481, -0.010816780850291252, 0.0,
-0.31737011671066284, 0.31246861815452576, 0.8953432440757751, 0.0,
0.6548618674278259, -0.6106656193733215, 0.4452453553676605, 0.0,
7.481131553649902, -6.5076398849487305, 5.34366512298584, 1.0}
}
}
}
GeometryObject $geometry1 // Cube
{
Mesh (primitive = "triangles")
{
VertexArray (attrib = "position")
{
float[3] // 24
{
{1.0, 0.9999999403953552, -1.0}, {1.0, -1.0, -1.0}, {-1.0000001192092896, -0.9999998211860657, -1.0}, {-0.9999996423721313, 1.0000003576278687, -1.0}, {1.0000004768371582, 0.999999463558197, 1.0}, {-0.9999999403953552, 1.0, 1.0}, {-1.0000003576278687, -0.9999996423721313, 1.0}, {0.9999993443489075, -1.0000005960464478, 1.0},
{1.0, 0.9999999403953552, -1.0}, {1.0000004768371582, 0.999999463558197, 1.0}, {0.9999993443489075, -1.0000005960464478, 1.0}, {1.0, -1.0, -1.0}, {1.0, -1.0, -1.0}, {0.9999993443489075, -1.0000005960464478, 1.0}, {-1.0000003576278687, -0.9999996423721313, 1.0}, {-1.0000001192092896, -0.9999998211860657, -1.0},
{-1.0000001192092896, -0.9999998211860657, -1.0}, {-1.0000003576278687, -0.9999996423721313, 1.0}, {-0.9999999403953552, 1.0, 1.0}, {-0.9999996423721313, 1.0000003576278687, -1.0}, {1.0000004768371582, 0.999999463558197, 1.0}, {1.0, 0.9999999403953552, -1.0}, {-0.9999996423721313, 1.0000003576278687, -1.0}, {-0.9999999403953552, 1.0, 1.0}
}
}
VertexArray (attrib = "normal")
{
float[3] // 24
{
{0.0, 0.0, -1.0}, {0.0, 0.0, -1.0}, {0.0, 0.0, -1.0}, {0.0, 0.0, -1.0}, {0.0, -0.0, 1.0}, {0.0, -0.0, 1.0}, {0.0, -0.0, 1.0}, {0.0, -0.0, 1.0},
{1.0, -2.8312206268310547e-07, 4.470341252726939e-08}, {1.0, -2.8312206268310547e-07, 4.470341252726939e-08}, {1.0, -2.8312206268310547e-07, 4.470341252726939e-08}, {1.0, -2.8312206268310547e-07, 4.470341252726939e-08}, {-2.8312206268310547e-07, -1.0, -1.0430819230577981e-07}, {-2.8312206268310547e-07, -1.0, -1.0430819230577981e-07}, {-2.8312206268310547e-07, -1.0, -1.0430819230577981e-07}, {-2.8312206268310547e-07, -1.0, -1.0430819230577981e-07},
{-1.0, 2.2351744632942427e-07, -1.341104365337742e-07}, {-1.0, 2.2351744632942427e-07, -1.341104365337742e-07}, {-1.0, 2.2351744632942427e-07, -1.341104365337742e-07}, {-1.0, 2.2351744632942427e-07, -1.341104365337742e-07}, {2.384185791015625e-07, 1.0, 2.086162567138672e-07}, {2.384185791015625e-07, 1.0, 2.086162567138672e-07}, {2.384185791015625e-07, 1.0, 2.086162567138672e-07}, {2.384185791015625e-07, 1.0, 2.086162567138672e-07}
}
}
IndexArray
{
unsigned_int32[3] // 12
{
{0, 1, 2}, {0, 2, 3}, {4, 5, 6}, {4, 6, 7}, {8, 9, 10}, {8, 10, 11}, {12, 13, 14}, {12, 14, 15}, {16, 17, 18}, {16, 18, 19}, {20, 21, 22}, {20, 22, 23}
}
}
}
}
LightObject $light1 (type = "point") // Lamp
{
Color (attrib = "light") {float[3] {{1.0, 1.0, 1.0}}}
Atten (curve = "inverse_square")
{
Param (attrib = "scale") {float {5.47722400800463}}
}
}
CameraObject $camera1 // Camera
{
Param (attrib = "fov") {float {0.8575560450553894}}
Param (attrib = "near") {float {0.10000000149011612}}
Param (attrib = "far") {float {100.0}}
}
Material $material1
{
Name {string {"Material"}}
Color (attrib = "diffuse") {float[3] {{0.6400000190734865, 0.6400000190734865, 0.6400000190734865}}}
Color (attrib = "specular") {float[3] {{0.5, 0.5, 0.5}}}
Param (attrib = "specular_power") {float {50}}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

View File

@ -0,0 +1,269 @@
{
"accessors": {
"accessor_21": {
"bufferView": "bufferView_29",
"byteOffset": 0,
"byteStride": 0,
"componentType": 5123,
"count": 36,
"type": "SCALAR"
},
"accessor_23": {
"bufferView": "bufferView_30",
"byteOffset": 0,
"byteStride": 12,
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
},
"accessor_25": {
"bufferView": "bufferView_30",
"byteOffset": 288,
"byteStride": 12,
"componentType": 5126,
"count": 24,
"max": [
1,
1,
1
],
"min": [
-1,
-1,
-1
],
"type": "VEC3"
},
"accessor_27": {
"bufferView": "bufferView_30",
"byteOffset": 576,
"byteStride": 8,
"componentType": 5126,
"count": 24,
"max": [
6,
1
],
"min": [
0,
0
],
"type": "VEC2"
}
},
"animations": {},
"asset": {
"generator": "collada2gltf@027f74366341d569dea42e9a68b7104cc3892054",
"premultipliedAlpha": true,
"profile": {
"api": "WebGL",
"version": "1.0.2"
},
"version": "1.0"
},
"bufferViews": {
"bufferView_29": {
"buffer": "BoxTextured",
"byteLength": 72,
"byteOffset": 0,
"target": 34963
},
"bufferView_30": {
"buffer": "BoxTextured",
"byteLength": 768,
"byteOffset": 72,
"target": 34962
}
},
"buffers": {
"BoxTextured": {
"byteLength": 840,
"type": "arraybuffer",
"uri": "BoxTextured.bin"
}
},
"extensionsUsed": [
"KHR_materials_common"
],
"images": {
"Image0001": {
"name": "Image0001",
"uri": "CesiumLogoFlat.png"
}
},
"materials": {
"Effect-Texture": {
"extensions": {
"KHR_materials_common": {
"doubleSided": false,
"jointCount": 0,
"technique": "PHONG",
"transparent": false,
"values": {
"diffuse": "texture_Image0001",
"shininess": 256,
"specular": [
0.2,
0.2,
0.2,
1
]
}
}
},
"name": "Texture"
}
},
"meshes": {
"Geometry-mesh002": {
"name": "Mesh",
"primitives": [
{
"attributes": {
"NORMAL": "accessor_25",
"POSITION": "accessor_23",
"TEXCOORD_0": "accessor_27"
},
"indices": "accessor_21",
"material": "Effect-Texture",
"mode": 4
}
]
}
},
"nodes": {
"Geometry-mesh002Node": {
"children": [],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"meshes": [
"Geometry-mesh002"
],
"name": "Mesh"
},
"groupLocator030Node": {
"children": [
"txtrLocator026Node"
],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"name": "Texture_Group"
},
"node_3": {
"children": [
"Geometry-mesh002Node",
"groupLocator030Node"
],
"matrix": [
1,
0,
0,
0,
0,
0,
-1,
0,
0,
1,
0,
0,
0,
0,
0,
1
],
"name": "Y_UP_Transform"
},
"txtrLocator026Node": {
"children": [],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"name": "Cesium_Logo_Flat__Image___Texture_"
}
},
"samplers": {
"sampler_0": {
"magFilter": 9729,
"minFilter": 9987,
"wrapS": 10497,
"wrapT": 10497
}
},
"scene": "defaultScene",
"scenes": {
"defaultScene": {
"nodes": [
"node_3"
]
}
},
"skins": {},
"textures": {
"texture_Image0001": {
"format": 6408,
"internalFormat": 6408,
"sampler": "sampler_0",
"source": "Image0001",
"target": 3553,
"type": 5121
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

View File

@ -0,0 +1,339 @@
{
"accessors": {
"accessor_21": {
"bufferView": "bufferView_29",
"byteOffset": 0,
"byteStride": 0,
"componentType": 5123,
"count": 36,
"type": "SCALAR"
},
"accessor_23": {
"bufferView": "bufferView_30",
"byteOffset": 0,
"byteStride": 12,
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
},
"accessor_25": {
"bufferView": "bufferView_30",
"byteOffset": 288,
"byteStride": 12,
"componentType": 5126,
"count": 24,
"max": [
1,
1,
1
],
"min": [
-1,
-1,
-1
],
"type": "VEC3"
},
"accessor_27": {
"bufferView": "bufferView_30",
"byteOffset": 576,
"byteStride": 8,
"componentType": 5126,
"count": 24,
"max": [
6,
1
],
"min": [
0,
0
],
"type": "VEC2"
}
},
"animations": {},
"asset": {
"generator": "collada2gltf@027f74366341d569dea42e9a68b7104cc3892054",
"premultipliedAlpha": true,
"profile": {
"api": "WebGL",
"version": "1.0.2"
},
"version": "1.0"
},
"bufferViews": {
"bufferView_29": {
"buffer": "BoxTextured",
"byteLength": 72,
"byteOffset": 0,
"target": 34963
},
"bufferView_30": {
"buffer": "BoxTextured",
"byteLength": 768,
"byteOffset": 72,
"target": 34962
}
},
"buffers": {
"BoxTextured": {
"byteLength": 840,
"type": "arraybuffer",
"uri": "BoxTextured.bin"
}
},
"images": {
"Image0001": {
"name": "Image0001",
"uri": "CesiumLogoFlat.png"
}
},
"materials": {
"Effect-Texture": {
"name": "Texture",
"technique": "technique0",
"values": {
"diffuse": "texture_Image0001",
"shininess": 256,
"specular": [
0.2,
0.2,
0.2,
1
]
}
}
},
"meshes": {
"Geometry-mesh002": {
"name": "Mesh",
"primitives": [
{
"attributes": {
"NORMAL": "accessor_25",
"POSITION": "accessor_23",
"TEXCOORD_0": "accessor_27"
},
"indices": "accessor_21",
"material": "Effect-Texture",
"mode": 4
}
]
}
},
"nodes": {
"Geometry-mesh002Node": {
"children": [],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"meshes": [
"Geometry-mesh002"
],
"name": "Mesh"
},
"groupLocator030Node": {
"children": [
"txtrLocator026Node"
],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"name": "Texture_Group"
},
"node_3": {
"children": [
"Geometry-mesh002Node",
"groupLocator030Node"
],
"matrix": [
1,
0,
0,
0,
0,
0,
-1,
0,
0,
1,
0,
0,
0,
0,
0,
1
],
"name": "Y_UP_Transform"
},
"txtrLocator026Node": {
"children": [],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"name": "Cesium_Logo_Flat__Image___Texture_"
}
},
"programs": {
"program_0": {
"attributes": [
"a_normal",
"a_position",
"a_texcoord0"
],
"fragmentShader": "BoxTextured0FS",
"vertexShader": "BoxTextured0VS"
}
},
"samplers": {
"sampler_0": {
"magFilter": 9729,
"minFilter": 9987,
"wrapS": 10497,
"wrapT": 10497
}
},
"scene": "defaultScene",
"scenes": {
"defaultScene": {
"nodes": [
"node_3"
]
}
},
"shaders": {
"BoxTextured0FS": {
"type": 35632,
"uri": "BoxTextured0FS.glsl"
},
"BoxTextured0VS": {
"type": 35633,
"uri": "BoxTextured0VS.glsl"
}
},
"skins": {},
"techniques": {
"technique0": {
"attributes": {
"a_normal": "normal",
"a_position": "position",
"a_texcoord0": "texcoord0"
},
"parameters": {
"diffuse": {
"type": 35678
},
"modelViewMatrix": {
"semantic": "MODELVIEW",
"type": 35676
},
"normal": {
"semantic": "NORMAL",
"type": 35665
},
"normalMatrix": {
"semantic": "MODELVIEWINVERSETRANSPOSE",
"type": 35675
},
"position": {
"semantic": "POSITION",
"type": 35665
},
"projectionMatrix": {
"semantic": "PROJECTION",
"type": 35676
},
"shininess": {
"type": 5126
},
"specular": {
"type": 35666
},
"texcoord0": {
"semantic": "TEXCOORD_0",
"type": 35664
}
},
"program": "program_0",
"states": {
"enable": [
2929,
2884
]
},
"uniforms": {
"u_diffuse": "diffuse",
"u_modelViewMatrix": "modelViewMatrix",
"u_normalMatrix": "normalMatrix",
"u_projectionMatrix": "projectionMatrix",
"u_shininess": "shininess",
"u_specular": "specular"
}
}
},
"textures": {
"texture_Image0001": {
"format": 6408,
"internalFormat": 6408,
"sampler": "sampler_0",
"source": "Image0001",
"target": 3553,
"type": 5121
}
}
}

View File

@ -0,0 +1,18 @@
precision highp float;
varying vec3 v_normal;
varying vec2 v_texcoord0;
uniform sampler2D u_diffuse;
uniform vec4 u_specular;
uniform float u_shininess;
void main(void) {
vec3 normal = normalize(v_normal);
vec4 color = vec4(0., 0., 0., 0.);
vec4 diffuse = vec4(0., 0., 0., 1.);
vec4 specular;
diffuse = texture2D(u_diffuse, v_texcoord0);
specular = u_specular;
diffuse.xyz *= max(dot(normal,vec3(0.,0.,1.)), 0.);
color.xyz += diffuse.xyz;
color = vec4(color.rgb * diffuse.a, diffuse.a);
gl_FragColor = color;
}

View File

@ -0,0 +1,15 @@
precision highp float;
attribute vec3 a_position;
attribute vec3 a_normal;
varying vec3 v_normal;
uniform mat3 u_normalMatrix;
uniform mat4 u_modelViewMatrix;
uniform mat4 u_projectionMatrix;
attribute vec2 a_texcoord0;
varying vec2 v_texcoord0;
void main(void) {
vec4 pos = u_modelViewMatrix * vec4(a_position,1.0);
v_normal = u_normalMatrix * a_normal;
v_texcoord0 = a_texcoord0;
gl_Position = u_projectionMatrix * pos;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 B

View File

@ -0,0 +1,17 @@
precision highp float;
varying vec3 v_normal;
uniform vec4 u_diffuse;
uniform vec4 u_specular;
uniform float u_shininess;
void main(void) {
vec3 normal = normalize(v_normal);
vec4 color = vec4(0., 0., 0., 0.);
vec4 diffuse = vec4(0., 0., 0., 1.);
vec4 specular;
diffuse = u_diffuse;
specular = u_specular;
diffuse.xyz *= max(dot(normal,vec3(0.,0.,1.)), 0.);
color.xyz += diffuse.xyz;
color = vec4(color.rgb * diffuse.a, diffuse.a);
gl_FragColor = color;
}

View File

@ -0,0 +1,12 @@
precision highp float;
attribute vec3 a_position;
attribute vec3 a_normal;
varying vec3 v_normal;
uniform mat3 u_normalMatrix;
uniform mat4 u_modelViewMatrix;
uniform mat4 u_projectionMatrix;
void main(void) {
vec4 pos = u_modelViewMatrix * vec4(a_position,1.0);
v_normal = u_normalMatrix * a_normal;
gl_Position = u_projectionMatrix * pos;
}

View File

@ -0,0 +1,276 @@
{
"accessors": {
"accessor_21": {
"bufferView": "bufferView_29",
"byteOffset": 0,
"byteStride": 0,
"componentType": 5123,
"count": 36,
"type": "SCALAR"
},
"accessor_23": {
"bufferView": "bufferView_30",
"byteOffset": 0,
"byteStride": 12,
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
},
"accessor_25": {
"bufferView": "bufferView_30",
"byteOffset": 288,
"byteStride": 12,
"componentType": 5126,
"count": 24,
"max": [
1,
1,
1
],
"min": [
-1,
-1,
-1
],
"type": "VEC3"
}
},
"animations": {},
"asset": {
"generator": "collada2gltf@027f74366341d569dea42e9a68b7104cc3892054",
"premultipliedAlpha": true,
"profile": {
"api": "WebGL",
"version": "1.0.2"
},
"version": "1.0"
},
"bufferViews": {
"bufferView_29": {
"buffer": "Box",
"byteLength": 72,
"byteOffset": 0,
"target": 34963
},
"bufferView_30": {
"buffer": "Box",
"byteLength": 576,
"byteOffset": 72,
"target": 34962
}
},
"buffers": {
"Box": {
"byteLength": 648,
"type": "arraybuffer",
"uri": "Box.bin"
}
},
"materials": {
"Effect-Red": {
"name": "Red",
"technique": "technique0",
"values": {
"diffuse": [
0.8,
0,
0,
1
],
"shininess": 256,
"specular": [
0.2,
0.2,
0.2,
1
]
}
}
},
"meshes": {
"Geometry-mesh002": {
"name": "Mesh",
"primitives": [
{
"attributes": {
"NORMAL": "accessor_25",
"POSITION": "accessor_23"
},
"indices": "accessor_21",
"material": "Effect-Red",
"mode": 4
}
]
}
},
"nodes": {
"BottomBox": {
"children": [],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"meshes": [
"Geometry-mesh002"
],
"name": "BottomBox"
},
"TopBox": {
"children": [],
"matrix": [
0.5,
0,
0,
0,
0,
0.5,
0,
0,
0,
0,
0.5,
0,
0,
0,
1,
1
],
"meshes": [
"Geometry-mesh002"
],
"name": "TopBox"
},
"node_1": {
"children": [
"BottomBox",
"TopBox"
],
"matrix": [
1,
0,
0,
0,
0,
0,
-1,
0,
0,
1,
0,
0,
0,
0,
0,
1
],
"name": "Y_UP_Transform"
}
},
"programs": {
"program_0": {
"attributes": [
"a_normal",
"a_position"
],
"fragmentShader": "Box0FS",
"vertexShader": "Box0VS"
}
},
"scene": "defaultScene",
"scenes": {
"defaultScene": {
"nodes": [
"node_1"
]
}
},
"shaders": {
"Box0FS": {
"type": 35632,
"uri": "Box0FS.glsl"
},
"Box0VS": {
"type": 35633,
"uri": "Box0VS.glsl"
}
},
"skins": {},
"techniques": {
"technique0": {
"attributes": {
"a_normal": "normal",
"a_position": "position"
},
"parameters": {
"diffuse": {
"type": 35666
},
"modelViewMatrix": {
"semantic": "MODELVIEW",
"type": 35676
},
"normal": {
"semantic": "NORMAL",
"type": 35665
},
"normalMatrix": {
"semantic": "MODELVIEWINVERSETRANSPOSE",
"type": 35675
},
"position": {
"semantic": "POSITION",
"type": 35665
},
"projectionMatrix": {
"semantic": "PROJECTION",
"type": 35676
},
"shininess": {
"type": 5126
},
"specular": {
"type": 35666
}
},
"program": "program_0",
"states": {
"enable": [
2929,
2884
]
},
"uniforms": {
"u_diffuse": "diffuse",
"u_modelViewMatrix": "modelViewMatrix",
"u_normalMatrix": "normalMatrix",
"u_projectionMatrix": "projectionMatrix",
"u_shininess": "shininess",
"u_specular": "specular"
}
}
}
}

Binary file not shown.