|
176 | 176 | eg. |
177 | 177 | #include "my_assert.h" |
178 | 178 | #define ogt_assert(condition, message_str) my_assert(condition, message_str) |
| 179 | + #define ogt_assert_warn(condition, message_str) my_assert(condition, message_str) |
179 | 180 |
|
180 | 181 | #define OGT_VOX_IMPLEMENTATION |
181 | 182 | #include "path/to/ogt_vox.h" |
|
515 | 516 | #ifndef ogt_assert |
516 | 517 | #include <assert.h> |
517 | 518 | #define ogt_assert(x, msg_str) do { assert((x) && (msg_str)); } while(0) |
| 519 | +#endif |
| 520 | +#ifndef ogt_assert_warn |
| 521 | + #define ogt_assert_warn(x, msg_str) ogt_assert(x, msg_str) |
518 | 522 | #endif |
519 | 523 | #include <stdlib.h> |
520 | 524 | #include <string.h> |
|
1282 | 1286 | } |
1283 | 1287 | default: |
1284 | 1288 | { |
1285 | | - ogt_assert(0, "unhandled node type"); |
| 1289 | + ogt_assert_warn(0, "unhandled node type"); |
1286 | 1290 | } |
1287 | 1291 | } |
1288 | 1292 | } |
|
1577 | 1581 | uint8_t y = packed_voxel_data[i * 4 + 1]; |
1578 | 1582 | uint8_t z = packed_voxel_data[i * 4 + 2]; |
1579 | 1583 | uint8_t color_index = packed_voxel_data[i * 4 + 3]; |
1580 | | - ogt_assert(x < size_x && y < size_y && z < size_z, "invalid data in XYZI chunk"); |
1581 | | - if(x < size_x && y < size_y && z < size_z ) { |
| 1584 | + const bool inside_region = x < size_x && y < size_y && z < size_z; |
| 1585 | + ogt_assert_warn(inside_region, "invalid data in XYZI chunk"); |
| 1586 | + if (inside_region) { |
1582 | 1587 | voxel_data[(x * k_stride_x) + (y * k_stride_y) + (z * k_stride_z)] = color_index; |
1583 | 1588 | } |
1584 | 1589 | } |
|
1618 | 1623 | _vox_file_read_uint32(fp, &reserved_id); |
1619 | 1624 | _vox_file_read_uint32(fp, &layer_id); |
1620 | 1625 | _vox_file_read_uint32(fp, &num_frames); |
1621 | | - ogt_assert(reserved_id == UINT32_MAX, "unexpected values for reserved_id in nTRN chunk"); |
1622 | | - ogt_assert(num_frames > 0, "must have at least 1 frame in nTRN chunk"); |
| 1626 | + ogt_assert_warn(reserved_id == UINT32_MAX, "unexpected values for reserved_id in nTRN chunk"); |
| 1627 | + ogt_assert_warn(num_frames > 0, "must have at least 1 frame in nTRN chunk"); |
1623 | 1628 |
|
1624 | 1629 | // make space in misc_data array for the number of transforms we'll need for this node |
1625 | 1630 | ogt_vox_keyframe_transform* keyframes = misc_data.alloc_many<ogt_vox_keyframe_transform>(num_frames); |
|
1733 | 1738 | _vox_file_read_int32(fp, &layer_id); |
1734 | 1739 | _vox_file_read_dict(&dict, fp); |
1735 | 1740 | _vox_file_read_int32(fp, &reserved_id); |
1736 | | - ogt_assert(reserved_id == -1, "unexpected value for reserved_id in LAYR chunk"); |
| 1741 | + ogt_assert_warn(reserved_id == -1, "unexpected value for reserved_id in LAYR chunk"); |
1737 | 1742 |
|
1738 | 1743 | layers.grow_to_fit_index(layer_id); |
1739 | 1744 | layers[layer_id].name = NULL; |
|
2056 | 2061 |
|
2057 | 2062 | if (g_progress_callback_func) { |
2058 | 2063 | // we indicate progress as 0.8f * amount of buffer read + 0.2f at end after processing |
2059 | | - if (!g_progress_callback_func(0.8f*(float)(fp->offset)/(float)(fp->buffer_size), g_progress_callback_user_data)) |
2060 | | - { |
| 2064 | + const float progress = 0.8f * (float)(fp->offset) / (float)(fp->buffer_size); |
| 2065 | + if (!g_progress_callback_func(progress, g_progress_callback_user_data)) { |
2061 | 2066 | return 0; |
2062 | 2067 | } |
2063 | 2068 | } |
|
2483 | 2488 | is_negative = f[i] < 0.0f ? true : false; |
2484 | 2489 | } |
2485 | 2490 | else { |
2486 | | - ogt_assert(f[i] == 0.0f, "rotation vector should contain only 0.0f, 1.0f, or -1.0f"); |
| 2491 | + ogt_assert_warn(f[i] == 0.0f, "rotation vector should contain only 0.0f, 1.0f, or -1.0f"); |
2487 | 2492 | } |
2488 | 2493 | } |
2489 | | - ogt_assert(out_index != 3, "rotation vector was all zeroes but it should be a cardinal axis vector"); |
| 2494 | + ogt_assert_warn(out_index != 3, "rotation vector was all zeroes but it should be a cardinal axis vector"); |
2490 | 2495 | return is_negative; |
2491 | 2496 | } |
2492 | 2497 |
|
|
2499 | 2504 | bool row0_negative = _vox_get_vec3_rotation_bits(row0, row0_index); |
2500 | 2505 | bool row1_negative = _vox_get_vec3_rotation_bits(row1, row1_index); |
2501 | 2506 | bool row2_negative = _vox_get_vec3_rotation_bits(row2, row2_index); |
2502 | | - ogt_assert(((1 << row0_index) | (1 << row1_index) | (1 << row2_index)) == 7, "non orthogonal rows found in transform"); // check that rows are orthogonal. There must be a non-zero entry in column 0, 1 and 2 across these 3 rows. |
| 2507 | + ogt_assert_warn(((1 << row0_index) | (1 << row1_index) | (1 << row2_index)) == 7, "non orthogonal rows found in transform"); // check that rows are orthogonal. There must be a non-zero entry in column 0, 1 and 2 across these 3 rows. |
2503 | 2508 | return (row0_index) | (row1_index << 2) | (row0_negative ? 1 << 4 : 0) | (row1_negative ? 1 << 5 : 0) | (row2_negative ? 1 << 6 : 0); |
2504 | 2509 | } |
2505 | 2510 |
|
|
3054 | 3059 | // check that the buffer is not larger than the maximum file size, return nothing if would overflow |
3055 | 3060 | if (fp->data.count > UINT32_MAX || (fp->data.count - offset_post_main_chunk) > UINT32_MAX) |
3056 | 3061 | { |
3057 | | - ogt_assert(0, "Generated file size exceeded 4GiB, which is too large for Magicavoxel to parse."); |
| 3062 | + ogt_assert_warn(0, "Generated file size exceeded 4GiB, which is too large for Magicavoxel to parse."); |
3058 | 3063 | *buffer_size = 0; |
3059 | 3064 | return NULL; // note: fp will be freed in dtor on exit |
3060 | 3065 | } |
|
0 commit comments