Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:syoyo/tinyusdz into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Jun 30, 2024
2 parents ed64e34 + e48bd0a commit 6a15802
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 37 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,25 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
PROPERTIES COMPILE_FLAGS ${TUSDZ_COMPILE_FLAGS})
endif()

# Increase warning level for gcc.
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")

set(TUSDZ_COMPILE_FLAGS
"-Wall "
)

option(TINYUSDZ_NO_WERROR "Don't set -Werror when building the tinyusdz library" ${TINYUSDZ_DEFAULT_NO_WERROR})
if (NOT TINYUSDZ_NO_WERROR)
set(TUSDZ_COMPILE_FLAGS "${TUSDZ_COMPILE_FLAGS} -Werror")
endif()

set_source_files_properties(${TINYUSDZ_SOURCES}
PROPERTIES COMPILE_FLAGS ${TUSDZ_COMPILE_FLAGS})

if (TINYUSDZ_WITH_C_API)
set_source_files_properties(${TINYUSDZ_C_API_SOURCES}
PROPERTIES COMPILE_FLAGS ${TUSDZ_COMPILE_FLAGS})
endif()
endif()

if(TINYUSDZ_CUSTOM_COMPILE_FLAGS)
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [examples/openglviewer](examples/openglviewer) OpenGL viewer
* [examples/sdlviewer](examples/sdlviewer) Software raytracing viewer
* For Vulkan and Android Vulkan example, please refer https://github.com/syoyo/Vulkan-glTF-USDZ-PBR for a while
* For OpenGL + MaterialX example, please refer ASF MaterialXViewer fork to load USD model through TinyUSDZ https://github.com/lighttransport/materialx

## Mid-term todo

Expand Down Expand Up @@ -154,13 +155,6 @@ USD itself is a generic container of 3D scene data.
Tydra is an interface to Renderers/Viewers and other DCCs.
Tydra may be something like Tiny version of pxrUSD Hydra, but its API is completely different. See [src/tydra/README.md](src/tydra/README.md) for the background.

* Image color space
* sRGB
* Linear
* Rec.709
* [ ] Partial support of OCIO(OpenColor IO) through TinyColorIO https://github.com/syoyo/tinycolorio . Currently SPI3DLut only.
* More details are T.B.W.

## Notice

TinyUSDZ does not support Reality Composer file format(`.reality`) since it uses proprietary file format and we cannot understand it(so no conversion support from/to Reality also).
Expand Down
2 changes: 1 addition & 1 deletion src/crate-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2795,7 +2795,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,

CHECK_MEMORY_USAGE(sizeof(double));

