-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hdEmbree] ies.h / ies.cpp: patch, and add pxr-IES.patch and README.md
- Loading branch information
Showing
4 changed files
with
216 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# IES utilities | ||
|
||
Utilities for reading and using .ies files (IESNA LM-63 Format), which are used | ||
to describe lights. | ||
|
||
The files `ies.h` and `ies.cpp` are originally from | ||
[Cycles](https://docs.blender.org/manual/en/latest/render/cycles/index.html), | ||
which is part of the larger | ||
[Blender](https://projects.blender.org/blender/blender/) project, though with | ||
a the less restrictive Apache 2.0 license - see: | ||
|
||
- https://www.blender.org/about/license/ | ||
|
||
## Version | ||
|
||
v4.1.1 ( 53c49589f311bd3c9e3ea8f62b3fa8fe8e5d2c8c ) | ||
|
||
## Setup | ||
|
||
When updating IES, the following steps should be followed: | ||
|
||
1. Copy `intern/cycles/util/ies.h` and `intern/cycles/util/ies.cpp` over the | ||
copies in `pxr/imaging/plugin/hdEmbree/pxrIES`. | ||
2. Apply `pxr-IES.patch` to update the source files with modifications for USD, | ||
ie, from the USD repo root folder: | ||
|
||
```sh | ||
patch -p1 -i pxr/imaging/plugin/hdEmbree/pxrIES/pxr-IES.patch | ||
``` | ||
3. Commit your changes, noting the exact version of blender that the new ies | ||
files were copied from. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp | ||
index a6725cc04..7a6917303 100644 | ||
--- a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp | ||
+++ b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp | ||
@@ -2,21 +2,22 @@ | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
+#include "ies.h" | ||
#include <algorithm> | ||
+#include <cstring> | ||
|
||
-#include "util/foreach.h" | ||
-#include "util/ies.h" | ||
-#include "util/math.h" | ||
-#include "util/string.h" | ||
+#define _USE_MATH_DEFINES | ||
+#include <cmath> | ||
|
||
-CCL_NAMESPACE_BEGIN | ||
+#if !defined(M_PI) | ||
+#define M_PI 3.14159265358979323846 | ||
+#endif | ||
|
||
-// NOTE: For some reason gcc-7.2 does not instantiate this version of the | ||
-// allocator here (used in IESTextParser). Works fine for gcc-6, gcc-7.3 and gcc-8. | ||
-// | ||
-// TODO(sergey): Get to the root of this issue, or confirm this is a compiler | ||
-// issue. | ||
-template class GuardedAllocator<char>; | ||
+#define M_PI_F M_PI | ||
+ | ||
+PXR_NAMESPACE_OPEN_SCOPE | ||
+ | ||
+namespace pxr_ccl { | ||
|
||
bool IESFile::load(const string &ies) | ||
{ | ||
@@ -43,11 +44,28 @@ int IESFile::packed_size() | ||
return 0; | ||
} | ||
|
||
+template <class To, class From> | ||
+std::enable_if_t<sizeof(To) == sizeof(From) && | ||
+ std::is_trivially_copyable_v<From> && | ||
+ std::is_trivially_copyable_v<To>, | ||
+ To> | ||
+// constexpr support needs compiler magic | ||
+bit_cast(const From &src) noexcept | ||
+{ | ||
+ static_assert(std::is_trivially_constructible_v<To>, | ||
+ "This implementation additionally requires " | ||
+ "destination type to be trivially constructible"); | ||
+ | ||
+ To dst; | ||
+ std::memcpy(&dst, &src, sizeof(To)); | ||
+ return dst; | ||
+} | ||
+ | ||
void IESFile::pack(float *data) | ||
{ | ||
if (v_angles.size() && h_angles.size()) { | ||
- *(data++) = __int_as_float(h_angles.size()); | ||
- *(data++) = __int_as_float(v_angles.size()); | ||
+ *(data++) = bit_cast<float>(static_cast<int>(h_angles.size())); | ||
+ *(data++) = bit_cast<float>(static_cast<int>(v_angles.size())); | ||
|
||
memcpy(data, &h_angles[0], h_angles.size() * sizeof(float)); | ||
data += h_angles.size(); | ||
@@ -407,4 +425,7 @@ IESFile::~IESFile() | ||
clear(); | ||
} | ||
|
||
-CCL_NAMESPACE_END | ||
+} // namespace pxr_ccl | ||
+ | ||
+PXR_NAMESPACE_CLOSE_SCOPE | ||
+ | ||
diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h | ||
index 8c506befd..051c23f6c 100644 | ||
--- a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h | ||
+++ b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h | ||
@@ -5,10 +5,18 @@ | ||
#ifndef __UTIL_IES_H__ | ||
#define __UTIL_IES_H__ | ||
|
||
-#include "util/string.h" | ||
-#include "util/vector.h" | ||
+#include <string> | ||
+#include <vector> | ||
+ | ||
+using std::string; | ||
+using std::vector; | ||
+ | ||
+#include "pxr/pxr.h" | ||
+ | ||
+PXR_NAMESPACE_OPEN_SCOPE | ||
+ | ||
+namespace pxr_ccl { | ||
|
||
-CCL_NAMESPACE_BEGIN | ||
|
||
class IESFile { | ||
public: | ||
@@ -19,11 +27,16 @@ class IESFile { | ||
void pack(float *data); | ||
|
||
bool load(const string &ies); | ||
+ | ||
+ virtual | ||
void clear(); | ||
|
||
protected: | ||
bool parse(const string &ies); | ||
+ | ||
+ virtual | ||
bool process(); | ||
+ | ||
void process_type_a(); | ||
void process_type_b(); | ||
void process_type_c(); | ||
@@ -41,6 +54,8 @@ class IESFile { | ||
enum IESType { TYPE_A = 3, TYPE_B = 2, TYPE_C = 1 } type; | ||
}; | ||
|
||
-CCL_NAMESPACE_END | ||
+} // namespace pxr_ccl | ||
+ | ||
+PXR_NAMESPACE_CLOSE_SCOPE | ||
|
||
#endif /* __UTIL_IES_H__ */ |