Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LOD_ExternBufferEditor.h « intern « decimation « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f628c4455b4c81a4f80d5efc2085b722942d07c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
 * $Id$
 * ***** BEGIN GPL/BL DUAL 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. The Blender
 * Foundation also sells licenses for use in proprietary software under
 * the Blender License.  See http://www.blender.org/BL/ for information
 * about this.
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * Contributor(s): none yet.
 *
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 */

/**

 * $Id$
 * Copyright (C) 2001 NaN Technologies B.V.
 */

#ifndef NAN_INCLUDED_LOD_ExternBufferEditor_h
#define NAN_INCLUDED_LOD_ExternBufferEditor_h

#include "LOD_MeshPrimitives.h"
#include <vector>
#include "LOD_ManMesh2.h"
#include "../extern/LOD_decimation.h"


// This class syncs external vertex/face buffers 
// with the internal mesh representation during
// decimation.

class LOD_ExternBufferEditor 
{

public :

	static 
		LOD_ExternBufferEditor *
	New(
		LOD_Decimation_InfoPtr extern_info
	){
		if (extern_info == NULL) return NULL;
		return new LOD_ExternBufferEditor(extern_info);
	}
	
	// update the external vertex buffer with vertices
	// from the mesh

		void
	CopyModifiedVerts(
		LOD_ManMesh2 & mesh,
		const std::vector<LOD_VertexInd> & mod_vertices
	){
	
		std::vector<LOD_VertexInd>::const_iterator v_start = mod_vertices.begin();
		std::vector<LOD_VertexInd>::const_iterator v_end = mod_vertices.end();

		std::vector<LOD_Vertex> & mesh_verts = mesh.VertexSet();

		float * const extern_vertex_ptr = m_extern_info->vertex_buffer;

		for (; v_start != v_end; ++v_start) {
			float * mod_vert = extern_vertex_ptr + int(*v_start)*3;
			mesh_verts[*v_start].CopyPosition(mod_vert);
		}
	}			
		
	// update the external face buffer with faces from the mesh

		void
	CopyModifiedFaces(
		LOD_ManMesh2 & mesh,
		const std::vector<LOD_FaceInd> & mod_faces
	){
	
		std::vector<LOD_FaceInd>::const_iterator f_start = mod_faces.begin();
		std::vector<LOD_FaceInd>::const_iterator f_end = mod_faces.end();

		std::vector<LOD_TriFace> &mesh_faces = mesh.FaceSet();

		int * const extern_face_ptr = m_extern_info->triangle_index_buffer;

		for (; f_start != f_end; ++f_start) {
			int *mod_face = extern_face_ptr + 3*int(*f_start);
			mesh_faces[*f_start].CopyVerts(mod_face);
		}
	}


	// Copy the last vertex over the vertex specified by
	// vi. Decrement the size of the vertex array	

		void
	CopyBackVertex(
		LOD_VertexInd vi
	){

		float * const extern_vertex_ptr = m_extern_info->vertex_buffer;
		int * extern_vertex_num = &(m_extern_info->vertex_num);

		float * last_external_vert = extern_vertex_ptr + 3*((*extern_vertex_num) - 1);
		float * external_vert = extern_vertex_ptr + 3*int(vi);

		external_vert[0] = last_external_vert[0];
		external_vert[1] = last_external_vert[1];
		external_vert[2] = last_external_vert[2];

		*extern_vertex_num -=1;
	}

	// Copy the last face over the face specified by fi
	// Decrement the size of the face array

		void
	CopyBackFace(
		LOD_FaceInd fi
	) {
		int * const extern_face_ptr = m_extern_info->triangle_index_buffer;
		int * extern_face_num = &(m_extern_info->face_num);
		
		int * last_external_face = extern_face_ptr + 3*((*extern_face_num) -1);
		int * external_face = extern_face_ptr + 3*int(fi);
		external_face[0] = last_external_face[0];
		external_face[1] = last_external_face[1];
		external_face[2] = last_external_face[2];

		*extern_face_num -=1;
	}	


private :
		
	LOD_ExternBufferEditor(
		LOD_Decimation_InfoPtr extern_info	
	) :
		m_extern_info (extern_info)
	{
	}

	LOD_Decimation_InfoPtr const m_extern_info;

};

#endif