X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscene3d-view%2Fgltf-loader.cpp;h=52dc2369a1e9e87f765bcb54a7618fd1b1a2bd34;hp=4115fb7b87009820e87cf9572f995dc69b22061d;hb=b1e8521ad77e7b4e62b59613b2edef64429130e9;hpb=f66c8a201b4ca45d2b65229bdae411b6e18633fa diff --git a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp index 4115fb7..52dc236 100644 --- a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp +++ b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,9 @@ #include // EXTERNAL INCLUDES -#include #include #include -#include +#include namespace Dali { @@ -107,7 +106,7 @@ bool ReadFloat( const TreeNode* node, float& num ) } else if( node->GetType() == TreeNode::INTEGER ) { - int32_t tempNum; + int32_t tempNum = 0; ReadInt( node, tempNum ); num = static_cast( tempNum ); returnValue = true; @@ -237,18 +236,19 @@ void FitBuffer( Dali::Vector& bufferDestination, Dali::Vector& buffe template bool ReadBinFile( Vector &dataBuffer, std::string url, int32_t offset, int32_t count ) { - dataBuffer.Resize( count ); - FILE* fp = fopen( url.c_str(), "rb" ); - if( fp == NULL ) + Dali::FileStream fileStream( url, FileStream::READ | FileStream::BINARY ); + FILE* fp = fileStream.GetFile(); + if( !fp ) { return false; } + + dataBuffer.Resize( count ); ssize_t result = -1; if( !fseek( fp, offset, SEEK_SET ) ) { result = fread( &dataBuffer[0], sizeof( T ), count, fp ); } - fclose( fp ); return ( result >= 0 ); } @@ -372,14 +372,14 @@ void SetMeshInfoAndCanonize( MeshInfo& meshInfo, Dali::Vector &ve } template -PropertyBuffer CreatePropertyBuffer( Vector bufferData, std::string map, int32_t type ) +VertexBuffer CreateVertexBuffer( Vector bufferData, std::string map, int32_t type ) { Property::Map positionMap; positionMap[map] = type; - PropertyBuffer propertyBuffer = PropertyBuffer::New( positionMap ); - propertyBuffer.SetData( bufferData.Begin(), bufferData.Count() ); - return propertyBuffer; + VertexBuffer vertexBuffer = VertexBuffer::New( positionMap ); + vertexBuffer.SetData( bufferData.Begin(), bufferData.Count() ); + return vertexBuffer; } void SetVertexBufferData( MeshInfo& meshInfo, std::string path, std::vector& accessorArray, std::vector& bufferViewArray, std::vector& bufferArray, int32_t accessorIdx, std::string map, int32_t type ) @@ -390,8 +390,8 @@ void SetVertexBufferData( MeshInfo& meshInfo, std::string path, std::vector( bufferData, map, type ); - meshInfo.geometry.AddVertexBuffer( propertyBuffer ); + VertexBuffer vertexBuffer = CreateVertexBuffer( bufferData, map, type ); + meshInfo.geometry.AddVertexBuffer( vertexBuffer ); } } @@ -403,8 +403,8 @@ void SetAttributeBufferData( MeshInfo& meshInfo, std::string path, std::vector bufferData; LoadDataFromAccessor( accessorIdx, bufferData, path, accessorArray, bufferViewArray, bufferArray ); - PropertyBuffer propertyBuffer = CreatePropertyBuffer( bufferData, map, type ); - meshInfo.geometry.AddVertexBuffer( propertyBuffer ); + VertexBuffer vertexBuffer = CreateVertexBuffer( bufferData, map, type ); + meshInfo.geometry.AddVertexBuffer( vertexBuffer ); } } @@ -1152,8 +1152,8 @@ bool SetGeometry( MeshInfo& meshInfo, std::string path, std::vector& bufferData[i].z = inputBufferData[i].z; bufferData[i].w = 1.0; } - PropertyBuffer propertyBuffer = CreatePropertyBuffer( bufferData, "aVertexColor", Property::VECTOR4 ); - meshInfo.geometry.AddVertexBuffer( propertyBuffer ); + VertexBuffer vertexBuffer = CreateVertexBuffer( bufferData, "aVertexColor", Property::VECTOR4 ); + meshInfo.geometry.AddVertexBuffer( vertexBuffer ); } else if( accessorArray[accessorIdx].type == "VEC4" ) { @@ -1228,11 +1228,16 @@ bool Loader::LoadScene( const std::string& filePath, Internal::Scene3dView& scen bool Loader::ParseGltf( const std::string& filePath ) { - std::ifstream fileStream( filePath.c_str() ); - std::string fileBuffer( ( std::istreambuf_iterator( fileStream ) ), - ( std::istreambuf_iterator() ) ); - mParser = Dali::Toolkit::JsonParser::New(); + std::streampos bufferSize = 0; + Dali::Vector buffer; + std::string fileBuffer; + if( !Dali::FileLoader::ReadFile( filePath, bufferSize, buffer, FileLoader::FileType::BINARY ) ) + { + return false; + } + fileBuffer.assign( &buffer[0], bufferSize ); + mParser = Dali::Toolkit::JsonParser::New(); return mParser.Parse( fileBuffer ); } @@ -1286,8 +1291,8 @@ void Loader::LoadCamera( Scene3dView& scene3dView ) } CameraActor cameraActor = CameraActor::New(); - cameraActor.SetParentOrigin( ParentOrigin::CENTER ); - cameraActor.SetAnchorPoint( AnchorPoint::CENTER ); + cameraActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + cameraActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); if( cameraInfo.type == "orthographic" ) { @@ -1423,7 +1428,7 @@ bool Loader::LoadSceneNodes( Scene3dView& scene3dView ) for( auto nodeIter = tempNode->CBegin(), end = tempNode->CEnd(); nodeIter != end; ++nodeIter ) { Actor actor = AddNode( scene3dView, ( ( *nodeIter ).second ).GetInteger() ); - actor.SetParentOrigin( ParentOrigin::CENTER ); + actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); scene3dView.GetRoot().Add( actor ); } @@ -1576,14 +1581,14 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index ) renderer.SetTextures( textureSet ); anchorPoint = meshInfo.pivot; - actor.SetAnchorPoint( anchorPoint ); + actor.SetProperty( Actor::Property::ANCHOR_POINT, anchorPoint ); - actor.SetSize( Vector3( meshInfo.size.x, meshInfo.size.y, meshInfo.size.z ) ); + actor.SetProperty( Actor::Property::SIZE, Vector3( meshInfo.size.x, meshInfo.size.y, meshInfo.size.z ) ); actor.AddRenderer( renderer ); - actor.SetScale( scale ); + actor.SetProperty( Actor::Property::SCALE, scale ); actor.RotateBy( orientation ); - actor.SetPosition( translation ); + actor.SetProperty( Actor::Property::POSITION, translation ); shader.RegisterProperty( "uLightType", ( scene3dView.GetLightType() & ~Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT ) ); shader.RegisterProperty( "uLightVector", scene3dView.GetLightVector() ); @@ -1643,10 +1648,10 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index ) } else { - actor.SetAnchorPoint( AnchorPoint::CENTER ); - actor.SetPosition( translation ); + actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + actor.SetProperty( Actor::Property::POSITION, translation ); actor.RotateBy( orientation ); - actor.SetSize( actorSize ); + actor.SetProperty( Actor::Property::SIZE, actorSize ); } tempNode = node->GetChild( "camera" ); @@ -1665,7 +1670,7 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index ) { std::string nameString; ReadString( tempNode, nameString ); - actor.SetName( nameString ); + actor.SetProperty( Dali::Actor::Property::NAME, nameString ); } SetActorCache( actor, index ); @@ -1674,7 +1679,7 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index ) for( auto childIter = tempNode->CBegin(), end = tempNode->CEnd(); childIter != end; ++childIter ) { Actor childActor = AddNode( scene3dView, ( ( *childIter ).second ).GetInteger() ); - childActor.SetParentOrigin( anchorPoint ); + childActor.SetProperty( Actor::Property::PARENT_ORIGIN, anchorPoint ); actor.Add( childActor ); } } @@ -1771,10 +1776,10 @@ bool Loader::LoadAnimation( Scene3dView& scene3dView ) } Animation animation = Animation::New( duration ); - Animation::Interpolation interpolation = Animation::Interpolation::Linear; + Animation::Interpolation interpolation = Animation::Interpolation::LINEAR; if( animationInfo.samplerArray[currentChannel.sampler].interpolation == "CUBICSPLINE" ) { - interpolation = Animation::Interpolation::Cubic; + interpolation = Animation::Interpolation::CUBIC; } if( animationInfo.samplerArray[currentChannel.sampler].interpolation == "STEP" ) {