Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize model loaders #29

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
71b4b56
Replace dummy file in assets
Gaztin Sep 12, 2020
3059dba
Rewrite entire file parsing workflow
Gaztin Sep 14, 2020
0b8a7c3
Replace Color class with new RGB and RGBA classes
Gaztin Sep 15, 2020
46e8187
Add `Abs` and `Pow` functions to Vector base
Gaztin Sep 15, 2020
b8c217a
Add ability to generate texcoords in geometry
Gaztin Sep 15, 2020
c415f0e
Add helper function for reading entire line in file
Gaztin Sep 15, 2020
d59a7b9
Rewrite OBJ loader from scratch
Gaztin Sep 15, 2020
b03878c
Fix not limiting logging of string view
Gaztin Sep 16, 2020
decc769
Fix ReadLine failing without trailing newline
Gaztin Sep 16, 2020
780ee17
Optimize out use of sscanf for parsing strings
Gaztin Sep 16, 2020
0e972ba
Add "or" helper function
Gaztin Sep 20, 2020
5aa162a
Fix variable naming
Gaztin Sep 20, 2020
b19f19b
Start rewrite of Collada parser
Gaztin Sep 20, 2020
e0aa301
Fix positions missing W
Gaztin Sep 21, 2020
b4dd9a4
Support no index buffer
Gaztin Sep 21, 2020
ce3a20d
Move functions around
Gaztin Sep 21, 2020
eff7770
Add correction matrix for non-Y up axes
Gaztin Sep 21, 2020
14e52e4
Add Suzanne model
Gaztin Sep 21, 2020
35d4b83
Add support for multiple varyings of same type
Gaztin Sep 21, 2020
e408d70
Implement phong shader
Gaztin Sep 22, 2020
72046f3
Revert faulty inequality operator
Gaztin Sep 22, 2020
1114071
Missing uniform is not ill-formed
Gaztin Sep 22, 2020
df407b1
Move function to source file
Gaztin Sep 22, 2020
cf736b5
Style fixes
Gaztin Sep 22, 2020
9796185
Fix type constraints in shader-gen operators
Gaztin Sep 22, 2020
88ed533
Don't generate index buffer for wavefront files
Gaztin Sep 22, 2020
18f0605
Add orbiting light around model
Gaztin Sep 22, 2020
53a5d9b
Add smooth faces to Suzanne
Gaztin Sep 23, 2020
55228b9
Fix normal generation for faceless geometries
Gaztin Sep 23, 2020
d178f71
Don't generate index buffers for Collada models
Gaztin Sep 23, 2020
fea94d3
Start parsing library_animations
Gaztin Sep 25, 2020
c26db79
Fix NO_OVERWRITE not fit for real time rendering
Gaztin Sep 25, 2020
cded1e6
Fix missing source file for SphereShape
Gaztin Sep 25, 2020
8da6577
Add before-draw callback to render commands
Gaztin Sep 25, 2020
b288c4d
Add ability to set radius on debug spheres
Gaztin Sep 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
69 changes: 69 additions & 0 deletions assets/models/suzanne.dae

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,41 @@
*/

#pragma once
#include "Orbit/Core/IO/Parser/IParser.h"
#include "Orbit/Core/Core.h"

// Fix macro interference on Windows
#if defined( ORB_OS_WINDOWS )
# include <Windows.h>
# undef RGB
#endif // ORB_OS_WINDOWS

ORB_NAMESPACE_BEGIN

class ORB_API_CORE ITextParser : public IParser
class RGB
{
public:

explicit ITextParser( ByteSpan data );

protected:
constexpr RGB( void ) = default;

void SkipWhitespace ( void );
std::string ReadAlphaNumeric( void );
std::string ReadPrintable ( void );
std::string ReadLiteral ( void );
constexpr explicit RGB( float grey )
: r( grey )
, g( grey )
, b( grey )
{
}

protected:
constexpr RGB( float red, float green, float blue )
: r( red )
, g( green )
, b( blue )
{
}

std::string Peek( size_t length ) const;

protected:
public:

bool ExpectString( std::string_view str );
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;

};

Expand Down
57 changes: 31 additions & 26 deletions src/Orbit/Core/IO/Parser/IParser.h → src/Orbit/Core/Color/RGBA.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,46 @@
*/

#pragma once
#include "Orbit/Core/Utility/Span.h"

#include <memory>
#include <string_view>
#include "Orbit/Core/Color/RGB.h"

ORB_NAMESPACE_BEGIN

class ORB_API_CORE IParser
class RGBA
{
public:

explicit IParser( ByteSpan data );
virtual ~IParser( void ) = default;
constexpr RGBA( void ) = default;

constexpr explicit RGBA( float grey )
: r( grey )
, g( grey )
, b( grey )
, a( 1.0f )
{
}

constexpr explicit RGBA( const RGB& rgb, float alpha = 1.0f )
: r( rgb.r )
, g( rgb.g )
, b( rgb.b )
, a( alpha )
{
}

constexpr RGBA( float red, float green, float blue, float alpha = 1.0f )
: r( red )
, g( green )
, b( blue )
, a( alpha )
{
}

public:

bool IsGood( void ) const { return good_; }

protected:

void Skip ( size_t size );
void ReadBytes( void* dst, size_t count );

protected:

bool IsEOF( void ) const;

protected:

std::unique_ptr< uint8_t[] > data_;

size_t size_;
size_t offset_;

bool good_;
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;
float a = 1.0f;

};

