May 11, 2011

Fun with Texture

Texture support is one major improvement in Mathematica 8.0. Sure, we can have some fun with it. Here is an example. We draw some polygons first.

animalcorssing2

Then some textures are applied, we get the following image. The main trick is to use alpha channel to get this cut-out texture mapping effect. The original tree image has the alpha channel already, we can use it directly, Texture[ImageData[tree]] will do the trick, if you use Texture[tree], somehow it will not pick up the alpha channel. For the character image, it doesn’t has the alpha channel, we can set a alpha channel by the following command:

SetAlphaChannel[im,
ChanVeseBinarize[ColorNegate@im] // FillingTransform ]

animalcorssing

By the way, the character is Tom Nook: "This isn't fat, I've just lined my insides with money."

Download the notebook.

7 comments:

All things mathematical and fractal said...

These textures won't export as 3d
ray trace models...

All things mathematical and fractal said...

Try this:
Clear[x1, y1, z1, g1, g, ga, gb, t, p, d, a]
(* surface with cusps : asteroid of rotation*)
x1 = Cos[t]^3*Sin[p];
y1 = Sin[t]^3*Sin[p];
z1 = Cos[p];
w1 = {x1, z1, y1};
g = Flatten[Table[w1, {t, 0, Pi, Pi/50}, {p, -Pi, Pi, 2*Pi/50}], 1];
Length[g]
(* texture generating array*)
d = 0.01;
a[0] = {d, d, d}
a[2] = {d, d, -d}
a[3] = {d, -d, d}
a[4] = {-d, d, d}
a[5] = {-d, d, -d}
a[6] = {-d, -d, d}
a[7] = {-d, d, -d}
a[8] = {-d, -d, -d}
(* applying the texture to the surface*)

g1 = Table[g[[n]] + a[Mod[n, 8]], {n, 1, Length[g]}];
ga = ListSurfacePlot3D[g1, MaxPlotPoints -> 200, Axes -> False,
Boxed -> False, Mesh -> None,
PlotStyle -> {Black, Specularity[White, 20]}]
gb = ParametricPlot3D[w1, {t, 0, Pi}, {p, -Pi, Pi}, PlotPoints -> 50,
PlotRange -> All, PlotStyle -> {LightBlue, Specularity[White, 30]},
Axes -> False, Boxed -> False, Mesh -> False]
gw = Show[{ga, gb}, PlotRange -> All]
(*Export["HairyAsteriod.3ds", gw]
Export["HairyAsteriod.obj", gw]
Export["HairyAsteriod.stl", gw]*)

Anonymous said...

I like a lot this nice job of us.

general recreation inc

Anonymous said...

It is extremely nice to see the greatest details presented in an easy and understanding manner.life insurance rates

Unknown said...

The superb highly informative blog I’m about to share this with all my contacts.full coverage insurance rates

Unknown said...

I am really appreciating very much by seeing your interesting posts.pay day lenders

Anonymous said...

I am really appreciating very much by seeing your interesting posts. can new yorkers still get payday loans