FreeWRL / FreeX3D 4.3.0
VRMLObject.java
1// copyright (c) 1997,1998 stephen f. white
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation; either version 2, or (at your option)
6// any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; see the file COPYING. If not, write to
15// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16
17package sai.eai;
18
19//JAS import vrml.external.*;
20//JAS import vrml.external.field.*;
21//JAS import java.util.Hashtable;
22
23public class VRMLObject
24{
25 public int id;
26 public String URL;
27 public VRMLObject next;
28 public String[] gestures;
29 public boolean loaded = false;
30
31 protected String name;
32 protected String [] fieldNames;
33 protected VRMLObjectObserver observer;
34 protected VField [] fields;
35
36 public VRMLObject(int id, String URL, VRMLObjectObserver observer)
37 {
38 this.id = id;
39 this.URL = URL;
40 this.observer = observer;
41 fieldNames = new String[VIP.NUM_FIELDS];
42 for (short i = 0; i < VIP.NUM_FIELDS; i++) {
43 fieldNames[i] = VIP.fieldName(i);
44 }
45 fields = new VField[4];
46 fields[VIP.POSITION] = new VSFVec3f(0.0F, 0.0F, 10.0F);
47 fields[VIP.ORIENTATION] = new VSFRotation(0.0F, 0.0F, 1.0F, 0.0F);
48 fields[VIP.SCALE] = new VSFVec3f(1.0F, 1.0F, 1.0F);
49 String[] strs = { "" };
50 fields[VIP.NAME] = new VMFString(strs);
51 }
52
53 public String[] getFieldNames() {
54 return fieldNames;
55 }
56
57 public VField getField(short field) {
58 return fields[field];
59 }
60
61 public void setName(String name) {
62 this.name = name;
63 }
64
65 public void setField(short field, VField value) {
66 try {
67 fields[field] = value;
68 doSetField(field, value);
69 if (field == VIP.NAME) {
70 setName(((VMFString) value).get1Value(0));
71 }
72 } catch (ArrayIndexOutOfBoundsException e) {
73 System.err.println("unknown field " + field + " in " + this);
74 }
75 }
76
77 public String toString()
78 {
79 return (name != null ? name : "" ) + "(" + id + ")";
80 }
81
82 protected void doSetField(short field, VField value) {}
83 public void load() {}
84}