Expand Down
28 changes: 28 additions & 0 deletions src/Orbit/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,36 @@
#pragma once
#include "Orbit/Orbit.h"

#include <type_traits>

#if defined( ORB_BUILD_CORE )
# define ORB_API_CORE ORB_DLL_EXPORT
#else // ORB_BUILD_CORE
# define ORB_API_CORE ORB_DLL_IMPORT
#endif // !ORB_BUILD_CORE

ORB_NAMESPACE_BEGIN

template< typename T, typename... RemainingTypes >
constexpr T Or( T first, RemainingTypes... remaining )
{
static_assert( ( std::is_convertible_v< T, RemainingTypes > && ... ) );

if( !!first )
{
return first;
}
else
{
for( T var : { remaining... } )
{
if( !!var )
return var;
}
}

// None of them evaluated to true. Just return the first one.
return first;
}

ORB_NAMESPACE_END
2 changes: 1 addition & 1 deletion src/Orbit/Core/IO/Asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ORB_NAMESPACE_BEGIN

Asset::Asset( std::string_view path )
{
ORB_TRACE( "Loading asset: %s", path.data() );
ORB_TRACE( "Loading asset: %.*s", path.size(), path.data() );

#if defined( ORB_OS_WINDOWS )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,39 @@
* 3. This notice may not be removed or altered from any source distribution.
*/

#include "IParser.h"
#include "BinaryFile.h"

#include <cstring>

ORB_NAMESPACE_BEGIN

IParser::IParser( ByteSpan data )
: data_ { data.Copy() }
, size_ { data.Size() }
, offset_{ 0 }
, good_ { false }
void BinaryFile::Init( size_t total_size )
{
total_size_ = total_size;
current_offset_ = 0;
}

void IParser::Skip( size_t size )
void BinaryFile::Skip( size_t size )
{
if( ( offset_ + size ) < size_ ) offset_ += size;
else offset_ = size_;
// Increment offset, but clamp it so it doesn't exceed the total size
current_offset_ = std::min( current_offset_ + size, total_size_ );
}

void IParser::ReadBytes( void* dst, size_t count )
void BinaryFile::ReadBytes( const void* src, void* dst, size_t size )
{
if( ( offset_ + count ) < size_ )
{
std::memcpy( dst, &data_[ offset_ ], count );
offset_ += count;
}
else
{
std::memcpy( dst, &data_[ offset_ ], ( offset_ - size_ ) );
offset_ = size_;
}
// Make sure we don't read more bytes than we have
const size_t bytes_to_write = std::min( size, total_size_ - current_offset_ );

// Copy bytes from src to dst
std::memcpy( dst, static_cast< const uint8_t* >( src ) + current_offset_, bytes_to_write );

// Increment offset
current_offset_ += bytes_to_write;
}

bool IParser::IsEOF( void ) const
bool BinaryFile::IsEOF( void ) const
{
return ( offset_ == size_ );
return ( current_offset_ == total_size_ );
}

ORB_NAMESPACE_END
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,42 @@
*/

#pragma once
#include "Orbit/Core/IO/Parser/XML/XMLAttribute.h"
#include "Orbit/Core/Utility/Span.h"

#include <string>
#include <vector>
#include <memory>
#include <string_view>

ORB_NAMESPACE_BEGIN

class ORB_API_CORE XMLElement
/** Base class for file format parsers.
* Does not store the data by default. This is by design in case the output can be processed in chunks rather than
* needing to wait until the entire file has been parsed.
*/
class ORB_API_CORE BinaryFile
{
public:

std::string_view Attribute( std::string_view key ) const;
BinaryFile( void ) = default;
virtual ~BinaryFile( void ) = default;

public:
protected:

const XMLElement& ChildWithAttribute( std::string_view element, std::string_view attribute, std::string_view value ) const;
size_t CountChildren ( std::string_view element ) const;
bool IsValid ( void ) const;
/** Initializes the metadata */
void Init( size_t total_size );

public:
/** Skips forward @size amount of bytes */
void Skip( size_t size );

auto begin( void ) const { return children.begin(); }
auto end ( void ) const { return children.end(); }
/** Reads @size amount of bytes from @src and writes them to @dst */
void ReadBytes( const void* src, void* dst, size_t size );

public:

const XMLElement& operator[]( std::string_view key ) const;

public:
/** Returns whether or not the file has reached the end */
bool IsEOF( void ) const;

std::string name;
std::string content;
protected:

std::vector< XMLAttribute > attributes;
std::vector< XMLElement > children;
size_t total_size_ = 0;
size_t current_offset_ = 0;

};

Expand Down
Loading