01: package com.db.geometry.updater;
02:
03: import javax.vecmath.*;
04: import javax.media.j3d.*;
05:
06: /**
07: *
08: * @author Michael Nischt - zero@monoid.net
09: */
10: public class Vertex {
11:
12: public final static int COORDINATE = GeometryArray.COORDINATES;
13: public final static int NORMAL = GeometryArray.NORMALS;
14: public final static int COLOR_3 = GeometryArray.COLOR_3;
15: public final static int COLOR_4 = GeometryArray.COLOR_4;
16: public final static int TEXTURE_COORDINATE_2 = GeometryArray.TEXTURE_COORDINATE_2;
17: public final static int TEXTURE_COORDINATE_3 = GeometryArray.TEXTURE_COORDINATE_3;
18: public final static int TEXTURE_COORDINATE_4 = GeometryArray.TEXTURE_COORDINATE_4;
19:
20: private int vertexFormat;
21: private int texCoordSetCount;
22:
23: private float[] coord;
24: private float[] normal;
25: private float[] color;
26: private float[][] texCoords;
27:
28: /** Creates a new instance of Vertex */
29: public Vertex(int vertexFormat) {
30: this (vertexFormat, 1);
31: }
32:
33: /** Creates a new instance of Vertex */
34: public Vertex(int vertexFormat, int texCoordSetCount) {
35: this .vertexFormat = vertexFormat;
36: this .texCoordSetCount = texCoordSetCount;
37: this .allocateFields();
38: }
39:
40: public int getVertexFormat() {
41: return this .vertexFormat;
42: }
43:
44: public int getTexCoordSetCount() {
45: return this .texCoordSetCount;
46: }
47:
48: public float[] getCoordinate() {
49: return this .coord;
50: }
51:
52: public float[] getNormal() {
53: return this .normal;
54: }
55:
56: public float[] getColor() {
57: return this .color;
58: }
59:
60: public float[] getTextureCoordinate(int texCoordSet) {
61: return this .texCoords[texCoordSet];
62: }
63:
64: private void allocateFields() {
65: if ((this .vertexFormat & COORDINATE) == COORDINATE) {
66: this .coord = new float[3];
67: }
68: if ((this .vertexFormat & NORMAL) == NORMAL) {
69: this .normal = new float[3];
70: }
71: if ((this .vertexFormat & COLOR_3) == COLOR_3) {
72: this .color = new float[3];
73: } else if ((this .vertexFormat & COLOR_3) == COLOR_4) {
74: this .color = new float[4];
75: }
76: this .texCoords = new float[this .texCoordSetCount][0];
77: for (int i = 0; i < this .texCoordSetCount; i++) {
78: if ((this .vertexFormat & TEXTURE_COORDINATE_2) == TEXTURE_COORDINATE_2) {
79: this .texCoords[i] = new float[2];
80: } else if ((this .vertexFormat & TEXTURE_COORDINATE_3) == TEXTURE_COORDINATE_3) {
81: this .texCoords[i] = new float[3];
82: }
83: if ((this .vertexFormat & TEXTURE_COORDINATE_4) == TEXTURE_COORDINATE_4) {
84: this .texCoords[i] = new float[4];
85: }
86: }
87:
88: }
89: }
|