Commit: 677c606dcb61b19b44790f06ee3c10aedfe5d340
Author: Nicholas Bishop
Date: Mon Jan 19 15:59:28 2015 +0100
Branches: cycles-ptex-49
https://developer.blender.org/rB677c606dcb61b19b44790f06ee3c10aedfe5d340
Add new CustomData layers for Ptex
===================================================================
A source/blender/blenkernel/BKE_ptex.h
M source/blender/blenkernel/CMakeLists.txt
M source/blender/blenkernel/SConscript
A source/blender/blenkernel/intern/bke_ptex.c
M source/blender/blenkernel/intern/customdata.c
M source/blender/makesdna/DNA_customdata_types.h
M source/blender/makesdna/DNA_meshdata_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_ptex.h
b/source/blender/blenkernel/BKE_ptex.h
new file mode 100644
index 0000000..f8677da
--- /dev/null
+++ b/source/blender/blenkernel/BKE_ptex.h
@@ -0,0 +1,91 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef __BKE_PTEX_H__
+#define __BKE_PTEX_H__
+
+#include "DNA_customdata_types.h"
+#include "DNA_meshdata_types.h"
+
+struct DerivedMesh;
+struct Image;
+struct Mesh;
+struct Object;
+
+void BKE_loop_ptex_init(MLoopPtex *loop_ptex,
+ const MPtexTexelInfo texel_info,
+ const MPtexLogRes log_res);
+
+void BKE_loop_ptex_pattern_fill(MLoopPtex *loop_ptex, int index);
+
+struct Image *
+BKE_ptex_mesh_image_get(struct Object *ob,
+ const char
layer_name[MAX_CUSTOMDATA_LAYER_NAME]);
+
+/* Free contents of loop_ptex, but not loop_ptex itself */
+void BKE_loop_ptex_free(MLoopPtex *loop_ptex);
+
+size_t BKE_loop_ptex_rect_num_bytes(const MLoopPtex *loop_ptex);
+
+size_t BKE_ptex_rect_num_bytes(const MPtexTexelInfo texel_info,
+ const MPtexLogRes
res);
+
+size_t BKE_ptex_bytes_per_texel(const MPtexTexelInfo texel_info);
+
+/* SDNA uses built-in type, these just convert to enum member */
+PtexDataType BKE_ptex_texel_data_type(const MPtexTexelInfo texel_info);
+PtexDataType BKE_loop_ptex_texel_data_type(const MLoopPtex *loop_ptex);
+
+void BKE_loop_ptex_resize(MLoopPtex *loop_ptex, const MPtexLogRes logres);
+
+void BKE_ptex_update_from_image(MLoopPtex *loop_ptex, const int totloop);
+
+/* Add CD_LOOP_PTEX layer to DerivedMesh. The 'id' field will be just
+ * the sequential loop indices, TODO */
+void BKE_ptex_derived_mesh_inject(struct DerivedMesh *dm);
+
+struct DerivedMesh *BKE_ptex_derived_mesh_subdivide(struct DerivedMesh *dm);
+
+/* TODO */
+/* CustomData layer, not saved in file */
+/* TODO, should have different name now */
+typedef struct {
+ float uv[2];
+ int id;
+} MLoopInterp;
+
+void BKE_ptex_derived_mesh_interp_coords(struct DerivedMesh *dm);
+
+void BKE_ptex_tess_face_interp(MTessFacePtex *tess_face_ptex,
+ const MLoopInterp
*loop_interp,
+ const unsigned int
*loop_indices,
+ const int
num_loop_indices);
+
+/* Convert texel resolution to MPtexLogRes. Inputs must be
+ * powers-of-two and within the valid range. Return true if
+ * successful, false otherwise. */
+bool BKE_ptex_log_res_from_res(MPtexLogRes *logres, const int u, const int v);
+
+bool BKE_ptex_texel_info_init(MPtexTexelInfo *texel_info,
+ const PtexDataType
data_type,
+ const int
num_channels);
+
+bool BKE_ptex_import(struct Mesh *me, const char filepath[]);
+
+#endif
diff --git a/source/blender/blenkernel/CMakeLists.txt
b/source/blender/blenkernel/CMakeLists.txt
index b3469ce..7d4e876 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -48,6 +48,7 @@ set(INC
../../../intern/smoke/extern
../../../intern/atomic
../../../extern/libmv
+ ../../../extern/ptex
# XXX - BAD LEVEL CALL WM_api.h
../windowmanager
@@ -68,6 +69,7 @@ set(SRC
intern/appdir.c
intern/armature.c
intern/autoexec.c
+ intern/bke_ptex.c
intern/blender.c
intern/bmfont.c
intern/boids.c
@@ -250,6 +252,7 @@ set(SRC
BKE_pbvh.h
BKE_pointcache.h
BKE_property.h
+ BKE_ptex.h
BKE_report.h
BKE_rigidbody.h
BKE_sca.h
diff --git a/source/blender/blenkernel/SConscript
b/source/blender/blenkernel/SConscript
index 47bba5f..bc75d56 100644
--- a/source/blender/blenkernel/SConscript
+++ b/source/blender/blenkernel/SConscript
@@ -45,6 +45,7 @@ incs = [
'#/intern/raskter',
'#/intern/rigidbody',
'#/extern/bullet2/src',
+ '#/extern/ptex',
env['BF_GLEW_INC'],
'#/intern/ghost',
'#/intern/glew-mx',
diff --git a/source/blender/blenkernel/intern/bke_ptex.c
b/source/blender/blenkernel/intern/bke_ptex.c
new file mode 100644
index 0000000..f056311
--- /dev/null
+++ b/source/blender/blenkernel/intern/bke_ptex.c
@@ -0,0 +1,944 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <string.h>
+
+#include "BLI_utildefines.h"
+
+#include "BKE_customdata.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_image.h"
+#include "BKE_mesh.h"
+#include "BKE_ptex.h"
+#include "BKE_subsurf.h"
+#include "BLI_math_base.h"
+#include "BLI_math_interp.h"
+#include "BLI_math_vector.h"
+#include "DNA_image_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_modifier_types.h"
+#include "GPU_extensions.h"
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+#include "MEM_guardedalloc.h"
+#include "BPX_pack.h"
+
+static int ptex_data_type_num_bytes(const PtexDataType data_type)
+{
+ switch (data_type) {
+ case MPTEX_DATA_TYPE_UINT8:
+ return 1;
+ case MPTEX_DATA_TYPE_FLOAT32:
+ return 4;
+ }
+
+ BLI_assert(!"Invalid PtexDataType");
+ return 0;
+}
+
+const int ptex_rlog2_limit = 30;
+static bool ptex_rlog2_valid(const int rlog2)
+{
+ /* Limit sides to about a billion texels */
+ return rlog2 >= 0 && rlog2 <= ptex_rlog2_limit;
+}
+
+static int ptex_res_from_rlog2(const int rlog2)
+{
+ BLI_assert(ptex_rlog2_valid(rlog2));
+ return (1 << rlog2);
+}
+
+static size_t ptex_area_from_logres(const MPtexLogRes logres)
+{
+ return ptex_res_from_rlog2(logres.u) * ptex_res_from_rlog2(logres.v);
+}
+
+/* Like MPtexLogRes, but actual values instead of log */
+typedef struct {
+ int u;
+ int v;
+} MPtexRes;
+
+static MPtexRes bke_ptex_res_from_logres(const MPtexLogRes logres)
+{
+ MPtexRes res = {
+ ptex_res_from_rlog2(logres.u),
+ ptex_res_from_rlog2(logres.v),
+ };
+ return res;
+}
+
+static void ptex_data_from_float(void *dst_v, const float *src,
+ const
PtexDataType data_type,
+ const size_t
count)
+{
+ int i;
+ switch (data_type) {
+ case MPTEX_DATA_TYPE_UINT8:
+ {
+ uint8_t *dst = dst_v;
+ for (i = 0; i < count; i++) {
+ dst[i] = FTOCHAR(src[i]);
+ }
+ return;
+ }
+
+ case MPTEX_DATA_TYPE_FLOAT32:
+ {
+ memcpy(dst_v, src, sizeof(*src) * count);
+ return;
+ }
+ }
+
+ BLI_assert(!"Invalid PtexDataType");
+}
+
+size_t BKE_ptex_bytes_per_texel(const MPtexTexelInfo texel_info)
+{
+ return (ptex_data_type_num_bytes(texel_info.data_type) *
+ texel_info.num_channels);
+}
+
+size_t BKE_ptex_rect_num_bytes(const MPtexTexelInfo texel_info,
+ const MPtexLogRes
logres)
+{
+ return (BKE_ptex_bytes_per_texel(texel_info) *
+ ptex_area_from_logres(logres));
+}
+
+size_t BKE_loop_ptex_rect_num_bytes(const MLoopPtex *loop_ptex)
+{
+ return BKE_ptex_rect_num_bytes(loop_ptex->texel_info,
+
loop_ptex->logres);
+}
+
+static void *bke_ptex_texels_calloc(const MPtexTexelInfo texel_info,
+ const
MPtexLogRes logres)
+{
+ return MEM_callocN(BKE_ptex_rect_num_bytes(texel_info, logres),
+ "bke_ptex_texels_calloc");
+}
+
+static void *bke_ptex_texels_malloc(const MPtexTexelInfo texel_info,
+ const
MPtexLogRes logres)
+{
+ return MEM_mallocN(BKE_ptex_rect_num_bytes(texel_info, logres),
+ "bke_ptex_texels_malloc");
+}
+
+void BKE_loop_ptex_init(MLoopPtex *loop_ptex,
+ const MPtexTexelInfo texel_info,
+ const MPtexLogRes logres)
+{
+ BLI_assert(ptex_rlog2_valid(logres.u));
+ BLI_assert(ptex_rlog2_valid(logres.v));
+ BLI_assert(texel_info.num_channels >= 1 &&
+ texel_info.num_channels < 255);
+
+ loop_ptex->texel_info = texel_info;
+ loop_ptex->logres = logres;
+
+ loop_ptex->rect = bke_ptex_texels_calloc(texel_info, logres);
+}
+
+/* TODO: for testing, fill initialized loop with some data */
+void BKE_loop_ptex_pattern_fill(MLoopPtex *lp, const int index)
+{
+ const int u_res = ptex_res_from_rlog2(lp->logres.u);
+ const int v_res = ptex_res_from_rlog2(lp->logres.v);
+ const int bytes_per_texel = BKE_ptex_bytes_per_texel(lp->texel_info);
+ char *dst = lp->rect;
+ int x, y;
+ BLI_assert(lp->texel_info.num_channels <= 4);
+ for (y = 0; y < v_res; y++) {
+ for (x = 0; x < u_res; x++) {
+ const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
+ float rgba[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ const float u = (float)x / (float)(u_res - 1);
+ const float v = (float)y / (float)(v_res - 1);
+ const float z = ((float)index) / 2.0f;
+ rgba[0] = u;
+ rgba[1] = v;
+ rgba[2] = z;
+ rgba[3] = 1.0f;
+ if (index == 0) {
+ rgba[0] = 1.0f; rgba[1] = 0.0f; rgba[2] = 0.0f;
+ }
+ else if (index == 1) {
+ rgba[0] = 0.0f; rgba[1] = 1.0f; rgba[2] = 0.0f;
+ }
+ else if (index == 2) {
+ rgba[0] = 0.0f; rgba[1] = 0.0f; rgba[2] = 1.0f;
+ }
+ else if (index == 3) {
+ rgba[0] = 1.0f; rgba[1] = 1.0f; rgba[2] = 0.0f;
+ }
+
+ if (u == 0 && v == 0) {
+ copy_v4_v4(rgba, white);
+ }
+ else if (u == 0) {
+ int c;
+ for (c = 0; c < 3; c++) {
+ if (rgba[c] == 0) {
+ rgba[c] += 0.5;
+ }
+ }
+ }
+ ptex_data_from_float(dst, rgba,
+
lp->texel_info.data_type,
+
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs