Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinearExtrude subdivision default & minimum 1 #87

Merged
merged 2 commits into from
Nov 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions away3d/extrusions/LinearExtrude.hx
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
package away3d.extrusions;

import openfl.Vector;
import Reflect;
import Reflect;
import Reflect;
import Reflect;
import Reflect;
import Reflect;
import Reflect;
import away3d.extrusions.data.RenderSide;
import away3d.extrusions.data.Line;
import away3d.extrusions.data.FourPoints;
import away3d.extrusions.data.SubGeometryList;
import openfl.errors.Error;
import away3d.bounds.BoundingVolumeBase;
import away3d.core.base.data.UV;
import away3d.core.base.data.Vertex;
import away3d.core.base.Geometry;
import away3d.core.base.SubGeometry;
import away3d.core.base.SubMesh;
import away3d.core.base.data.UV;
import away3d.core.base.data.Vertex;
import away3d.entities.Mesh;
import away3d.extrusions.data.FourPoints;
import away3d.extrusions.data.Line;
import away3d.extrusions.data.RenderSide;
import away3d.extrusions.data.SubGeometryList;
import away3d.materials.MaterialBase;
import away3d.materials.utils.MultipleMaterials;
import away3d.tools.helpers.MeshHelper;
import openfl.errors.Error;
import openfl.geom.Point;
import openfl.geom.Vector3D;
import away3d.core.base.SubGeometry;
import away3d.materials.MaterialBase;
import openfl.geom.Point;
import openfl.Vector;
import Reflect;

class LinearExtrude extends Mesh {
public var axis(get, set):String;
Expand Down Expand Up @@ -97,14 +88,13 @@ class LinearExtrude extends Mesh {
* @param ignoreSides [optional] String. To prevent the generation of sides if thickness is set higher than 0. To avoid the bottom ignoreSides = "bottom", avoiding both top and bottom: ignoreSides = "bottom, top". Strings options: bottom, top, left, right, front and back. Default is "".
* @param flip [optional] Boolean. If the faces must be reversed depending on Vector3D's orientation. Default is false.
*/
public function new(material:MaterialBase = null, vectors:Vector<Vector3D> = null, axis:String = LinearExtrude.Y_AXIS, offset:Float = 10, subdivision:Int = 3, coverAll:Bool = false, thickness:Float = 0, thicknessSubdivision:Int = 3, materials:MultipleMaterials = null, centerMesh:Bool = false, closePath:Bool = false, ignoreSides:String = "", flip:Bool = false) {
public function new(material:MaterialBase = null, vectors:Vector<Vector3D> = null, axis:String = LinearExtrude.Y_AXIS, offset:Float = 10, subdivision:Int = 1, coverAll:Bool = false, thickness:Float = 0, thicknessSubdivision:Int = 3, materials:MultipleMaterials = null, centerMesh:Bool = false, closePath:Bool = false, ignoreSides:String = "", flip:Bool = false) {
LIMIT = 196605;
EPS = .0001;
_geomDirty = true;
var geom:Geometry = new Geometry();
_subGeometry = new SubGeometry();
if (material == null && materials != null && materials.front != null) material = materials.front;
super(geom, material);
_aVectors = vectors;
_axis = axis;
_offset = offset;
Expand All @@ -118,10 +108,11 @@ class LinearExtrude extends Mesh {
_closePath = closePath;
if (materials != null) this.materials = materials;
if (_closePath && ignoreSides != "") this.ignoreSides = ignoreSides;
super(geom, material);
}

private function buildExtrude():Void {
if (_aVectors.length != 0 || _aVectors.length < 2) throw new Error("LinearExtrusion error: at least 2 vector3D required!");
if (_aVectors!=null && _aVectors.length > 0 && _aVectors.length < 2) throw new Error("LinearExtrusion error: at least 2 vector3D required!");
if (_closePath) _aVectors.push(new Vector3D(_aVectors[0].x, _aVectors[0].y, _aVectors[0].z));
_maxIndProfile = _aVectors.length * 9;
_MaterialsSubGeometries = null;
Expand Down Expand Up @@ -185,14 +176,14 @@ class LinearExtrude extends Mesh {
}

/**
* Defines the subdivisions created in the mesh for the total number of revolutions. Defaults to 2, minimum 2.
* Defines the subdivisions created in the mesh for the total number of revolutions. Defaults to 1, minimum 1.
*/
private function get_subdivision():Int {
return _subdivision;
}

private function set_subdivision(val:Int):Int {
val = ((val < 3)) ? 3 : val;
val = ((val < 1)) ? 1 : val;
if (_subdivision == val) return val;
_subdivision = val;
invalidateGeometry();
Expand Down Expand Up @@ -583,7 +574,7 @@ class LinearExtrude extends Mesh {
_varr.push(new Vertex(vector.x, vector.y, vector.z));
j = 0;
while (j < _subdivision) {
Reflect.setField(vector, _axis, Reflect.field(vector, _axis) + increase);
Reflect.setField(vector, "_"+_axis, Reflect.field(vector, _axis) + increase);
_varr.push(new Vertex(vector.x, vector.y, vector.z));
j++;
}
Expand Down