1
/* MapObject 1.2.0 -- image filter plug-in for The Gimp program
3
* Copyright (C) 1996-98 Tom Bech
4
* Copyright (C) 1996-98 Federico Mena Quintero
6
* E-mail: tomb@gimp.org (Tom) or quartic@gimp.org (Federico)
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
#include <libgimp/gimp.h>
28
#include <libgimp/gimpui.h>
30
#include "mapobject_ui.h"
31
#include "mapobject_image.h"
32
#include "mapobject_apply.h"
33
#include "mapobject_preview.h"
34
#include "mapobject_main.h"
36
#include "libgimp/stdplugins-intl.h"
39
/* Global variables */
40
/* ================ */
42
MapObjectValues mapvals;
48
/*************************************/
49
/* Set parameters to standard values */
50
/*************************************/
53
set_default_settings (void)
57
gimp_vector3_set (&mapvals.viewpoint, 0.5, 0.5, 2.0);
58
gimp_vector3_set (&mapvals.firstaxis, 1.0, 0.0, 0.0);
59
gimp_vector3_set (&mapvals.secondaxis, 0.0, 1.0, 0.0);
60
gimp_vector3_set (&mapvals.normal, 0.0, 0.0, 1.0);
61
gimp_vector3_set (&mapvals.position, 0.5, 0.5, 0.0);
62
gimp_vector3_set (&mapvals.lightsource.position, -0.5, -0.5, 2.0);
63
gimp_vector3_set (&mapvals.lightsource.direction, -1.0, -1.0, 1.0);
64
gimp_vector3_set (&mapvals.scale, 0.5, 0.5, 0.5);
66
mapvals.maptype = MAP_PLANE;
68
mapvals.pixeltreshold = 0.25;
72
mapvals.maxdepth = 3.0;
73
mapvals.radius = 0.25;
74
mapvals.cylinder_radius = 0.25;
75
mapvals.cylinder_length = 1.0;
77
mapvals.preview_zoom_factor = 0;
79
mapvals.lightsource.type = POINT_LIGHT;
81
mapvals.antialiasing = TRUE;
82
mapvals.create_new_image = FALSE;
83
mapvals.transparent_background = FALSE;
84
mapvals.tiled = FALSE;
85
mapvals.showgrid = FALSE;
87
mapvals.lightsource.intensity = 1.0;
88
gimp_rgba_set (&mapvals.lightsource.color, 1.0, 1.0, 1.0, 1.0);
90
mapvals.material.ambient_int = 0.3;
91
mapvals.material.diffuse_int = 1.0;
92
mapvals.material.diffuse_ref = 0.5;
93
mapvals.material.specular_ref = 0.5;
94
mapvals.material.highlight = 27.0;
96
for (i = 0; i < 6; i++)
97
mapvals.boxmap_id[i] = -1;
99
for (i = 0; i < 2; i++)
100
mapvals.cylindermap_id[i] = -1;
104
check_drawables (GimpDrawable *drawable)
108
/* Check that boxmap images are valid */
109
/* ================================== */
111
for (i = 0; i < 6; i++)
113
if (mapvals.boxmap_id[i] == -1)
114
mapvals.boxmap_id[i] = drawable->drawable_id;
115
else if (mapvals.boxmap_id[i] != -1 &&
116
gimp_drawable_get_image (mapvals.boxmap_id[i]) == -1)
117
mapvals.boxmap_id[i] = drawable->drawable_id;
118
else if (gimp_drawable_is_gray (mapvals.boxmap_id[i]))
119
mapvals.boxmap_id[i] = drawable->drawable_id;
122
/* Check that cylindermap images are valid */
123
/* ======================================= */
125
for (i = 0; i < 2; i++)
127
if (mapvals.cylindermap_id[i] == -1)
128
mapvals.cylindermap_id[i] = drawable->drawable_id;
129
else if (mapvals.cylindermap_id[i]!=-1 &&
130
gimp_drawable_get_image (mapvals.cylindermap_id[i]) == -1)
131
mapvals.cylindermap_id[i] = drawable->drawable_id;
132
else if (gimp_drawable_is_gray (mapvals.cylindermap_id[i]))
133
mapvals.cylindermap_id[i] = drawable->drawable_id;
140
static GimpParamDef args[] =
142
{ GIMP_PDB_INT32, "run_mode", "Interactive (0), non-interactive (1)" },
143
{ GIMP_PDB_IMAGE, "image", "Input image" },
144
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
145
{ GIMP_PDB_INT32, "maptype", "Type of mapping (0=plane,1=sphere,2=box,3=cylinder)" },
146
{ GIMP_PDB_FLOAT, "viewpoint_x", "Position of viewpoint (x,y,z)" },
147
{ GIMP_PDB_FLOAT, "viewpoint_y", "Position of viewpoint (x,y,z)" },
148
{ GIMP_PDB_FLOAT, "viewpoint_z", "Position of viewpoint (x,y,z)" },
149
{ GIMP_PDB_FLOAT, "position_x", "Object position (x,y,z)" },
150
{ GIMP_PDB_FLOAT, "position_y", "Object position (x,y,z)" },
151
{ GIMP_PDB_FLOAT, "position_z", "Object position (x,y,z)" },
152
{ GIMP_PDB_FLOAT, "firstaxis_x", "First axis of object [x,y,z]" },
153
{ GIMP_PDB_FLOAT, "firstaxis_y", "First axis of object [x,y,z]" },
154
{ GIMP_PDB_FLOAT, "firstaxis_z", "First axis of object [x,y,z]" },
155
{ GIMP_PDB_FLOAT, "secondaxis_x", "Second axis of object [x,y,z]" },
156
{ GIMP_PDB_FLOAT, "secondaxis_y", "Second axis of object [x,y,z]" },
157
{ GIMP_PDB_FLOAT, "secondaxis_z", "Second axis of object [x,y,z]" },
158
{ GIMP_PDB_FLOAT, "rotationangle_x", "Rotation about X axis in degrees" },
159
{ GIMP_PDB_FLOAT, "rotationangle_y", "Rotation about Y axis in degrees" },
160
{ GIMP_PDB_FLOAT, "rotationangle_z", "Rotation about Z axis in degrees" },
161
{ GIMP_PDB_INT32, "lighttype", "Type of lightsource (0=point,1=directional,3=none)" },
162
{ GIMP_PDB_COLOR, "lightcolor", "Lightsource color (r,g,b)" },
163
{ GIMP_PDB_FLOAT, "lightposition_x", "Lightsource position (x,y,z)" },
164
{ GIMP_PDB_FLOAT, "lightposition_y", "Lightsource position (x,y,z)" },
165
{ GIMP_PDB_FLOAT, "lightposition_z", "Lightsource position (x,y,z)" },
166
{ GIMP_PDB_FLOAT, "lightdirection_x", "Lightsource direction [x,y,z]" },
167
{ GIMP_PDB_FLOAT, "lightdirection_y", "Lightsource direction [x,y,z]" },
168
{ GIMP_PDB_FLOAT, "lightdirection_z", "Lightsource direction [x,y,z]" },
169
{ GIMP_PDB_FLOAT, "ambient_intensity", "Material ambient intensity (0..1)" },
170
{ GIMP_PDB_FLOAT, "diffuse_intensity", "Material diffuse intensity (0..1)" },
171
{ GIMP_PDB_FLOAT, "diffuse_reflectivity", "Material diffuse reflectivity (0..1)" },
172
{ GIMP_PDB_FLOAT, "specular_reflectivity", "Material specular reflectivity (0..1)" },
173
{ GIMP_PDB_FLOAT, "highlight", "Material highlight (0..->), note: it's expotential" },
174
{ GIMP_PDB_INT32, "antialiasing", "Apply antialiasing (TRUE/FALSE)" },
175
{ GIMP_PDB_INT32, "tiled", "Tile source image (TRUE/FALSE)" },
176
{ GIMP_PDB_INT32, "newimage", "Create a new image (TRUE/FALSE)" },
177
{ GIMP_PDB_INT32, "transparentbackground", "Make background transparent (TRUE/FALSE)" },
178
{ GIMP_PDB_FLOAT, "radius", "Sphere/cylinder radius (only used when maptype=1 or 3)" },
179
{ GIMP_PDB_FLOAT, "x_scale", "Box x size (0..->)" },
180
{ GIMP_PDB_FLOAT, "y_scale", "Box y size (0..->)" },
181
{ GIMP_PDB_FLOAT, "z_scale", "Box z size (0..->)"},
182
{ GIMP_PDB_FLOAT, "cylinder_length", "Cylinder length (0..->)"},
183
{ GIMP_PDB_DRAWABLE, "box_front_drawable", "Box front face (set these to -1 if not used)" },
184
{ GIMP_PDB_DRAWABLE, "box_back_drawable", "Box back face" },
185
{ GIMP_PDB_DRAWABLE, "box_top_drawable", "Box top face" },
186
{ GIMP_PDB_DRAWABLE, "box_bottom_drawable", "Box bottom face" },
187
{ GIMP_PDB_DRAWABLE, "box_left_drawable", "Box left face" },
188
{ GIMP_PDB_DRAWABLE, "box_right_drawable", "Box right face" },
189
{ GIMP_PDB_DRAWABLE, "cyl_top_drawable", "Cylinder top face (set these to -1 if not used)" },
190
{ GIMP_PDB_DRAWABLE, "cyl_bottom_drawable", "Cylinder bottom face" }
193
gimp_install_procedure ("plug_in_map_object",
194
"Maps a picture to a object (plane, sphere, box or cylinder)",
196
"Tom Bech & Federico Mena Quintero",
197
"Tom Bech & Federico Mena Quintero",
198
"Version 1.2.0, July 16 1998",
199
N_("Map _Object..."),
202
G_N_ELEMENTS (args), 0,
205
gimp_plugin_menu_register ("plug_in_map_object", "<Image>/Filters/Map");
209
run (const gchar *name,
211
const GimpParam *param,
213
GimpParam **return_vals)
215
static GimpParam values[1];
216
GimpDrawable *drawable;
217
GimpRunMode run_mode;
218
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
221
run_mode = param[0].data.d_int32;
225
values[0].type = GIMP_PDB_STATUS;
226
values[0].data.d_status = status;
229
*return_vals = values;
231
/* Set default values */
232
/* ================== */
234
set_default_settings ();
236
/* Get the specified drawable */
237
/* ========================== */
239
drawable = gimp_drawable_get (param[2].data.d_drawable);
243
case GIMP_RUN_INTERACTIVE:
245
/* Possibly retrieve data */
246
/* ====================== */
248
gimp_get_data ("plug_in_map_object", &mapvals);
249
check_drawables (drawable);
250
if (main_dialog (drawable))
254
gimp_set_data ("plug_in_map_object",
255
&mapvals, sizeof (MapObjectValues));
259
case GIMP_RUN_WITH_LAST_VALS:
260
gimp_get_data ("plug_in_map_object", &mapvals);
261
check_drawables (drawable);
262
image_setup (drawable, FALSE);
266
case GIMP_RUN_NONINTERACTIVE:
269
status = GIMP_PDB_CALLING_ERROR;
273
mapvals.maptype = (MapType) param[3].data.d_int32;
274
mapvals.viewpoint.x = param[4].data.d_float;
275
mapvals.viewpoint.y = param[5].data.d_float;
276
mapvals.viewpoint.z = param[6].data.d_float;
277
mapvals.position.x = param[7].data.d_float;
278
mapvals.position.y = param[8].data.d_float;
279
mapvals.position.z = param[9].data.d_float;
280
mapvals.firstaxis.x = param[10].data.d_float;
281
mapvals.firstaxis.y = param[11].data.d_float;
282
mapvals.firstaxis.z = param[12].data.d_float;
283
mapvals.secondaxis.x = param[13].data.d_float;
284
mapvals.secondaxis.y = param[14].data.d_float;
285
mapvals.secondaxis.z = param[15].data.d_float;
286
mapvals.alpha = param[16].data.d_float;
287
mapvals.beta = param[17].data.d_float;
288
mapvals.gamma = param[18].data.d_float;
289
mapvals.lightsource.type = (LightType) param[19].data.d_int32;
290
mapvals.lightsource.color = param[20].data.d_color;
291
mapvals.lightsource.position.x = param[21].data.d_float;
292
mapvals.lightsource.position.y = param[22].data.d_float;
293
mapvals.lightsource.position.z = param[23].data.d_float;
294
mapvals.lightsource.direction.x = param[24].data.d_float;
295
mapvals.lightsource.direction.y = param[25].data.d_float;
296
mapvals.lightsource.direction.z = param[26].data.d_float;
297
mapvals.material.ambient_int = param[27].data.d_float;
298
mapvals.material.diffuse_int = param[28].data.d_float;
299
mapvals.material.diffuse_ref = param[29].data.d_float;
300
mapvals.material.specular_ref = param[30].data.d_float;
301
mapvals.material.highlight = param[31].data.d_float;
302
mapvals.antialiasing = (gint) param[32].data.d_int32;
303
mapvals.tiled = (gint) param[33].data.d_int32;
304
mapvals.create_new_image = (gint) param[34].data.d_int32;
305
mapvals.transparent_background = (gint) param[35].data.d_int32;
306
mapvals.radius = param[36].data.d_float;
307
mapvals.cylinder_radius = param[36].data.d_float;
308
mapvals.scale.x = param[37].data.d_float;
309
mapvals.scale.y = param[38].data.d_float;
310
mapvals.scale.z = param[39].data.d_float;
311
mapvals.cylinder_length = param[40].data.d_float;
313
for (i = 0; i < 6; i++)
314
mapvals.boxmap_id[i] = param[41+i].data.d_drawable;
316
for (i = 0; i < 2; i++)
317
mapvals.cylindermap_id[i] = param[47+i].data.d_drawable;
319
check_drawables (drawable);
320
image_setup (drawable, FALSE);
326
values[0].data.d_status = status;
328
if (run_mode != GIMP_RUN_NONINTERACTIVE)
329
gimp_displays_flush ();
331
gimp_drawable_detach (drawable);
334
GimpPlugInInfo PLUG_IN_INFO =
336
NULL, /* init_proc */
337
NULL, /* quit_proc */
338
query, /* query_proc */