double v;
double v{0.0};
if (!_sr->read_double(&v)) {
PUSH_ERROR("Failed to read Double value.");
return false;
Expand Down
98 changes: 91 additions & 7 deletions src/external/tiny_dng_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ THE SOFTWARE.

#include <string>
#include <vector>
#include <array>

namespace tinydng {

Expand Down Expand Up @@ -251,6 +252,9 @@ struct DNGImage {
std::vector<unsigned char>
data; // Decoded pixel data(len = spp * width * height * bps / 8)

std::array<int32_t, 2> shutter_speed{0,0}; // numerator, denominator
std::array<int32_t, 2> aperture_value{0,0}; // numerator, denominator

// Custom fields
std::vector<FieldData> custom_fields;
};
Expand Down Expand Up @@ -346,7 +350,7 @@ bool IsDNGFromMemory(const char* mem, unsigned int size, std::string* msg);
#pragma clang diagnostic ignored "-Weverything"
#endif

#define TINY_DNG_LOADER_DEBUG
//#define TINY_DNG_LOADER_DEBUG
#ifdef TINY_DNG_LOADER_DEBUG
#define TINY_DNG_DPRINTF(...) printf(__VA_ARGS__)
#else
Expand Down Expand Up @@ -1928,6 +1932,8 @@ int lj92_encode(uint16_t* image, int width, int height, int bitdepth,
#endif
#endif

// NOTE: - https://exiftool.org/TagNames/EXIF.html
// - https://helpx.adobe.com/photoshop/kb/dng-specification-tags.html
typedef enum {
TAG_NEW_SUBFILE_TYPE = 254,
TAG_SUBFILE_TYPE = 255,
Expand All @@ -1941,6 +1947,11 @@ typedef enum {
TAG_ROWS_PER_STRIP = 278,
TAG_STRIP_BYTE_COUNTS = 279,
TAG_PLANAR_CONFIGURATION = 284,
TAG_TRANSFER_FUNCTION = 301, // int16u[768]
TAG_SOFTWARE = 305, // string
TAG_MODIFY_DATA = 306, // string
TAG_ARTIST = 315, // string
//TAG_HOST_COMPUTER = 316,
TAG_PREDICTOR = 317,
TAG_SUB_IFDS = 330,
TAG_TILE_WIDTH = 322,
Expand Down Expand Up @@ -1979,17 +1990,40 @@ typedef enum {
TAG_CR2_SLICES = 50752,
TAG_CR2_META2 = 50885,

TAG_EXPOSURE_TIME = 0x829a, // rational64u
TAG_F_NUMBER = 0x829d, // rational64u
TAG_EXPOSURE_PROGRAM = 0x8822, // int16u
TAG_GPS_INFO = 0x8825,
TAG_ISO = 0x8827, // int16u[n]

TAG_SHUTTER_SPEED_VALUE = 0x9201, // rational64s
TAG_APERTURE_VALUE = 0x9202, // rational64u
TAG_BRIGHTNESS_VALUE = 0x9203, // rational64s
TAG_EXPOSURE_COMPENSATION = 0x9204, // rational64s
TAG_MAX_APERTURE_VALUE = 0x9205, // rational64u
TAG_SUBJECT_DISTANCE = 0x9206, // rational64u
TAG_METERING_MODE = 0x9207, // int16u
TAG_LIGHT_SOURCE = 0x9208, // int16u
TAG_FLASH = 0x9209, // int16u
TAG_FOCAL_LENGTH = 0x920a, // rational64u

TAG_LENS_INFO = 0xa432, // rational64u[4]
TAG_LENS_MAKE = 0xa433, // string
TAG_LENS_MODEL = 0xa434, // string
TAG_LENS_SERIAL_NUMBER = 0xa435, // string

//
// OpCodeList
//
TAG_OPCODE_LIST1 = 0xc740,
TAG_OPCODE_LIST2 = 0xc741,
TAG_OPCODE_LIST3 = 0xc742,

TAG_NOISE_PROFILE = 51041,

TAG_NOISE_PROFILE = 0xc761,

// DNG 1.6(Apple ProRAW)
// ahttps://helpx.adobe.com/photoshop/kb/dng-specification-tags.html
// https://helpx.adobe.com/photoshop/kb/dng-specification-tags.html
TAG_SEMANTIC_NAME = 52526, // Type: ASCII, Count: String length including
// null, Value: null-terminated string

Expand Down Expand Up @@ -2447,6 +2481,56 @@ class StreamReader {
// never come here.
}

bool read_rational(int type, uint32_t* ret0, uint32_t *ret1) const {
// @todo { Support more types. }

if (!ret0 || !ret1) {
return false;
}

if (type == TYPE_RATIONAL) {
unsigned int num;
if (!read4(&num)) {
return false;
}
unsigned int denom;
if (!read4(&denom)) {
return false;
}

(*ret0) = num;
(*ret1) = denom;
return true;
}

return false;
}

bool read_srational(int type, int32_t* ret0, int32_t *ret1) const {
// @todo { Support more types. }

if (!ret0 || !ret1) {
return false;
}

if (type == TYPE_SRATIONAL) {
int num;
if (!read4(&num)) {
return false;
}
int denom;
if (!read4(&denom)) {
return false;
}

(*ret0) = num;
(*ret1) = denom;
return true;
}

return false;
}

//
// Returns a memory address. The begining of address is computed in
// relative(based on current seek pos). This function is useful when you just
Expand Down Expand Up @@ -4039,7 +4123,7 @@ static bool ParseTIFFIFD(const StreamReader& sr,

return false;
}
size_t readLen = len * sizeof(float);
//size_t readLen = len * sizeof(float);

const size_t kMaxSamples = 1024 * 1024;

Expand Down Expand Up @@ -4112,7 +4196,7 @@ static bool ParseTIFFIFD(const StreamReader& sr,
}
}

if (len != (image.samples_per_pixel * 2)) {
if (size_t(len) != (size_t(image.samples_per_pixel) * 2)) {
if (err) {
(*err) += "Counts in NoisProfile must be 2 * SamplesPerPixel.\n";
}
Expand Down Expand Up @@ -4501,7 +4585,7 @@ static bool ParseTIFFIFD(const StreamReader& sr,
unsigned int strip_offset;
if (!sr.read4(&strip_offset)) {
if (err) {
(*err) += "Failed to read StripOffset value.";
(*err) += "Failed to read StripOffset value.\n";
}
return false;
}
Expand Down Expand Up @@ -5847,7 +5931,7 @@ bool LoadDNGFromMemory(const char* mem, unsigned int size,
}
return false;
}
TINY_DNG_DPRINTF("image.data.size = %lld\n", len);
TINY_DNG_DPRINTF("image.data.size = %u\n", uint32_t(len));

image->data.resize(len);
TINY_DNG_DPRINTF("image.data.size = %d\n", int(len));
Expand Down
11 changes: 11 additions & 0 deletions src/image-loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
#pragma clang diagnostic ignored "-Weverything"
#endif

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#endif


#if defined(TINYUSDZ_USE_WUFFS_IMAGE_LOADER)

#include "external/wuffs-unsupported-snapshot.c"
Expand Down Expand Up @@ -92,6 +99,10 @@
#pragma clang diagnostic pop
#endif

#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

#include "image-loader.hh"
#include "io-util.hh"

Expand Down
11 changes: 11 additions & 0 deletions src/image-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
#pragma clang diagnostic ignored "-Weverything"
#endif

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif

#if !defined(TINYUSDZ_NO_STB_IMAGE_RESIZE_IMPLEMENTATION)
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#endif
Expand All @@ -23,6 +30,10 @@
#pragma clang diagnostic pop
#endif

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "image-util.hh"
#include "value-types.hh"
#include "common-macros.inc"
Expand Down
19 changes: 11 additions & 8 deletions src/linear-algebra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ value::quatf slerp(const value::quatf &a, const value::quatf &b, const float t)
linalg::vec<float, 4> qb;
linalg::vec<float, 4> qret;

memcpy(&qa, &a, sizeof(float) * 4);
memcpy(&qb, &b, sizeof(float) * 4);
memcpy(reinterpret_cast<value::quatf *>(&qa), &a, sizeof(float) * 4);
memcpy(reinterpret_cast<value::quatf *>(&qb), &b, sizeof(float) * 4);

qret = linalg::slerp(qa, qb, t);


return *(reinterpret_cast<value::quatf *>(&qret));
value::quatf ret;
memcpy(&ret, reinterpret_cast<value::quatf *>(&qret), sizeof(float) * 4);
return ret;
}

value::quatd slerp(const value::quatd &a, const value::quatd &b, const double t) {
Expand All @@ -61,13 +62,15 @@ value::quatd slerp(const value::quatd &a, const value::quatd &b, const double t)
linalg::vec<double, 4> qb;
linalg::vec<double, 4> qret;

memcpy(&qa, &a, sizeof(double) * 4);
memcpy(&qb, &b, sizeof(double) * 4);
memcpy(reinterpret_cast<value::quatd *>(&qa), &a, sizeof(double) * 4);
memcpy(reinterpret_cast<value::quatd *>(&qb), &b, sizeof(double) * 4);

qret = linalg::slerp(qa, qb, t);

return *(reinterpret_cast<value::quatd *>(&qret));

value::quatd ret;
memcpy(&ret, reinterpret_cast<value::quatd *>(&qret), sizeof(double) * 4);
return ret;

}

float vlength(const value::float3 &a) {
Expand Down
4 changes: 2 additions & 2 deletions src/stream-reader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class StreamReader {
return false;
}

float value;
float value{};
if (!read4(reinterpret_cast<int *>(&value))) {
return false;
}
Expand All @@ -308,7 +308,7 @@ class StreamReader {
return false;
}

double value;
double value{};
if (!read8(reinterpret_cast<uint64_t *>(&value))) {
return false;
}
Expand Down
22 changes: 18 additions & 4 deletions src/tydra/render-data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,18 @@ struct UDIMTexture {
std::unordered_map<uint32_t, int32_t> imageTileIds;
};

// workaround for GCC
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif

// T or TextureId
template <typename T>
struct ShaderParam {
ShaderParam(const T &t) { value = t; }
class ShaderParam {
public:
ShaderParam() = default;
ShaderParam(const T &t) : value(t) { }

bool is_texture() const { return texture_id >= 0; }

Expand All @@ -1078,12 +1086,14 @@ struct ShaderParam {
memcpy(&value, &val, sizeof(T));
}

T value;
//private:
T value{};
int32_t texture_id{-1}; // negative = invalid
};

// UsdPreviewSurface
struct PreviewSurfaceShader {
class PreviewSurfaceShader {
public:
bool useSpecularWorkflow{false};

ShaderParam<vec3> diffuseColor{{0.18f, 0.18f, 0.18f}};
Expand All @@ -1103,6 +1113,10 @@ struct PreviewSurfaceShader {
uint64_t handle{0}; // Handle ID for Graphics API. 0 = invalid
};

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

// Material + Shader
struct RenderMaterial {
std::string name; // elementName in USD (e.g. "pbrMat")
Expand Down
Loading

0 comments on commit 6a15802

Please sign in to comment.