Initial 1.7 commit

This commit is contained in:
Chicken-Bomes committed 2014-04-07 14:02:47 +10:00
1 parent 34154fc011
commit ca675b5f31
72 files changed
+2967 -3335

No files matched your search

+195 -206
View File
@@ -11,59 +11,96 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import codechicken.lib.lighting.LC;
import codechicken.lib.render.uv.UV;
import codechicken.lib.render.uv.UVTransformation;
import codechicken.lib.render.uv.UVTranslation;
import codechicken.lib.util.Copyable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import codechicken.lib.lighting.CCRBModel;
import codechicken.lib.lighting.LightModel;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.RedundantTransformation;
import codechicken.lib.vec.Transformation;
import codechicken.lib.vec.TransformationList;
import codechicken.lib.vec.Translation;
import codechicken.lib.vec.Vector3;
import static codechicken.lib.vec.Rotation.*;
public class CCModel
public class CCModel implements CCRenderState.IVertexSource, Copyable<CCModel>
{
private static class PositionNormalEntry
{
{
public Vector3 pos;
public LinkedList<Vector3> normals = new LinkedList<Vector3>();
public PositionNormalEntry(Vector3 position)
{
pos = position;
}
public boolean positionEqual(Vector3 v)
{
return pos.x == v.x && pos.y == v.y && pos.z == v.z;
}
public PositionNormalEntry addNormal(Vector3 normal)
{
normals.add(normal);
return this;
}
}
public final int vertexMode;
public final int vp;
public Vertex5[] verts;
public Vector3[] normals;
public int[] colours;
public ArrayList<Object> attributes = new ArrayList<Object>();
protected CCModel(int vertexMode)
{
if(vertexMode != 7 && vertexMode != 4)
throw new IllegalArgumentException("Models must be GL_QUADS or GL_TRIANGLES");
this.vertexMode = vertexMode;
vp = vertexMode == 7 ? 4 : 3;
}
public Vector3[] normals() {
return getAttributes(CCRenderState.normalAttrib);
}
@Override
public Vertex5[] getVertices() {
return verts;
}
@Override
public <T> T getAttributes(CCRenderState.VertexAttribute<T> attr) {
if(attr.attributeIndex < attributes.size())
return (T) attributes.get(attr.attributeIndex);
return null;
}
@Override
public boolean hasAttribute(CCRenderState.VertexAttribute<?> attrib) {
return attrib.attributeIndex < attributes.size() && attributes.get(attrib.attributeIndex) != null;
}
@Override
public void prepareVertex() {
}
public <T> T getOrAllocate(CCRenderState.VertexAttribute<T> attrib) {
T array = getAttributes(attrib);
if(array == null) {
while(attributes.size() <= attrib.attributeIndex)
attributes.add(null);
attributes.set(attrib.attributeIndex, array = attrib.newArray(verts.length));
}
return array;
}
/**
* Each pixel corresponds to one unit of position when generating the model
* @param i Vertex index to start generating at
@@ -87,7 +124,7 @@ public class CCModel
double y2 = y1+h;
double z2 = z1+d;
x1 /= f; x2 /= f; y1 /= f; y2 /= f; z1 /= f; z2 /= f;
//bottom face
u1 = (tx + d + w) / tw; v1 = (ty + d) / th;
u2 = (tx + d*2 + w) / tw; v2 = ty / th;
@@ -95,7 +132,7 @@ public class CCModel
verts[i++] = new Vertex5(x1, y1, z1, u1, v1);
verts[i++] = new Vertex5(x2, y1, z1, u2, v1);
verts[i++] = new Vertex5(x2, y1, z2, u2, v2);
//top face
u1 = (tx + d) / tw; v1 = (ty + d) / th;
u2 = (tx + d + w) / tw; v2 = ty / th;
@@ -103,7 +140,7 @@ public class CCModel
verts[i++] = new Vertex5(x2, y2, z1, u2, v1);
verts[i++] = new Vertex5(x1, y2, z1, u1, v1);
verts[i++] = new Vertex5(x1, y2, z2, u1, v2);
//front face
u1 = (tx + d + w) / tw; v1 = (ty + d) / th;
u2 = (tx + d) / tw; v2 = (ty + d + h) / th;
@@ -111,7 +148,7 @@ public class CCModel
verts[i++] = new Vertex5(x2, y2, z1, u1, v1);
verts[i++] = new Vertex5(x2, y1, z1, u1, v2);
verts[i++] = new Vertex5(x1, y1, z1, u2, v2);
//back face
u1 = (tx + d*2 + w*2) / tw; v1 = (ty + d) / th;
u2 = (tx + d*2 + w) / tw; v2 = (ty + d + h) / th;
@@ -119,7 +156,7 @@ public class CCModel
verts[i++] = new Vertex5(x1, y1, z2, u1, v2);
verts[i++] = new Vertex5(x2, y1, z2, u2, v2);
verts[i++] = new Vertex5(x2, y2, z2, u2, v1);
//left face
u1 = (tx + d) / tw; v1 = (ty + d) / th;
u2 = (tx) / tw; v2 = (ty + d + h) / th;
@@ -127,7 +164,7 @@ public class CCModel
verts[i++] = new Vertex5(x1, y2, z1, u1, v1);
verts[i++] = new Vertex5(x1, y1, z1, u1, v2);
verts[i++] = new Vertex5(x1, y1, z2, u2, v2);
//right face
u1 = (tx + d*2 + w) / tw; v1 = (ty + d) / th;
u2 = (tx + d + w) / tw; v2 = (ty + d + h) / th;
@@ -135,7 +172,7 @@ public class CCModel
verts[i++] = new Vertex5(x2, y1, z1, u2, v2);
verts[i++] = new Vertex5(x2, y2, z1, u2, v1);
verts[i++] = new Vertex5(x2, y2, z2, u1, v1);
return this;
}
@@ -149,7 +186,7 @@ public class CCModel
{
return generateBlock(i, bounds, 0);
}
public CCModel generateBlock(int i, Cuboid6 bounds, int mask)
{
return generateBlock(i, bounds.min.x, bounds.min.y, bounds.min.z, bounds.max.x, bounds.max.y, bounds.max.z, mask);
@@ -175,7 +212,7 @@ public class CCModel
public CCModel generateBlock(int i, double x1, double y1, double z1, double x2, double y2, double z2, int mask)
{
double u1, v1, u2, v2;
if((mask&1) == 0) {//bottom face
u1 = x1; v1 = z1;
u2 = x2; v2 = z2;
@@ -184,7 +221,7 @@ public class CCModel
verts[i++] = new Vertex5(x2, y1, z1, u2, v1);
verts[i++] = new Vertex5(x2, y1, z2, u2, v2);
}
if((mask&2) == 0) {//top face
u1 = x1+2; v1 = z1;
u2 = x2+2; v2 = z2;
@@ -193,7 +230,7 @@ public class CCModel
verts[i++] = new Vertex5(x1, y2, z1, u1, v1);
verts[i++] = new Vertex5(x1, y2, z2, u1, v2);
}
if((mask&4) == 0) {//east face
u1 = 1-x1+4; v1 = 1-y2;
u2 = 1-x2+4; v2 = 1-y1;
@@ -202,7 +239,7 @@ public class CCModel
verts[i++] = new Vertex5(x2, y2, z1, u2, v1);
verts[i++] = new Vertex5(x2, y1, z1, u2, v2);
}
if((mask&8) == 0) {//west face
u1 = x1+6; v1 = 1-y2;
u2 = x2+6; v2 = 1-y1;
@@ -211,7 +248,7 @@ public class CCModel
verts[i++] = new Vertex5(x1, y2, z2, u1, v1);
verts[i++] = new Vertex5(x1, y1, z2, u1, v2);
}
if((mask&0x10) == 0) {//north face
u1 = z1+8; v1 = 1-y2;
u2 = z2+8; v2 = 1-y1;
@@ -220,7 +257,7 @@ public class CCModel
verts[i++] = new Vertex5(x1, y2, z1, u1, v1);
verts[i++] = new Vertex5(x1, y1, z1, u1, v2);
}
if((mask&0x20) == 0) {//south face
u1 = 1-z1+10; v1 = 1-y2;
u2 = 1-z2+10; v2 = 1-y1;
@@ -229,10 +266,10 @@ public class CCModel
verts[i++] = new Vertex5(x2, y2, z2, u2, v1);
verts[i++] = new Vertex5(x2, y1, z2, u2, v2);
}
return this;
}
public CCModel computeNormals()
{
return computeNormals(0, verts.length);
@@ -249,10 +286,8 @@ public class CCModel
{
if(length%vp != 0 || start%vp != 0)
throw new IllegalArgumentException("Cannot generate normals across polygons");
if(normals == null)
normals = new Vector3[verts.length];
Vector3[] normals = getOrAllocate(CCRenderState.normalAttrib);
for(int k = 0; k < length; k+=vp)
{
int i = k + start;
@@ -262,44 +297,47 @@ public class CCModel
for(int d = 1; d < vp; d++)
normals[i+d] = normals[i].copy();
}
return this;
}
/**
* Computes lighting using the normals and the colour 0xFFFFFF.
* Per vert colouring will be added when needed.
* Make sure you have generated your normals on the model first.
* If you rotate your model after this, the lighting will no longer be valid
* @param light The light model to calculate
* @return The model
*/
public CCModel computeLighting(LightModel light)
{
if(colours == null)
setColour(-1);
for(int k = 0; k < verts.length; k++)
colours[k] = light.apply(colours[k], normals[k]);
return this;
}
public CCModel setColour(int c)
{
if(colours == null)
colours = new int[verts.length];
for(int k = 0; k < verts.length; k++)
colours[k] = c;
return this;
}
/**
* Warning, only use this if you NEED to be identical to MC's light model, it's hideous.
* Computes lighting using the normals add a light model
* If the model is rotated, the lighting will no longer be valid
* @return The model
*/
public CCRBModel withMCLighting()
public CCModel computeLighting(LightModel light)
{
return new CCRBModel(this);
Vector3[] normals = normals();
int[] colours = getAttributes(CCRenderState.colourAttrib);
if(colours == null) {
setColour(-1);
colours = getAttributes(CCRenderState.colourAttrib);
}
for(int k = 0; k < verts.length; k++)
colours[k] = light.apply(colours[k], normals[k]);
return this;
}
public CCModel setColour(int c)
{
int[] colours = getOrAllocate(CCRenderState.colourAttrib);
Arrays.fill(colours, c);
return this;
}
/**
* Computes the minecraft lighting coordinates for use with a LightMatrix
* @return The model
*/
public CCModel computeLightCoords() {
LC[] lcs = getOrAllocate(CCRenderState.lightCoordAttrib);
Vector3[] normals = normals();
for(int i = 0; i < verts.length; i++)
lcs[i] = new LC().compute(verts[i].vec, normals[i]);
return this;
}
/**
* Averages all normals at the same position to produce a smooth lighting effect.
* @return The model
@@ -307,6 +345,7 @@ public class CCModel
public CCModel smoothNormals()
{
ArrayList<PositionNormalEntry> map = new ArrayList<PositionNormalEntry>();
Vector3[] normals = normals();
nextvert: for(int k = 0; k < verts.length; k++)
{
Vector3 vec = verts[k].vec;
@@ -316,24 +355,24 @@ public class CCModel
e.addNormal(normals[k]);
continue nextvert;
}
map.add(new PositionNormalEntry(vec).addNormal(normals[k]));
}
for(PositionNormalEntry e : map)
{
if(e.normals.size() <= 1)
continue;
Vector3 new_n = new Vector3();
for(Vector3 n : e.normals)
new_n.add(n);
new_n.normalize();
for(Vector3 n : e.normals)
n.set(new_n);
}
return this;
}
@@ -341,134 +380,93 @@ public class CCModel
{
for(int k = 0; k < verts.length; k++)
verts[k].apply(t);
Vector3[] normals = normals();
if(normals != null)
for(int k = 0; k < normals.length; k++)
t.applyN(normals[k]);
return this;
}
public CCModel apply(IUVTransformation uvt)
public CCModel apply(UVTransformation uvt)
{
for(int k = 0; k < verts.length; k++)
verts[k].apply(uvt);
return this;
}
public CCModel expand(int extraVerts)
{
int newLen = verts.length+extraVerts;
verts = Arrays.copyOf(verts, newLen);
if(normals != null)
normals = Arrays.copyOf(normals, newLen);
if(colours != null)
colours = Arrays.copyOf(colours, newLen);
for(int i = 0; i < attributes.size(); i++)
if(attributes.get(i) != null)
attributes.set(i, CCRenderState.copyOf((CCRenderState.VertexAttribute)CCRenderState.getAttribute(i), attributes.get(i), newLen));
return this;
}
public void render()
{
render(0, verts.length, null, null, null);
}
public void render(double x, double y, double z, double u, double v)
{
render(new Translation(new Vector3(x, y, z)), new UVTranslation(u, v));
render(new Vector3(x, y, z).translation(), new UVTranslation(u, v));
}
public void render(double x, double y, double z, IUVTransformation u)
public void render(double x, double y, double z, UVTransformation u)
{
render(new Translation(new Vector3(x, y, z)), u);
render(new Vector3(x, y, z).translation(), u);
}
public void render(Transformation t, double u, double v)
{
render(t, new UVTranslation(u, v));
}
public void render(Transformation t, IUVTransformation u)
public void render(CCRenderState.IVertexOperation... ops)
{
render(t, u, ColourModifier.instance);
}
public void render(Transformation t, IUVTransformation u, IVertexModifier m)
{
render(0, verts.length, t, u, m);
render(0, verts.length, ops);
}
/**
* Renders vertices start through start+length-1 of the model
* @param start The first vertex to render
* @param length The number of vertices to render
* @param t The transformation to apply to the mat
* @param u The u texture offset
* @param v The v texture offset
* @param start The first vertex index to render
* @param end The vertex index to render until
* @param ops Operations to apply
*/
public void render(int start, int length, Transformation t, IUVTransformation u, IVertexModifier m)
public void render(int start, int end, CCRenderState.IVertexOperation... ops)
{
boolean drawNormal = CCRenderState.useNormals() && normals != null;
boolean computeNormal = drawNormal || m != null && m.needsNormals();
Vector3 normal = new Vector3();
Vertex5 vert;
Vector3 vec = new Vector3();
UV uv = new UV();
Tessellator tess = Tessellator.instance;
for(int k = 0; k < length; k++)
{
int i = start+k;
if(computeNormal)
{
if(t != null)
t.applyN(normal.set(normals[i]));
else
normal = normals[i];
if(drawNormal)
tess.setNormal((float)normal.x, (float)normal.y, (float)normal.z);
}
vert = verts[i];
if(t != null)
t.apply(vec.set(vert.vec));
else
vec = vert.vec;
if(u != null)
u.transform(uv.set(vert.uv));
else
uv = vert.uv;
if(m != null)
m.applyModifiers(this, tess, vec, uv, normal, i);
tess.addVertexWithUV(vec.x, vec.y, vec.z, uv.u, uv.v);
}
CCRenderState.setPipeline(this, start, end, ops);
CCRenderState.render();
}
public static CCModel quadModel(int numVerts)
{
return newModel(7, numVerts);
}
public static CCModel triModel(int numVerts)
{
return newModel(4, numVerts);
}
public static CCModel newModel(int vertexMode, int numVerts)
{
CCModel model = newModel(vertexMode);
model.verts = new Vertex5[numVerts];
return model;
}
public static CCModel newModel(int vertexMode)
{
return new CCModel(vertexMode);
}
public static double[] parseDoubles(String s, String token)
{
String[] as = s.split(token);
@@ -482,7 +480,7 @@ public class CCModel
{
if(!b) throw new IllegalArgumentException(err);
}
public static void assertMatch(Matcher m, String s)
{
m.reset(s);
@@ -497,7 +495,7 @@ public class CCModel
public static final Matcher uvwMatcher = uvwPattern.matcher("");
public static final Matcher normalMatcher = normalPattern.matcher("");
public static final Matcher polyMatcher = polyPattern.matcher("");
/**
* Parses vertices, texture coords, normals and polygons from a WaveFront Obj file
* @param input An input stream to a obj file
@@ -511,14 +509,14 @@ public class CCModel
if(coordSystem == null)
coordSystem = new RedundantTransformation();
int vp = vertexMode == 7 ? 4 : 3;
HashMap<String, CCModel> modelMap = new HashMap<String, CCModel>();
ArrayList<Vector3> verts = new ArrayList<Vector3>();
ArrayList<Vector3> uvs = new ArrayList<Vector3>();
ArrayList<Vector3> normals = new ArrayList<Vector3>();
ArrayList<int[]> polys = new ArrayList<int[]>();
String modelName = "unnamed";
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line;
@@ -527,7 +525,7 @@ public class CCModel
line = line.replaceAll("\\s+", " ").trim();
if(line.startsWith("#") || line.length() == 0)
continue;
if(line.startsWith("v "))
{
assertMatch(vertMatcher, line);
@@ -584,13 +582,13 @@ public class CCModel
modelName = line.substring(2);
}
}
if(!polys.isEmpty())
modelMap.put(modelName, createModel(verts, uvs, normals, vertexMode, polys));
return modelMap;
}
public static void triangulate(List<int[]> polys, int[][] polyVerts)
{
for(int i = 2; i < polyVerts.length; i++)
@@ -600,7 +598,7 @@ public class CCModel
polys.add(polyVerts[i-1]);
}
}
public static void quadulate(List<int[]> polys, int[][] polyVerts)
{
if(polyVerts.length == 4)
@@ -624,7 +622,7 @@ public class CCModel
/**
* Parses vertices, texture coords, normals and polygons from a WaveFront Obj file
* @param s The name of the obj resource
* @param res The resource for the obj file
* @return A map of group names to models
*/
public static Map<String, CCModel> parseObjModels(ResourceLocation res)
@@ -642,7 +640,7 @@ public class CCModel
try
{
return parseObjModels(
Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream(),
Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream(),
4, coordSystem);
}
catch(IOException e)
@@ -650,10 +648,10 @@ public class CCModel
throw new RuntimeException("failed to load model: "+res, e);
}
}
/**
* Parses vertices, texture coords, normals and polygons from a WaveFront Obj file
* @param s The name of the obj resource
* @param res The resource for the obj file
* @param vertexMode The vertex mode to create the model for (GL_TRIANGLES or GL_QUADS)
* @param coordSystem The cooridnate system transformation to apply
* @return A map of group names to models
@@ -663,7 +661,7 @@ public class CCModel
try
{
return parseObjModels(
Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream(),
Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream(),
vertexMode, coordSystem);
}
catch(Exception e)
@@ -677,12 +675,12 @@ public class CCModel
int vp = vertexMode == 7 ? 4 : 3;
if(polys.size() < vp || polys.size()%vp != 0)
throw new IllegalArgumentException("Invalid number of vertices for model: "+polys.size());
boolean hasNormals = polys.get(0)[2] > 0;
CCModel model = CCModel.newModel(vertexMode, polys.size());
if(hasNormals)
model.normals = new Vector3[polys.size()];
model.getOrAllocate(CCRenderState.normalAttrib);
for(int i = 0; i < polys.size(); i++)
{
int[] ai = polys.get(i);
@@ -690,12 +688,12 @@ public class CCModel
Vector3 uv = ai[1] <= 0 ? new Vector3() : uvs.get(ai[1]-1).copy();
if(ai[2] > 0 != hasNormals)
throw new IllegalArgumentException("Normals are an all or nothing deal here.");
model.verts[i] = new Vertex5(vert, uv.x, uv.y);
if(hasNormals)
model.normals[i] = normals.get(ai[2]-1).copy();
model.normals()[i] = normals.get(ai[2]-1).copy();
}
return model;
}
@@ -726,7 +724,7 @@ public class CCModel
int vStart = verts.size();
int uStart = uvs.size();
int nStart = normals.size();
boolean hasNormals = m.normals != null;
boolean hasNormals = m.normals() != null;
polys.clear();
for(int i = 0; i < m.verts.length; i++) {
@@ -734,7 +732,7 @@ public class CCModel
ia[0] = addIndex(verts, m.verts[i].vec);
ia[1] = addIndex(uvs, m.verts[i].uv);
if(hasNormals)
ia[2] = addIndex(normals, m.normals[i]);
ia[2] = addIndex(normals, m.normals()[i]);
polys.add(ia);
}
@@ -788,7 +786,7 @@ public class CCModel
{
uv.add(verts[k+i].uv);
}
uv.mul(1D/vp);
uv.multiply(1D/vp);
for(int i = 0; i < vp; i++)
{
Vertex5 vert = verts[k+i];
@@ -798,7 +796,7 @@ public class CCModel
}
return this;
}
/**
* @param side1 The side of this model
* @param side2 The side of the new model
@@ -811,30 +809,18 @@ public class CCModel
copy(this, 0, model, 0, model.verts.length);
return model.apply(new TransformationList(sideRotations[side1].inverse(), sideRotations[side2]).at(point));
}
/**
* Copies length vertices and normals
*/
public static void copy(CCModel src, int srcpos, CCModel dest, int destpos, int length)
public static void copy(CCModel src, int srcpos, CCModel dst, int destpos, int length)
{
for(int k = 0; k < length; k++)
dest.verts[destpos+k] = src.verts[srcpos+k].copy();
if(src.normals != null)
{
if(dest.normals == null)
dest.normals = new Vector3[dest.verts.length];
dst.verts[destpos+k] = src.verts[srcpos+k].copy();
for(int k = 0; k < length; k++)
dest.normals[destpos+k] = src.normals[srcpos+k].copy();
}
if(src.colours != null)
{
if(dest.colours == null)
dest.colours = new int[dest.verts.length];
System.arraycopy(src.colours, srcpos, dest.colours, destpos, length);
}
for(int i = 0; i < src.attributes.size(); i++)
if(src.attributes.get(i) != null)
CCRenderState.arrayCopy(src.attributes.get(i), srcpos, dst.getOrAllocate(CCRenderState.getAttribute(i)), destpos, length);
}
/**
@@ -849,11 +835,11 @@ public class CCModel
{
if(s == side)
continue;
models[s] = models[side].sidedCopy(side, s, point);
}
}
/**
* Generate models rotated to the other 3 horizontal of the block
* @param models An array of 4 models
@@ -870,12 +856,12 @@ public class CCModel
models[s] = models[side].sidedCopy(side, s, point);
}
}
public CCModel backfacedCopy()
{
return generateBackface(this, 0, copy(), 0, verts.length);
}
/**
* Generates copies of faces with clockwise vertices
* @return The model
@@ -885,7 +871,7 @@ public class CCModel
int vp = src.vp;
if(srcpos%vp != 0 || destpos%vp != 0 || length%vp != 0)
throw new IllegalArgumentException("Vertices do not align with polygons");
int[][] o = new int[][]{{0, 0}, {1, vp-1}, {2, vp-2}, {3, vp-3}};
for(int i = 0; i < length; i++)
{
@@ -894,10 +880,12 @@ public class CCModel
int di = destpos+b+o[d][1];
int si = srcpos+b+o[d][0];
dst.verts[di] = src.verts[si].copy();
if(src.normals != null && src.normals[si] != null)
dst.normals[di] = src.normals[si].copy().negate();
if(src.colours != null)
dst.colours[di] = src.colours[si];
for(int a = 0; a < src.attributes.size(); a++)
if(src.attributes.get(a) != null)
CCRenderState.arrayCopy(src.attributes.get(a), si, dst.getOrAllocate(CCRenderState.getAttribute(a)), di, 1);
if(dst.normals() != null && dst.normals()[di] != null)
dst.normals()[di].negate();
}
return dst;
}
@@ -911,15 +899,15 @@ public class CCModel
if(verts.length%(6*vp) != 0)
throw new IllegalArgumentException("Invalid number of vertices for sided part generation");
int length = verts.length/6;
for(int s = 0; s < 6; s++)
{
if(s == side)
continue;
generateSidedPart(side, s, point, length*side, length*s, length);
}
return this;
}
@@ -932,7 +920,7 @@ public class CCModel
if(verts.length%(4*vp) != 0)
throw new IllegalArgumentException("Invalid number of vertices for sided part generation");
int length = verts.length/4;
for(int s = 2; s < 6; s++)
{
if(s == side)
@@ -940,7 +928,7 @@ public class CCModel
generateSidedPart(side, s, point, length*(side-2), length*(s-2), length);
}
return this;
}
@@ -962,13 +950,14 @@ public class CCModel
verts[destpos+k] = verts[srcpos+k].copy();
verts[destpos+k].vec.apply(t);
}
Vector3[] normals = normals();
if(normals != null)
for(int k = 0; k < length; k++) {
normals[destpos+k] = normals[srcpos+k].copy();
t.applyN(normals[destpos+k]);
}
return this;
}
@@ -976,7 +965,7 @@ public class CCModel
{
if(models.isEmpty())
return null;
int numVerts = 0;
int vertexMode = -1;
for(CCModel model : models)
@@ -985,10 +974,10 @@ public class CCModel
vertexMode = model.vertexMode;
if(vertexMode != model.vertexMode)
throw new IllegalArgumentException("Cannot combine models with different vertex modes");
numVerts+=model.verts.length;
}
CCModel c_model = newModel(vertexMode, numVerts);
int i = 0;
for(CCModel model : models)
@@ -996,7 +985,7 @@ public class CCModel
copy(model, 0, c_model, i, model.verts.length);
i+=model.verts.length;
}
return c_model;
}
@@ -1013,7 +1002,7 @@ public class CCModel
copy(this, 0, model, 0, verts.length);
return model;
}
/**
* @return The average of all vertices, for bones.
*/
@@ -1025,13 +1014,13 @@ public class CCModel
v.multiply(1/(double)verts.length);
return v;
}
public CCModel zOffset(Cuboid6 offsets)
{
for(int k = 0; k < verts.length; k++)
{
Vertex5 vert = verts[k];
Vector3 normal = normals[k];
Vector3 normal = normals()[k];
switch(findSide(normal))
{
case 0:
@@ -1056,7 +1045,7 @@ public class CCModel
}
return this;
}
public static int findSide(Vector3 normal)
{
if(normal.y <=-0.99) return 0;