[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31092] branches/soc-2010-nicolasbishop: = = Ptex ==
Nicholas Bishop
nicholasbishop at gmail.com
Fri Aug 6 06:16:34 CEST 2010
Revision: 31092
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31092
Author: nicholasbishop
Date: 2010-08-06 06:16:13 +0200 (Fri, 06 Aug 2010)
Log Message:
-----------
== Ptex ==
Fixes for triangles
* the quad-mesh-with-triangles example file from ptex contains subfaces with
non-matching resolutions; changed the internal MPtex format to store
separate resolutions for each subface
* changed ptex drawing to give each subface its own texture
* various fixes to the loading and painting code to support triangles
* small change to the ptex build files, hopefully fixes and MSVC issue
Modified Paths:
--------------
branches/soc-2010-nicolasbishop/extern/ptex/CMakeLists.txt
branches/soc-2010-nicolasbishop/extern/ptex/SConscript
branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/writefile.c
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/ptex.c
branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
branches/soc-2010-nicolasbishop/source/blender/makesdna/DNA_meshdata_types.h
Modified: branches/soc-2010-nicolasbishop/extern/ptex/CMakeLists.txt
===================================================================
--- branches/soc-2010-nicolasbishop/extern/ptex/CMakeLists.txt 2010-08-06 03:52:13 UTC (rev 31091)
+++ branches/soc-2010-nicolasbishop/extern/ptex/CMakeLists.txt 2010-08-06 04:16:13 UTC (rev 31092)
@@ -14,5 +14,7 @@
ptex_C_api.cpp
)
+ADD_DEFINITIONS(-DPTEX_STATIC)
+
BLENDERLIB(extern_ptex "${SRC}" "${INC}")
Modified: branches/soc-2010-nicolasbishop/extern/ptex/SConscript
===================================================================
--- branches/soc-2010-nicolasbishop/extern/ptex/SConscript 2010-08-06 03:52:13 UTC (rev 31091)
+++ branches/soc-2010-nicolasbishop/extern/ptex/SConscript 2010-08-06 04:16:13 UTC (rev 31092)
@@ -8,7 +8,7 @@
sources = env.Glob('src/ptex/*.cpp')
sources += env.Glob('*.cpp')
-defs = ''
+defs = 'PTEX_STATIC'
incs = 'src/ptex'
incs += ' ' + env['BF_ZLIB_INC']
Modified: branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/writefile.c 2010-08-06 03:52:13 UTC (rev 31091)
+++ branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/writefile.c 2010-08-06 04:16:13 UTC (rev 31092)
@@ -1510,16 +1510,16 @@
static void write_customdata_mptex(WriteData *wd, int count,
MPtex *mptex)
{
- int i;
+ int i, j;
writestruct(wd, DATA, "MPtex", count, mptex);
for(i = 0; i < count; ++i, ++mptex) {
int layersize = mptex->channels * ptex_data_size(mptex->type);
- float texels = mptex->ures*mptex->vres;
+ int texels;
- if(mptex->subfaces)
- texels *= mptex->subfaces;
+ for(j = 0, texels = 0; j < mptex->subfaces; ++j)
+ texels += mptex->res[j][0] * mptex->res[j][1];
writedata(wd, DATA, layersize * texels,
mptex->data);
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c 2010-08-06 03:52:13 UTC (rev 31091)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c 2010-08-06 04:16:13 UTC (rev 31092)
@@ -1729,7 +1729,7 @@
}
static void vpaint_ptex_from_quad(Brush *brush, PaintStroke *stroke, PaintStrokeTest *test,
- MPtex *pt, char *data,
+ MPtex *pt, int res[2], char *data,
float v1[3], float v2[3], float v3[3], float v4[3])
{
@@ -1742,20 +1742,20 @@
sub_v3_v3v3(dtop, v1, v2);
sub_v3_v3v3(dbot, v4, v3);;
ustep = 1;
- if(pt->ures != 1)
- ustep /= (pt->ures - 1);
+ if(res[0] != 1)
+ ustep /= (res[0] - 1);
mul_v3_fl(dtop, ustep);
mul_v3_fl(dbot, ustep);
vstep = 1;
- if(pt->vres != 1)
- vstep /= (pt->vres - 1);
+ if(res[1] != 1)
+ vstep /= (res[1] - 1);
- for(v = 0, yinterp = 0; v < pt->vres; ++v) {
+ for(v = 0, yinterp = 0; v < res[1]; ++v) {
copy_v3_v3(co_top, v2);
copy_v3_v3(co_bot, v3);
- for(u = 0; u < pt->ures; ++u, data += layersize) {
+ for(u = 0; u < res[0]; ++u, data += layersize) {
float co[3];
interp_v3_v3v3(co, co_bot, co_top, yinterp);
@@ -1772,10 +1772,6 @@
ptex_elem_from_float4(pt->type, pt->channels, data, fcol);
}
- /*(*color)[0] = u / (pt->ures-1.0f);
- (*color)[1] = v / (pt->vres-1.0f);
- (*color)[2] = 1;*/
-
add_v3_v3(co_bot, dbot);
add_v3_v3(co_top, dtop);
}
@@ -1811,7 +1807,8 @@
if(S == 4) {
/* fast case */
- vpaint_ptex_from_quad(brush, stroke, &test, pt, pt->data,
+ vpaint_ptex_from_quad(brush, stroke, &test, pt,
+ pt->res[0], pt->data,
mvert[f->v3].co, mvert[f->v4].co,
mvert[f->v1].co, mvert[f->v2].co);
}
@@ -1822,6 +1819,7 @@
float half[4][3], center[3];
int layersize = pt->channels * ptex_data_size(pt->type);
+ char *data = pt->data;
for(j = 0; j < 3; ++j) {
int next = (j == S-1) ? 0 : j+1;
@@ -1833,13 +1831,14 @@
for(j = 0; j < 3; ++j) {
int vndx = (&f->v1)[j];
int prev = j==0 ? S-1 : j-1;
- char *data = pt->data;
- data += layersize*pt->ures*pt->vres * j;
-
+
vpaint_ptex_from_quad(brush, stroke, &test, pt,
- data,
- mvert[vndx].co, half[j],
- center, half[prev]);
+ pt->res[j], data,
+ center, half[prev],
+ mvert[vndx].co, half[j]);
+
+ data += layersize * pt->res[j][0]*pt->res[j][1];
+
}
}
}
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/ptex.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/ptex.c 2010-08-06 03:52:13 UTC (rev 31091)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/ptex.c 2010-08-06 04:16:13 UTC (rev 31092)
@@ -137,8 +137,8 @@
vres = MAX2(vres, 1);
gridsize = ures * vres;
- mptex[i].ures = ures;
- mptex[i].vres = vres;
+ mptex[i].res[0][0] = ures;
+ mptex[i].res[0][1] = vres;
mptex[i].type = type;
mptex[i].channels = totchannel;
@@ -147,6 +147,8 @@
texels = gridsize;
}
else {
+ mptex[i].res[1][0] = mptex[i].res[2][0] = ures;
+ mptex[i].res[1][1] = mptex[i].res[2][1] = vres;
mptex[i].subfaces = S;
texels = S*gridsize;
}
@@ -209,7 +211,7 @@
PtexTextureHandle *ptex_texture;
PtexDataType ptex_data_type;
- int totchannel;
+ int totchannel, layersize;
char *path;
int i, j;
@@ -242,7 +244,7 @@
}
/* check that ptex file matches mesh topology */
- for(i = 0, j = 0; i < me->totface; ++i, j += (me->mface[i].v4 ? 1 : 3)) {
+ for(i = 0, j = 0; i < me->totface; ++i) {
MFace *f = &me->mface[i];
PtexFaceInfoHandle *ptex_face = ptex_texture_get_face_info(ptex_texture, j);
int subface;
@@ -261,44 +263,54 @@
return OPERATOR_CANCELLED;
}
- /* TODO: check that all subfaces of a particular face have the same resolution */
+ j += (f->v4 ? 1 : 3);
}
+ /* number of bytes for one ptex element */
+ layersize = ptex_data_size(ptex_data_type) * totchannel;
+
mptex = CustomData_add_layer(&me->fdata, CD_MPTEX, CD_CALLOC,
NULL, me->totface);
- /* TODO: for now, just convert to customdata ptex */
- for(i = 0, j = 0; i < me->totface; ++i, j += (me->mface[i].v4 ? 1 : 3)) {
+ for(i = 0, j = 0; i < me->totface; ++i) {
int S = me->mface[i].v4 ? 4 : 3;
- PtexFaceInfoHandle *ptex_face;
- PtexResHandle *ptex_res;
- int texels;
+ int k, texels, faceid;
+ char *data;
- ptex_face = ptex_texture_get_face_info(ptex_texture, j);
- ptex_res = ptex_face_get_res(ptex_face);
-
- mptex[i].ures = ptex_res_u(ptex_res);
- mptex[i].vres = ptex_res_v(ptex_res);
mptex[i].type = ptex_data_type;
mptex[i].channels = totchannel;
- if(S == 4) {
- mptex[i].subfaces = 0;
- texels = mptex[i].ures * mptex[i].vres;
+ mptex[i].subfaces = (S==4? 1 : S);
+
+ /* get quad resolution or per-subface resolutions */
+ for(k = 0, texels = 0; k < mptex[i].subfaces; ++k) {
+ PtexFaceInfoHandle *ptex_face;
+ PtexResHandle *ptex_res;
+
+ faceid = j+k;
+
+ ptex_face = ptex_texture_get_face_info(ptex_texture, faceid);
+ ptex_res = ptex_face_get_res(ptex_face);
+
+ mptex[i].res[k][0] = ptex_res_u(ptex_res);
+ mptex[i].res[k][1] = ptex_res_v(ptex_res);
+
+ texels += mptex[i].res[k][0] * mptex[i].res[k][1];
}
- else {
- mptex[i].subfaces = S;
- mptex[i].ures = ptex_res_u(ptex_res);
- mptex[i].vres = ptex_res_v(ptex_res);
- texels = mptex[i].ures * mptex[i].vres * S;
- }
-
- mptex[i].data = MEM_callocN(ptex_data_size(ptex_data_type) *
- totchannel * texels, "Ptex file data");
- ptex_texture_get_data(ptex_texture, j, mptex[i].data, 0, ptex_res);
+ data = mptex[i].data = MEM_callocN(layersize * texels, "Ptex data from file");
- /* TODO: interleave data? */
+ for(k = 0; k < mptex[i].subfaces; ++k, ++j) {
+ PtexFaceInfoHandle *ptex_face;
+ PtexResHandle *ptex_res;
+
+ ptex_face = ptex_texture_get_face_info(ptex_texture, j);
+ ptex_res = ptex_face_get_res(ptex_face);
+
+ ptex_texture_get_data(ptex_texture, j, data, 0, ptex_res);
+
+ data += layersize * mptex[i].res[k][0] * mptex[i].res[k][1];
+ }
}
/* data is all copied, can release ptex file */
Modified: branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c 2010-08-06 03:52:13 UTC (rev 31091)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c 2010-08-06 04:16:13 UTC (rev 31092)
@@ -770,7 +770,7 @@
MFace *mface;
MPtex *mptex;
int *face_indices, totface;
- int i, j;
+ int i, j, id;
BLI_pbvh_get_customdata(pbvh, NULL, &fdata);
BLI_pbvh_node_get_faces(pbvh, node, &mface, &face_indices, NULL, &totface);
@@ -778,45 +778,38 @@
/* TODO: composite multiple layers */
mptex = CustomData_get_layer(fdata, CD_MPTEX);
- /* pack all ptex for one face into one texture */
+ /* one texture per subface */
if(!buffers->ptex) {
- buffers->totptex = totface;
+ for(i = 0, buffers->totptex = 0; i < totface; ++i)
+ buffers->totptex += mptex[face_indices[i]].subfaces;
+
buffers->ptex = MEM_callocN(sizeof(GLuint) * buffers->totptex, "PTex IDs");
glGenTextures(buffers->totptex, buffers->ptex);
}
- for(i = 0; i < totface; ++i) {
+ for(i = 0, id = 0; i < totface; ++i) {
int face_ndx = face_indices[i];
MPtex *pt = &mptex[face_ndx];
- int S = mface[i].v4 ? 4 : 3;
+ char *data = pt->data;
GLenum gltype = gl_type_from_ptex(pt);
GLenum glformat = gl_format_from_ptex(pt);
+
int layersize = pt->channels * ptex_data_size(pt->type);
-
- glBindTexture(GL_TEXTURE_2D, buffers->ptex[i]);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ for(j = 0; j < pt->subfaces; ++j, ++id) {
+ glBindTexture(GL_TEXTURE_2D, buffers->ptex[id]);
- if(S == 4) {
- /* load quad ptex whole */
- glTexImage2D(GL_TEXTURE_2D, 0, glformat, pt->ures, pt->vres,
- 0, glformat, gltype, pt->data);
- }
- else {
- /* pack non-quads ptex in side by side */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list