Skip to content

Commit 6f4849f

Browse files
author
Nikos M
committed
0.3.5
* add DisplaceMap Modifier (in progress) * edits / typos / optimizations * example / doc updates
1 parent 1eb301a commit 6f4849f

21 files changed

Lines changed: 207 additions & 113 deletions

api-reference.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ The taper modifier displaces the vertices on two axes proportionally to their po
5656

5757
Use it with vehicle models for wheels.
5858

59-
The usual problem with a 3d wheel in a vahicle is that if it is
60-
supposed to turn (steer) and roll in the same time. So, this code:
59+
The usual problem with a 3d wheel in a vahicle is that it is
60+
supposed to turn (steer) and roll in the same time.
61+
So, this code:
6162
6263
```javascript
6364
wheel.rotationY = 10; // Steer 10deg to the left
@@ -109,6 +110,21 @@ Randomly displaces each vertex in all 3 axes
109110

110111

111112

113+
###DisplaceMap (BitmapDisplacement) Modifier
114+
115+
Displaces vertices based on RGB values of bitmapData pixels.
116+
117+
BitmapDisplacement is inspired by both the AS3 built-in DisplacementMapFilter. It allows
118+
to use color values for each channels of a bitmap to modify the position of vertices in a mesh.
119+
120+
The displacement takes place along the cardinal axes, and each axis is mapped to a
121+
channel in the bitmap: X for Red, Y for Green and Z for Blue.
122+
123+
@author Bartek Drozdz
124+
125+
126+
127+
112128
###Perlin modifier
113129

114130
Displaces vertices based on a perlin/simplex noise source.

build/MOD3.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/mod3.bundle.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/mod3.three.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dependencies

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SRC =[]
5151
./src/modifiers/Wheel.js
5252
./src/modifiers/Break.js
5353
./src/modifiers/Noise.js
54+
./src/modifiers/DisplaceMap.js
5455
./src/modifiers/Perlin.js
5556

5657
# Support for Three.js
@@ -88,7 +89,7 @@ HEADER =
8889

8990
REPLACE =[{}]
9091

91-
"@@VERSION@@" = "0.3.4"
92+
"@@VERSION@@" = "0.3.5"
9293

9394
"@@DEPENDENCIES@@" = "@dependencies: Classy.js"
9495

dependencies-three

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SRC =[]
5151
./src/modifiers/Wheel.js
5252
./src/modifiers/Break.js
5353
./src/modifiers/Noise.js
54+
./src/modifiers/DisplaceMap.js
5455
./src/modifiers/Perlin.js
5556

5657
# Support for Three.js
@@ -68,7 +69,7 @@ HEADER =
6869

6970
REPLACE =[{}]
7071

71-
"@@VERSION@@" = "0.3.4"
72+
"@@VERSION@@" = "0.3.5"
7273

7374
"@@DEPENDENCIES@@" = "@dependencies: Classy.js"
7475

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ __supports:__ *Three.js* , *Pre3d* , *J3D* , *Copperlicht* , *CubicVR.js*
1212

1313
[![MOD3.js](/flipbook2.png)](http://foo123.github.com/examples/flipbook3/)
1414

15-
It is named *MOD3* to signify that it has support for [Three.js](https://github.com/mrdoob/three.js/)
15+
It is named *MOD3* to signify that it has support for [Three.js](https://github.com/mrdoob/three.js/)
1616

17-
It is a complete port (up to limitations between the 2 frameworks)
18-
Not all Modifiers of AS3DMod can be ported but most can.
19-
However the structure is ready for more modifiers to be added (even custom ones)
17+
It is a (almost) complete port. All Modifiers found in AS3DMod are scheduled to be ported.
18+
Also the API architecture is setup for more modifiers to be added (even custom ones).
2019

2120

2221
###Contents
@@ -56,6 +55,7 @@ It is named *MOD3* to signify that it has support for [Three.js](https://github.
5655
* Bloat
5756
* Break
5857
* Perlin ( MOD3 v.0.3.4 )
58+
* DisplaceMap ( MOD3 v.0.3.5, in progress )
5959

6060

6161
###TODO

src/core/Modifier.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,31 @@
66
**/
77
(function(MOD3, undef){
88

9-
var _modCount = 0;
9+
var _modCount = 0, NONE = MOD3.ModConstant.NONE;
1010

1111
var Modifier = MOD3.Modifier = MOD3.Class( Object, {
1212

1313
constructor: function( mod ) {
1414
this.id = ++_modCount;
15-
this.name = 'Generic Modifier';
15+
this.name = 'Generic';
1616
this.mod = mod || null;
17+
this.axes = NONE;
18+
this.constraint = NONE;
1719
this.enabled = true;
1820
},
1921

2022
id: null,
2123
name: null,
2224
mod : null,
25+
axes: null,
26+
constraint: null,
2327
enabled: true,
2428

2529
dispose: function( ) {
2630
this.mod = null;
2731
this.name = null;
32+
this.axes = null;
33+
this.constraint = null;
2834
return this;
2935
},
3036

@@ -37,19 +43,33 @@
3743
return this.enabled;
3844
},
3945

46+
constraintAxes: function( axes ) {
47+
this.axes = axes || NONE;
48+
return this;
49+
},
50+
51+
setConstraint: function( c ) {
52+
this.constraint = c || NONE;
53+
return this;
54+
},
55+
4056
setModifiable: function( mod ) {
4157
this.mod = mod;
4258

4359
return this;
4460
},
4561

4662
getVertices: function( ) {
47-
return this.mod.getVertices();
63+
return this.mod.getVertices( );
4864
},
4965

66+
// override
5067
apply: function( ) {
51-
// override
5268
return this;
69+
},
70+
71+
toString: function( ) {
72+
return '[Modifier '+this.name+']';
5373
}
5474
});
5575

src/core/VertexProxy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@
117117

118118
setXYZ: function( xyz ) {
119119
// override
120-
this,xyz = new A( xyz );
120+
this.xyz = new A( xyz );
121121
return this;
122122
},
123123

124124
setXYZRef: function( xyz ) {
125125
// override
126-
this,xyz = xyz;
126+
this.xyz = xyz;
127127
return this;
128128
},
129129

src/modifiers/Bend.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616

1717
(function(MOD3, undef){
1818

19-
var NONE = MOD3.ModConstant.NONE,
20-
LEFT = MOD3.ModConstant.LEFT,
21-
RIGHT = MOD3.ModConstant.RIGHT,
22-
Matrix = MOD3.Matrix,
23-
Atan = Math.atan, Atan2 = Math.atan2, Sin = Math.sin, Cos = Math.cos,
19+
var NONE = MOD3.ModConstant.NONE, LEFT = MOD3.ModConstant.LEFT, RIGHT = MOD3.ModConstant.RIGHT,
20+
Matrix = MOD3.Matrix, Atan = Math.atan, Atan2 = Math.atan2, Sin = Math.sin, Cos = Math.cos,
2421
PI = MOD3.Constants.PI, halfPI = MOD3.Constants.halfPI, doublePI = MOD3.Constants.doublePI,
2522
Point = MOD3.Point
2623
;
@@ -52,7 +49,6 @@
5249
offset: 0,
5350
angle: 0,
5451
diagAngle: 0,
55-
constraint: NONE,
5652
max: 0,
5753
min: 0,
5854
mid: 0,
@@ -68,7 +64,6 @@
6864
this.offset = null;
6965
this.angle = null;
7066
this.diagAngle = null;
71-
this.constraint = null;
7267
this.max = null;
7368
this.min = null;
7469
this.mid = null;
@@ -147,8 +142,8 @@
147142
p = (vmax - origin) * invwidth;
148143

149144
if (
150-
( (constraint == LEFT) && (p <= offset) ) ||
151-
( (constraint == RIGHT) && (p >= offset) )
145+
( (LEFT === constraint) && (p <= offset) ) ||
146+
( (RIGHT === constraint) && (p >= offset) )
152147
)
153148
{
154149
/* do nothing */

0 commit comments

Comments
 (0)