Source code: org/pqt/autorib/instr/InstrGroupEnvMap.java
1 //AutoRIB
2 // Copyright © 1998 - 2002, P W Quint
3 //
4 // Contact: autorib00@aol.com
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 package org.pqt.autorib.instr;
21 import java.io.*;
22 import java.util.*;
23
24 import org.pqt.autorib.tokenizer.*;
25 import org.pqt.autorib.globals.*;
26 import org.pqt.autorib.util.*;
27 import org.pqt.autorib.rib.*;
28
29
30 /** A class to handle the GroupEnvMap instruction, which
31 * creates an environment map using bounding box information
32 * of a named group of objects to deduce
33 * the point from which to 'take' the environment pictures
34 * these objects have the name of the map added in a given
35 * parameter of the shader
36 */
37 public class InstrGroupEnvMap extends InstrRequest {
38 private static Point[] dirarray = { new Point(1,0,0),
39 new Point(-1,0,0), new Point(0,1,0), new Point(0,-1,0),
40 new Point(0,0,1), new Point(0,0,-1) };
41 private InstrState state;
42 private String shaderType;
43 private String paramName;
44 private Point origin = null;
45 private Vector omit = new Vector();
46 private Vector include = new Vector();
47 private String envFileName = null;
48 private int priority;
49
50 public InstrGroupEnvMap(InstrWReader in) throws IOException, FormatException {
51 read(in);
52 state = in.state;
53 }
54
55 public void read(InstrWReader in) throws IOException,
56 FormatException {
57 readRequestName(in);
58 shaderType = in.tokenizer.getString();
59 if (!checkShaderType(shaderType))
60 throw new FormatException("Incorrect shader type",in.tokenizer);
61 paramName = in.tokenizer.getString();
62 int t = in.tokenizer.getToken();
63 include.add(new OmitRec("*", true));
64 while ((t == Token.STRING) || (t == Token.ARRAY)) {
65 if (t == Token.STRING) {
66 omit.add(new OmitRec(in.tokenizer.token.stringVal, true));
67 include.add(new OmitRec(in.tokenizer.token.stringVal, false));
68 }
69 else {
70 OmitRec.addOmitsFromVector(in.tokenizer.token.arrayVal, omit,
71 false);
72 OmitRec.addOmitsFromVector(in.tokenizer.token.arrayVal, include,
73 true);
74 }
75 t = in.tokenizer.getToken();
76 }
77 in.tokenizer.pushBack();
78 priority = in.tokenizer.lineno();
79 }
80
81 public void write(Writer out) throws IOException {
82 writeRequest(out);
83 out.write("\"" + shaderType + "\" \"" + paramName + "\" ");
84 Iterator i = omit.iterator();
85 OmitRec or;
86 while (i.hasNext()) {
87 or = (OmitRec) i.next();
88 out.write(or.toString() + ' ');
89 }
90 }
91
92
93 public void process(InstrWReader rw, RIBObjectGroup object)
94 throws FormatException, IOException {
95 if (envFileName == null) {
96 Bounds3D worldBounds = rw.rib.calculateWorldBounds(include);
97 origin = worldBounds.getCentre();
98 if (Globals.omitCurrentObject)
99 state.omitNames.addAll(omit); //make sure we omit these objects
100 InstrMapRec mapRec = new InstrMapRec(rw.rib, state, origin,
101 object, shaderType, paramName, null, priority);
102 envFileName = mapRec.mapName;
103 rw.rib.mapList.addElement(mapRec);
104 InstrAppendParam.conditionalFileNameAppend(object, shaderType, paramName,
105 mapRec.mapName);
106 }
107 else {
108 InstrMapRec mapRec = new InstrMapRec(object, shaderType, paramName,
109 envFileName + ".env", null, priority + 0.5f);
110 rw.rib.mapList.addElement(mapRec);
111 InstrAppendParam.conditionalFileNameAppend(object, shaderType, paramName,
112 mapRec.mapName);
113 }
114 }
115
116 }//class