1
0
mirror of https://github.com/moparisthebest/rswiki-book synced 2025-01-10 21:18:00 -05:00

Update MediaWiki page 'OB3'

This commit is contained in:
S 2012-12-22 12:44:19 +00:00 committed by moparisthebest
parent f8f22fd3fa
commit 041d636ef3

View File

@ -1,107 +1,106 @@
[[Category RSC]] [[Category RSC]]
Work in progress.
This page refers to .ob3, a custom format for 3D models created by Jagex. It is used by the RuneScape Classic engine since client version #74. For the earlier version of the format see [[OB2|OB2]]. This page refers to .ob3, a custom format for 3D models created by Jagex. It is used by the RuneScape Classic engine since client version #74. For the earlier version of the format see [[OB2|OB2]].
<pre>public class OB3Model { <pre>public class OB3Model {
private static final int num_seq = 0xbc614e; private static final int num_seq = 0xbc614e;
public int gouraud_shade[]; public int vertex_count;
public int vert_count; public int vertices_x[];
public int vert_x[]; public int vertices_y[];
public int vert_y[]; public int vertices_z[];
public int vert_z[]; public int face_count;
public int face_count; public int face_vertex_count[];
public int face_v_count[]; public int face_vertices[][];
public int face_v[][]; public int face_fill_back[];
public int face_back[]; public int face_fill_front[];
public int face_front[]; public int face_gouraud[];
public OB3Model(byte data[], int offset) { public OB3Model(byte data[], int offset) {
int vert_count = get_u_short(data, offset); int vertex_count = get_uint16(data, offset);
offset += 2; offset += 2;
int face_count = get_u_short(data, offset); int face_count = get_uint16(data, offset);
offset += 2; offset += 2;
vert_x = new int[vert_count]; vertices_x = new int[vertex_count];
vert_y = new int[vert_count]; vertices_y = new int[vertex_count];
vert_z = new int[vert_count]; vertices_z = new int[vertex_count];
face_v_count = new int[face_count]; face_vertex_count = new int[face_count];
faces = new int[face_count][]; face_vertices = new int[face_count][];
face_back = new int[face_count]; face_fill_back = new int[face_count];
face_front = new int[face_count]; face_fill_front = new int[face_count];
gouraud_shade = new int[face_count]; face_gouraud = new int[face_count];
for (int v = 0; v < vert_count; v++) { for (int v = 0; v < vertex_count; v++) {
vert_x[v] = get_short(data, offset); vertices_x[v] = get_int16b(data, offset);
offset += 2; offset += 2;
} }
for (int v = 0; v < vert_count; v++) { for (int v = 0; v < vertex_count; v++) {
vert_y[v] = get_short(data, offset); vertices_y[v] = get_int16b(data, offset);
offset += 2; offset += 2;
} }
for (int v = 0; v < vert_count; v++) { for (int v = 0; v < vertex_count; v++) {
vert_z[v] = get_short(data, offset); vertices_z[v] = get_int16b(data, offset);
offset += 2; offset += 2;
} }
this.vert_count = vert_count; this.vertex_count = vertex_count;
for (int f = 0; f < face_count; f++) for (int f = 0; f < face_count; f++)
face_v_count[f] = get_u_byte(data[offset++]); face_vertex_count[f] = get_ubyte(data[offset++]);
for (int f = 0; f < face_count; f++) { for (int f = 0; f < face_count; f++) {
face_back[f] = get_short(data, offset); face_fill_back[f] = get_int16b(data, offset);
offset += 2; offset += 2;
if (face_back[f] == 32767) if (face_fill_back[f] == 32767)
face_back[f] = num_seq; face_fill_back[f] = num_seq;
} }
for (int f = 0; f < face_count; f++) { for (int f = 0; f < face_count; f++) {
face_front[f] = get_short(data, offset); face_fill_front[f] = get_int16b(data, offset);
offset += 2; offset += 2;
if (face_front[f] == 32767) if (face_fill_front[f] == 32767)
face_front[f] = num_seq; face_fill_front[f] = num_seq;
} }
for (int f = 0; f < face_count; f++) { for (int f = 0; f < face_count; f++) {
int i = get_u_byte(data[offset++]); int i = get_ubyte(data[offset++]);
if (i == 0) if (i == 0)
gouraud_shade[f] = 0; face_gouraud[f] = 0;
else else
gouraud_shade[f] = num_seq; face_gouraud[f] = num_seq;
} }
for (int f = 0; f < face_count; f++) { for (int f = 0; f < face_count; f++) {
face_v[f] = new int[face_v_count[f]]; face_vertices[f] = new int[face_vertex_count[f]];
for (int fv = 0; fv < face_v_count[f]; fv++) { for (int fv = 0; fv < face_vertex_count[f]; fv++) {
if (vert_count < 256) { if (vertex_count < 256) {
face_v[f][fv] = get_u_byte(data[offset++]); face_vertices[f][fv] = get_ubyte(data[offset++]);
} else { } else {
face_v[f][fv] = get_u_short(data, offset); face_vertices[f][fv] = get_uint16(data, offset);
offset += 2; offset += 2;
} }
} }
} }
this.face_count = face_count; this.face_count = face_count;
} }
public static int get_u_byte(byte b) { private static int get_ubyte(byte b) {
return (b & 0xff); return (b & 0xff);
} }
public static int get_u_short(byte b[], int start) { private static int get_uint16(byte b[], int start) {
return ((b[start] & 0xff) << 8) + (b[start + 1] & 0xff); return (get_ubyte(b[start]) << 8) + get_ubyte(b[start + 1]);
} }
public static int get_short(byte b[], int start) { private static int get_int16b(byte b[], int start) {
int i = get_u_byte(b[start]) * 256 + get_u_byte(b[start + 1]); int i = get_ubyte(b[start]) * 256 + get_ubyte(b[start + 1]);
if (i > 32767) if (i > 32767)
i -= 0x10000; i -= 0x10000;
return i; return i;
} }
} }
</pre> </pre>
@ -111,15 +110,15 @@ A '''negative''' face_back or face_front value indicates a '''solid colour''', w
When converting to/from [http://en.wikipedia.org/wiki/Wavefront_.obj_file Wavefront OBJ] format, remember that the OB3 face vertices are one less than the OBJ face vertices. When converting to/from [http://en.wikipedia.org/wiki/Wavefront_.obj_file Wavefront OBJ] format, remember that the OB3 face vertices are one less than the OBJ face vertices.
<pre>public static int decode_colour(int i) { <pre>public static int decode_colour(int i) {
i = -(i + 1); i = -(i + 1);
int r = i >> 10 & 0x1f; int r = i >> 10 & 0x1f;
int g = i >> 5 & 0x1f; int g = i >> 5 & 0x1f;
int b = i & 0x1f; int b = i & 0x1f;
return (r << 19) + (g << 11) + (b << 3); return (r << 19) + (g << 11) + (b << 3);
} }
</pre> </pre>
<pre>public static final int encode_colour(int r, int g, int b) { <pre>public static int encode_colour(int r, int g, int b) {
return -1 - (r / 8) * 1024 - (g / 8) * 32 - b / 8; return -1 - (r / 8) * 1024 - (g / 8) * 32 - b / 8;
} }
</pre> </pre>