public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(); foreach (Instance i in instances) bounds.include(i.getBounds()); return bounds; }
public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(1.5f); if (o2w != null) bounds = o2w.transform(bounds); return bounds; }
public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(); if (o2w == null) { for (int i = 0; i < patches.Length; i++) { float[] patch = patches[i]; for (int j = 0; j < patch.Length; j += 3) bounds.include(patch[j], patch[j + 1], patch[j + 2]); } } else { // transform vertices first for (int i = 0; i < patches.Length; i++) { float[] patch = patches[i]; for (int j = 0; j < patch.Length; j += 3) { float x = patch[j]; float y = patch[j + 1]; float z = patch[j + 2]; float wx = o2w.transformPX(x, y, z); float wy = o2w.transformPY(x, y, z); float wz = o2w.transformPZ(x, y, z); bounds.include(wx, wy, wz); } } } return bounds; }
public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(minX, minY, minZ); bounds.include(maxX, maxY, maxZ); if (o2w == null) return bounds; return o2w.transform(bounds); }
public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(-ro - ri, -ro - ri, -ri); bounds.include(ro + ri, ro + ri, ri); if (o2w != null) bounds = o2w.transform(bounds); return bounds; }
public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(); for (int i = 0, i3 = 0; i < n; i++, i3 += 3) bounds.include(particles[i3], particles[i3 + 1], particles[i3 + 2]); bounds.include(bounds.getMinimum().x - r, bounds.getMinimum().y - r, bounds.getMinimum().z - r); bounds.include(bounds.getMaximum().x + r, bounds.getMaximum().y + r, bounds.getMaximum().z + r); return o2w == null ? bounds : o2w.transform(bounds); }
public static Instance createTemporary(PrimitiveList primitives, Matrix4 transform, IShader shader) { Instance i = new Instance(); i.o2w = new MovingMatrix4(transform); i.w2o = i.o2w.inverse(); if (i.w2o == null) { UI.printError(UI.Module.GEOM, "Unable to compute transform inverse"); return null; } i.geometry = new Geometry(primitives); i.shaders = new IShader[] { shader }; i.updateBounds(); return i; }
public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(); if (o2w == null) { for (int i = 0; i < points.Length; i += 3) bounds.include(points[i], points[i + 1], points[i + 2]); } else { // transform vertices first for (int i = 0; i < points.Length; i += 3) { float x = points[i]; float y = points[i + 1]; float z = points[i + 2]; float wx = o2w.transformPX(x, y, z); float wy = o2w.transformPY(x, y, z); float wz = o2w.transformPZ(x, y, z); bounds.include(wx, wy, wz); } } return bounds; }
/** * Creates a rotation matrix about the Z axis. * * @param theta angle to rotate about the Z axis in radians * @return a new Matrix4 object representing the rotation */ public static Matrix4 rotateZ(float theta) { Matrix4 m = new Matrix4(); float s = (float)Math.Sin(theta); float c = (float)Math.Cos(theta); m.m22 = m.m33 = 1; m.m00 = m.m11 = c; m.m01 = -s; m.m10 = +s; return m; }
/** * Create a new ray by transforming the supplied one by the given matrix. If * the matrix is <code>null</code>, the original ray is returned. * * @param m matrix to transform the ray by */ public Ray transform(Matrix4 m) { if (m == null) return this; Ray r = new Ray(); r.ox = m.transformPX(ox, oy, oz); r.oy = m.transformPY(ox, oy, oz); r.oz = m.transformPZ(ox, oy, oz); r.dx = m.transformVX(dx, dy, dz); r.dy = m.transformVY(dx, dy, dz); r.dz = m.transformVZ(dx, dy, dz); r.tMin = tMin; r.tMax = tMax; return r; }
public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(getPrimitiveBound(0, 1)); if (o2w != null) bounds = o2w.transform(bounds); return bounds; }
/** * Create a translation matrix for the specified vector. * * @param x x component of translation * @param y y component of translation * @param z z component of translation * @return a new Matrix4 object representing the translation */ public static Matrix4 translation(float x, float y, float z) { Matrix4 m = new Matrix4(); m.m00 = m.m11 = m.m22 = m.m33 = 1; m.m03 = x; m.m13 = y; m.m23 = z; return m; }
public BoundingBox getWorldBounds(Matrix4 o2w) { if (o2w == null) return bounds; return o2w.transform(bounds); }
/** * Constructs a simple static matrix. * * @param m matrix value at all times */ public MovingMatrix4(Matrix4 m) { transforms = new Matrix4[] { m }; t0 = t1 = 0; inv = 1; }
/** * Declare a parameter with the specified name and value. This parameter * will be added to the currently active parameter list. * * @param name parameter name * @param value parameter value */ public void parameter(string name, Matrix4 value) { parameterList.addMatrices(name, ParameterList.InterpolationType.NONE, value.asRowMajor()); }
private void parseObjectBlock(SunflowAPI api) { p.checkNextToken("{"); bool noInstance = false; Matrix4[] transform = null; float transformTime0 = 0, transformTime1 = 0; string name = null; string[] shaders = null; string[] modifiers = null; if (p.peekNextToken("noinstance")) { // this indicates that the geometry is to be created, but not // instanced into the scene noInstance = true; } else { // these are the parameters to be passed to the instance if (p.peekNextToken("shaders")) { int n = p.getNextInt(); shaders = new string[n]; for (int i = 0; i < n; i++) shaders[i] = p.getNextToken(); } else { p.checkNextToken("shader"); shaders = new string[] { p.getNextToken() }; } if (p.peekNextToken("modifiers")) { int n = p.getNextInt(); modifiers = new string[n]; for (int i = 0; i < n; i++) modifiers[i] = p.getNextToken(); } else if (p.peekNextToken("modifier")) modifiers = new string[] { p.getNextToken() }; if (p.peekNextToken("transform")) { if (p.peekNextToken("steps")) { transform = new Matrix4[p.getNextInt()]; p.checkNextToken("times"); transformTime0 = p.getNextFloat(); transformTime1 = p.getNextFloat(); for (int i = 0; i < transform.Length; i++) transform[i] = parseMatrix(); } else transform = new Matrix4[] { parseMatrix() }; } } if (p.peekNextToken("accel")) api.parameter("accel", p.getNextToken()); p.checkNextToken("type"); string type = p.getNextToken(); if (p.peekNextToken("name")) name = p.getNextToken(); else name = generateUniqueName(type); if (type == "mesh") { UI.printWarning(UI.Module.API, "Deprecated object type: mesh"); UI.printInfo(UI.Module.API, "Reading mesh: {0} ...", name); int numVertices = p.getNextInt(); int numTriangles = p.getNextInt(); float[] points = new float[numVertices * 3]; float[] normals = new float[numVertices * 3]; float[] uvs = new float[numVertices * 2]; for (int i = 0; i < numVertices; i++) { p.checkNextToken("v"); points[3 * i + 0] = p.getNextFloat(); points[3 * i + 1] = p.getNextFloat(); points[3 * i + 2] = p.getNextFloat(); normals[3 * i + 0] = p.getNextFloat(); normals[3 * i + 1] = p.getNextFloat(); normals[3 * i + 2] = p.getNextFloat(); uvs[2 * i + 0] = p.getNextFloat(); uvs[2 * i + 1] = p.getNextFloat(); } int[] triangles = new int[numTriangles * 3]; for (int i = 0; i < numTriangles; i++) { p.checkNextToken("t"); triangles[i * 3 + 0] = p.getNextInt(); triangles[i * 3 + 1] = p.getNextInt(); triangles[i * 3 + 2] = p.getNextInt(); } // create geometry api.parameter("triangles", triangles); api.parameter("points", "point", "vertex", points); api.parameter("normals", "vector", "vertex", normals); api.parameter("uvs", "texcoord", "vertex", uvs); api.geometry(name, "triangle_mesh"); } else if (type == "flat-mesh") { UI.printWarning(UI.Module.API, "Deprecated object type: flat-mesh"); UI.printInfo(UI.Module.API, "Reading flat mesh: {0} ...", name); int numVertices = p.getNextInt(); int numTriangles = p.getNextInt(); float[] points = new float[numVertices * 3]; float[] uvs = new float[numVertices * 2]; for (int i = 0; i < numVertices; i++) { p.checkNextToken("v"); points[3 * i + 0] = p.getNextFloat(); points[3 * i + 1] = p.getNextFloat(); points[3 * i + 2] = p.getNextFloat(); p.getNextFloat(); p.getNextFloat(); p.getNextFloat(); uvs[2 * i + 0] = p.getNextFloat(); uvs[2 * i + 1] = p.getNextFloat(); } int[] triangles = new int[numTriangles * 3]; for (int i = 0; i < numTriangles; i++) { p.checkNextToken("t"); triangles[i * 3 + 0] = p.getNextInt(); triangles[i * 3 + 1] = p.getNextInt(); triangles[i * 3 + 2] = p.getNextInt(); } // create geometry api.parameter("triangles", triangles); api.parameter("points", "point", "vertex", points); api.parameter("uvs", "texcoord", "vertex", uvs); api.geometry(name, "triangle_mesh"); } else if (type == "sphere") { UI.printInfo(UI.Module.API, "Reading sphere ..."); api.geometry(name, "sphere"); if (transform == null && !noInstance) { // legacy method of specifying transformation for spheres p.checkNextToken("c"); float x = p.getNextFloat(); float y = p.getNextFloat(); float z = p.getNextFloat(); p.checkNextToken("r"); float radius = p.getNextFloat(); api.parameter("transform", Matrix4.translation(x, y, z).multiply(Matrix4.scale(radius))); api.parameter("shaders", shaders); if (modifiers != null) api.parameter("modifiers", modifiers); api.instance(name + ".instance", name); // disable future auto-instancing - instance has already been created noInstance = true; } } else if (type.Equals("cylinder")) { UI.printInfo(UI.Module.API, "Reading cylinder ..."); api.geometry(name, "cylinder"); } else if (type == "banchoff") { UI.printInfo(UI.Module.API, "Reading banchoff ..."); api.geometry(name, "banchoff"); } else if (type == "torus") { UI.printInfo(UI.Module.API, "Reading torus ..."); p.checkNextToken("r"); api.parameter("radiusInner", p.getNextFloat()); api.parameter("radiusOuter", p.getNextFloat()); api.geometry(name, "torus"); } else if (type.Equals("sphereflake")) { UI.printInfo(UI.Module.API, "Reading sphereflake ..."); if (p.peekNextToken("level")) api.parameter("level", p.getNextInt()); if (p.peekNextToken("axis")) api.parameter("axis", parseVector()); if (p.peekNextToken("radius")) api.parameter("radius", p.getNextFloat()); api.geometry(name, "sphereflake"); } else if (type == "plane") { UI.printInfo(UI.Module.API, "Reading plane ..."); p.checkNextToken("p"); api.parameter("center", parsePoint()); if (p.peekNextToken("n")) { api.parameter("normal", parseVector()); } else { p.checkNextToken("p"); api.parameter("point1", parsePoint()); p.checkNextToken("p"); api.parameter("point2", parsePoint()); } api.geometry(name, "plane"); } else if (type == "generic-mesh") { UI.printInfo(UI.Module.API, "Reading generic mesh: {0} ... ", name); // parse vertices p.checkNextToken("points"); int np = p.getNextInt(); api.parameter("points", "point", "vertex", parseFloatArray(np * 3)); // parse triangle indices p.checkNextToken("triangles"); int nt = p.getNextInt(); api.parameter("triangles", parseIntArray(nt * 3)); // parse normals p.checkNextToken("normals"); if (p.peekNextToken("vertex")) api.parameter("normals", "vector", "vertex", parseFloatArray(np * 3)); else if (p.peekNextToken("facevarying")) api.parameter("normals", "vector", "facevarying", parseFloatArray(nt * 9)); else p.checkNextToken("none"); // parse texture coordinates p.checkNextToken("uvs"); if (p.peekNextToken("vertex")) api.parameter("uvs", "texcoord", "vertex", parseFloatArray(np * 2)); else if (p.peekNextToken("facevarying")) api.parameter("uvs", "texcoord", "facevarying", parseFloatArray(nt * 6)); else p.checkNextToken("none"); if (p.peekNextToken("face_shaders")) api.parameter("faceshaders", parseIntArray(nt)); api.geometry(name, "triangle_mesh"); } else if (type == "hair") { UI.printInfo(UI.Module.API, "Reading hair curves: {0} ... ", name); p.checkNextToken("segments"); api.parameter("segments", p.getNextInt()); p.checkNextToken("width"); api.parameter("widths", p.getNextFloat()); p.checkNextToken("points"); api.parameter("points", "point", "vertex", parseFloatArray(p.getNextInt())); api.geometry(name, "hair"); } else if (type == "csharp-tesselatable") { UI.printInfo(UI.Module.API, "Reading procedural primitive: {0} ... ", name); string code = p.getNextCodeBlock(); try { String typename = p.peekNextToken("typename") ? p.getNextToken() : PluginRegistry.tesselatablePlugins.generateUniqueName(name); if (!PluginRegistry.tesselatablePlugins.registerPlugin(typename, code)) return; api.geometry(name, typename); } catch (Exception e) { UI.printDetailed(UI.Module.API, "Compiling: {0}", code); UI.printError(UI.Module.API, "{0}", e); noInstance = true; } } else if (type == "teapot") { UI.printInfo(UI.Module.API, "Reading teapot: {0} ... ", name); if (p.peekNextToken("subdivs")) { api.parameter("subdivs", p.getNextInt()); } if (p.peekNextToken("smooth")) { api.parameter("smooth", p.getNextbool()); } api.geometry(name, "teapot"); } else if (type == "gumbo") { UI.printInfo(UI.Module.API, "Reading gumbo:{0} ... ", name); if (p.peekNextToken("subdivs")) { api.parameter("subdivs", p.getNextInt()); } if (p.peekNextToken("smooth")) { api.parameter("smooth", p.getNextbool()); } api.geometry(name, "gumbo"); } else if (type == "julia") { UI.printInfo(UI.Module.API, "Reading julia fractal: {0} ... ", name); if (p.peekNextToken("q")) { api.parameter("cw", p.getNextFloat()); api.parameter("cx", p.getNextFloat()); api.parameter("cy", p.getNextFloat()); api.parameter("cz", p.getNextFloat()); } if (p.peekNextToken("iterations")) api.parameter("iterations", p.getNextInt()); if (p.peekNextToken("epsilon")) api.parameter("epsilon", p.getNextFloat()); api.geometry(name, "julia"); } else if (type == "particles" || type == "dlasurface") { if (type == "dlasurface") UI.printWarning(UI.Module.API, "Deprecated object type: \"dlasurface\" - please use \"particles\" instead"); float[] data; if (p.peekNextToken("filename")) { string filename = p.getNextToken(); bool littleEndian = false; if (p.peekNextToken("little_endian")) littleEndian = true; UI.printInfo(UI.Module.USER, "Loading particle file: {0}", filename); //File file = new File(filename); //FileInputStream stream = new FileInputStream(filename); //MappedByteBuffer map = stream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.Length()); //if (littleEndian) // map.order(ByteOrder.LITTLE_ENDIAN); //FloatBuffer buffer = map.asFloatBuffer(); BinaryReader reader = new BinaryReader(File.OpenRead(filename)); data = new float[reader.BaseStream.Length / 4]; if (!littleEndian) { for (int i = 0; i < data.Length; i++) { byte[] newBytes = reader.ReadBytes(4); Array.Reverse(newBytes); data[i] = BitConverter.ToSingle(newBytes, 0);//buffer.get(i); // UI.printInfo(UI.Module.USER, " particle {0}: {1}", i, data[i]); } } else { for (int i = 0; i < data.Length; i++) { data[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);//buffer.get(i); // UI.printInfo(UI.Module.USER, " particle {0}: {1}", i, data[i]); } } reader.Close(); } else { p.checkNextToken("points"); int n = p.getNextInt(); data = parseFloatArray(n * 3); // read 3n points } api.parameter("particles", "point", "vertex", data); if (p.peekNextToken("num")) api.parameter("num", p.getNextInt()); else api.parameter("num", data.Length / 3); p.checkNextToken("radius"); api.parameter("radius", p.getNextFloat()); api.geometry(name, "particles"); } else if (type == "file-mesh") { UI.printInfo(UI.Module.API, "Reading file mesh: {0} ... ", name); p.checkNextToken("filename"); api.parameter("filename", p.getNextToken()); if (p.peekNextToken("smooth_normals")) api.parameter("smooth_normals", p.getNextbool()); api.geometry(name, "file_mesh"); } else if (type == "bezier-mesh") { UI.printInfo(UI.Module.API, "Reading bezier mesh: {0} ... ", name); p.checkNextToken("n"); int nu, nv; api.parameter("nu", nu = p.getNextInt()); api.parameter("nv", nv = p.getNextInt()); if (p.peekNextToken("wrap")) { api.parameter("uwrap", p.getNextbool()); api.parameter("vwrap", p.getNextbool()); } p.checkNextToken("points"); float[] points = new float[3 * nu * nv]; for (int i = 0; i < points.Length; i++) points[i] = p.getNextFloat(); api.parameter("points", "point", "vertex", points); if (p.peekNextToken("subdivs")) api.parameter("subdivs", p.getNextInt()); if (p.peekNextToken("smooth")) api.parameter("smooth", p.getNextbool()); api.geometry(name, "bezier_mesh"); } else { UI.printWarning(UI.Module.API, "Unrecognized object type: {0}", p.getNextToken()); noInstance = true; } if (!noInstance) { // create instance api.parameter("shaders", shaders); if (modifiers != null) api.parameter("modifiers", modifiers); if (transform != null && transform.Length > 0) { if (transform.Length == 1) api.parameter("transform", transform[0]); else { api.parameter("transform.steps", transform.Length); api.parameter("transform.times", "float", "none", new float[] { transformTime0, transformTime1 }); for (int i = 0; i < transform.Length; i++) api.parameter(string.Format("transform[{0}]", i), transform[i]); } } api.instance(name + ".instance", name); } p.checkNextToken("}"); }
/** * Get the specified matrix parameter from this list. * * @param name name of the parameter * @param defaultValue value to return if not found * @return the value of the parameter specified or default value if not * found */ public Matrix4 getMatrix(string name, Matrix4 defaultValue) { Parameter p; if (list.TryGetValue(name, out p)) if (isValidParameter(name, ParameterType.MATRIX, InterpolationType.NONE, 1, p)) return p.getMatrix(); return defaultValue; }
/** * Computes this*m and return the result as a new Matrix4 * * @param m right hand side of the multiplication * @return a new Matrix4 object equal to <code>this*m</code> */ public Matrix4 multiply(Matrix4 m) { // matrix multiplication is m[r][c] = (row[r]).(col[c]) float rm00 = m00 * m.m00 + m01 * m.m10 + m02 * m.m20 + m03 * m.m30; float rm01 = m00 * m.m01 + m01 * m.m11 + m02 * m.m21 + m03 * m.m31; float rm02 = m00 * m.m02 + m01 * m.m12 + m02 * m.m22 + m03 * m.m32; float rm03 = m00 * m.m03 + m01 * m.m13 + m02 * m.m23 + m03 * m.m33; float rm10 = m10 * m.m00 + m11 * m.m10 + m12 * m.m20 + m13 * m.m30; float rm11 = m10 * m.m01 + m11 * m.m11 + m12 * m.m21 + m13 * m.m31; float rm12 = m10 * m.m02 + m11 * m.m12 + m12 * m.m22 + m13 * m.m32; float rm13 = m10 * m.m03 + m11 * m.m13 + m12 * m.m23 + m13 * m.m33; float rm20 = m20 * m.m00 + m21 * m.m10 + m22 * m.m20 + m23 * m.m30; float rm21 = m20 * m.m01 + m21 * m.m11 + m22 * m.m21 + m23 * m.m31; float rm22 = m20 * m.m02 + m21 * m.m12 + m22 * m.m22 + m23 * m.m32; float rm23 = m20 * m.m03 + m21 * m.m13 + m22 * m.m23 + m23 * m.m33; float rm30 = m30 * m.m00 + m31 * m.m10 + m32 * m.m20 + m33 * m.m30; float rm31 = m30 * m.m01 + m31 * m.m11 + m32 * m.m21 + m33 * m.m31; float rm32 = m30 * m.m02 + m31 * m.m12 + m32 * m.m22 + m33 * m.m32; float rm33 = m30 * m.m03 + m31 * m.m13 + m32 * m.m23 + m33 * m.m33; return new Matrix4(rm00, rm01, rm02, rm03, rm10, rm11, rm12, rm13, rm20, rm21, rm22, rm23, rm30, rm31, rm32, rm33); }
/** * Compute the inverse of this matrix and return it as a new object. If the * matrix is not invertible, <code>null</code> is returned. * * @return the inverse of this matrix, or <code>null</code> if not * invertible */ public Matrix4 inverse() { float A0 = m00 * m11 - m01 * m10; float A1 = m00 * m12 - m02 * m10; float A2 = m00 * m13 - m03 * m10; float A3 = m01 * m12 - m02 * m11; float A4 = m01 * m13 - m03 * m11; float A5 = m02 * m13 - m03 * m12; float B0 = m20 * m31 - m21 * m30; float B1 = m20 * m32 - m22 * m30; float B2 = m20 * m33 - m23 * m30; float B3 = m21 * m32 - m22 * m31; float B4 = m21 * m33 - m23 * m31; float B5 = m22 * m33 - m23 * m32; float det = A0 * B5 - A1 * B4 + A2 * B3 + A3 * B2 - A4 * B1 + A5 * B0; if (Math.Abs(det) < 1e-12f) return null; // matrix is not invertible float invDet = 1 / det; Matrix4 inv = new Matrix4(); inv.m00 = (+m11 * B5 - m12 * B4 + m13 * B3) * invDet; inv.m10 = (-m10 * B5 + m12 * B2 - m13 * B1) * invDet; inv.m20 = (+m10 * B4 - m11 * B2 + m13 * B0) * invDet; inv.m30 = (-m10 * B3 + m11 * B1 - m12 * B0) * invDet; inv.m01 = (-m01 * B5 + m02 * B4 - m03 * B3) * invDet; inv.m11 = (+m00 * B5 - m02 * B2 + m03 * B1) * invDet; inv.m21 = (-m00 * B4 + m01 * B2 - m03 * B0) * invDet; inv.m31 = (+m00 * B3 - m01 * B1 + m02 * B0) * invDet; inv.m02 = (+m31 * A5 - m32 * A4 + m33 * A3) * invDet; inv.m12 = (-m30 * A5 + m32 * A2 - m33 * A1) * invDet; inv.m22 = (+m30 * A4 - m31 * A2 + m33 * A0) * invDet; inv.m32 = (-m30 * A3 + m31 * A1 - m32 * A0) * invDet; inv.m03 = (-m21 * A5 + m22 * A4 - m23 * A3) * invDet; inv.m13 = (+m20 * A5 - m22 * A2 + m23 * A1) * invDet; inv.m23 = (-m20 * A4 + m21 * A2 - m23 * A0) * invDet; inv.m33 = (+m20 * A3 - m21 * A1 + m22 * A0) * invDet; return inv; }
public BoundingBox GetWorldBounds(Matrix4 o2w) { if (o2w == null) return bb; return o2w.transform(bb); }
public bool update(ParameterList pl, SunflowAPI api) { string geometryName = pl.getstring("geometry", null); if (geometry == null || geometryName != null) { if (geometryName == null) { UI.printError(UI.Module.GEOM, "geometry parameter missing - unable to create instance"); return false; } geometry = api.lookupGeometry(geometryName); if (geometry == null) { UI.printError(UI.Module.GEOM, "Geometry \"{0}\" was not declared yet - instance is invalid", geometryName); return false; } } string[] shaderNames = pl.getstringArray("shaders", null); if (shaderNames != null) { // new shader names have been provided shaders = new IShader[shaderNames.Length]; for (int i = 0; i < shaders.Length; i++) { shaders[i] = api.lookupShader(shaderNames[i]); if (shaders[i] == null) UI.printWarning(UI.Module.GEOM, "Shader \"{0}\" was not declared yet - ignoring", shaderNames[i]); } } else { // re-use existing shader array } string[] modifierNames = pl.getstringArray("modifiers", null); if (modifierNames != null) { // new modifier names have been provided modifiers = new Modifier[modifierNames.Length]; for (int i = 0; i < modifiers.Length; i++) { modifiers[i] = api.lookupModifier(modifierNames[i]); if (modifiers[i] == null) UI.printWarning(UI.Module.GEOM, "Modifier \"{0}\" was not declared yet - ignoring", modifierNames[i]); } } Matrix4 transform = pl.getMatrix("transform", o2w); if (transform != o2w) { o2w = transform; if (o2w != null) { w2o = o2w.inverse(); if (w2o == null) { UI.printError(UI.Module.GEOM, "Unable to compute transform inverse - determinant is: {0}", o2w.determinant()); return false; } } else o2w = w2o = null; } return true; }
public BoundingBox getWorldBounds(Matrix4 o2w) { return null; }
/** * Updates the matrix for the given time step. * * @param i time step to update * @param m new value for the matrix at this time step */ public void updateData(int i, Matrix4 m) { transforms[i] = m; }
/** * Creates a rotation matrix about the specified axis. The axis vector need * not be normalized. * * @param x x component of the axis vector * @param y y component of the axis vector * @param z z component of the axis vector * @param theta angle to rotate about the axis in radians * @return a new Matrix4 object representing the rotation */ public static Matrix4 rotate(float x, float y, float z, float theta) { Matrix4 m = new Matrix4(); float invLen = 1 / (float)Math.Sqrt(x * x + y * y + z * z); x *= invLen; y *= invLen; z *= invLen; float s = (float)Math.Sin(theta); float c = (float)Math.Cos(theta); float t = 1 - c; m.m00 = t * x * x + c; m.m11 = t * y * y + c; m.m22 = t * z * z + c; float txy = t * x * y; float sz = s * z; m.m01 = txy - sz; m.m10 = txy + sz; float txz = t * x * z; float sy = s * y; m.m02 = txz + sy; m.m20 = txz - sy; float tyz = t * y * z; float sx = s * x; m.m12 = tyz - sx; m.m21 = tyz + sx; m.m33 = 1; return m; }
public BoundingBox getWorldBounds(Matrix4 o2w) { if (primitives == null) { BoundingBox b = tesselatable.getWorldBounds(o2w); if (b != null) return b; if (builtTess == 0) tesselate(); if (primitives == null) return null; // failed tesselation, return infinite bounding // box } return primitives.getWorldBounds(o2w); }
/** * Create a uniform scaling matrix. * * @param s scale factor for all three axes * @return a new Matrix4 object representing the uniform scale */ public static Matrix4 scale(float s) { Matrix4 m = new Matrix4(); m.m00 = m.m11 = m.m22 = s; m.m33 = 1; return m; }
public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(); for (int i = 0, j = 0; i < points.Length; i += 3, j++) { float w = 0.5f * getWidth(j); bounds.include(points[i] - w, points[i + 1] - w, points[i + 2] - w); bounds.include(points[i] + w, points[i + 1] + w, points[i + 2] + w); } if (o2w != null) bounds = o2w.transform(bounds); return bounds; }
/** * Creates a non-uniform scaling matrix. * * @param sx scale factor in the x dimension * @param sy scale factor in the y dimension * @param sz scale factor in the z dimension * @return a new Matrix4 object representing the non-uniform scale */ public static Matrix4 scale(float sx, float sy, float sz) { Matrix4 m = new Matrix4(); m.m00 = sx; m.m11 = sy; m.m22 = sz; m.m33 = 1; return m; }
public BoundingBox getWorldBounds(Matrix4 o2w) { // world bounds can't be computed without reading file // return null so the mesh will be loaded right away return null; }
public BoundingBox getWorldBounds(Matrix4 o2w) { BoundingBox bounds = new BoundingBox(); if (o2w == null) { for (int i = 0; i < triangleMesh.uvs.data.Length; i += 2) bounds.include(triangleMesh.uvs.data[i], triangleMesh.uvs.data[i + 1], 0); } else { // transform vertices first for (int i = 0; i < triangleMesh.uvs.data.Length; i += 2) { float x = triangleMesh.uvs.data[i]; float y = triangleMesh.uvs.data[i + 1]; float wx = o2w.transformPX(x, y, 0); float wy = o2w.transformPY(x, y, 0); float wz = o2w.transformPZ(x, y, 0); bounds.include(wx, wy, wz); } } return bounds; }