Arduino to 3D Studio Max
After trying to find a simple to use 3D application to see how I can use the WiiChuck to control servos for a robotic arm, I settled on 3D Studio Max (3DS) because it’s the one I know best.
But how could I transfer the datas from the arduino to 3DS ?
Well, 3D Studio Max have a nice SDK and a lot of stuff, but it’s too hard for me to code a plugin using the serial port. So I stuck with Processing. Maybe I’ll try to check into MaxScript to see if it can communicate with the serial port.
A good way to control objects in 3DS is to use the track view to assign different type of controllers to the various properties of the object you want to control. For instance, if you want to have small vibrations on the tip of a bird’s wing, you can use a Noise Controller. For this setup, I used the Motion Capture controller.
3DS can use different inputs to allow motion capture : Mouse, Keyboard, Joystick or MIDI. I wanted to use some kind of “translation” in processing to emulate a HID device, but it seems to be impossible… So I used MIDI.
Here’s my setup under windows :
- Arduino using a WiiChuck adapter from todbot (thanks kurt ^^) and the WiiChuck library from Tim Hirzel
- Data sent to Processing via serial connection and translated to MIDI CC messages using the proMIDI library by Christian Riekoff
- MIDI output from processing sent to midiYoke
- midiYoke sends this data to Ableton Live
- Ableton re-sends the CC messages to midiYoke
- Using Float Motion Capture controllers on 3D Studio Max to rotate the objects according to the pitch and roll of the wiichuck…
I know it’s a little bit complicated but, I haven’t yet figured why, 3DS doesn’t want to read directly from midiYoke without the Ableton Live gate…
The drawback here is that CC messages are 8 bits only (128 values), so I still have to figure out some way to have finer resolution and handling negative values.
Anyway, I think it’s really interesting because you can use the Arduino with any kind of sensor to output your data directly into 3D Studio Max to make motion capture, for exemple, by putting tiny accelerometers on each tip of your finger, or whatever.
Here are the test codes, nothing fancy or cleaned up :
Arduino
(the WiiChuck.h library is a bit modified, to return 1 while buttons are pressed, not only on the button press)
#include "Wire.h"
#include "WiiChuck.h"
WiiChuck chuck = WiiChuck();
int zPress = 0;
int aX, aY, aZ;
// Arrays to store the values and smooth out the output
int rollA[8],pitchA[8],xA[8],yA[8],zA[8];
int i=0;
void setup() {
Serial.begin(115200);
chuck.begin();
chuck.update();
chuck.calibrateJoy();
}
void loop() {
chuck.update();
int roll, pitch, x, y, z, bZ, bC, joyX, joyY;
// Cycle through arrays and store values
rollA[i] = (int)chuck.readRoll();
pitchA[i] = (int)chuck.readPitch();
xA[i] = (int)chuck.readAccelX();
yA[i] = (int)chuck.readAccelY();
zA[i] = (int)chuck.readAccelZ();
// Smooth values
for (int j=0;j<8;j++) {
roll+=rollA[j];
pitch+=pitchA[j];
x+=xA[j];
y+=yA[j];
z+=zA[j];
}
roll=roll/8;
pitch=pitch/8;
x=x/8;
y=y/8;
z=z/8;
// Send the values via serial only if Z button is pressed
if (chuck.zPressed() == 1) {
if (zPress == 0) {
zPress = 1;
}
Serial.print(roll);
Serial.print(”,”);
Serial.print(pitch);
Serial.print(”,”);
Serial.print(x);
Serial.print(”,”);
Serial.print(y);
Serial.print(”,”);
Serial.print(z);
Serial.println();
} else {
zPress = 0;
}
// Increment position in Arrays
i++;
if(i==8) {
i=0;
}
delay(20);
}
Processing
int sensorCount = 5; // number of values to expect
import processing.serial.*;
Serial myPort; // The serial port
import promidi.*;
MidiIO midiIO;
MidiOut midiOut;
int BAUDRATE = 115200;
char DELIM = ','; // the delimeter for parsing incoming data
void setup()
{
size(100,100);
background(0);
myPort = new Serial(this, Serial.list()[0], BAUDRATE);
myPort.clear();
//get an instance of MidiIO
midiIO = MidiIO.getInstance(this);
midiIO.printDevices();
//open an midiout using the fourth device and the fifth channel
midiOut = midiIO.getMidiOut(5,4);
}
void draw()
{
// NOTHING
}
float[] sensorValues = new float[sensorCount]; // array to hold the incoming values
void serialEvent(Serial myPort) {
// read incoming data until you get a newline:
String serialString = myPort.readStringUntil(’\n’);
// if the read data is a real string, parse it:
if (serialString != null) {
// split it into substrings on the DELIM character:
String[] numbers = split(serialString, DELIM);
// convert each subastring into an int
if (numbers.length == sensorCount) {
for (int i = 0; i < numbers.length; i++) {
// make sure you’re only reading as many numbers as
// you can fit in the array:
if (i <= sensorCount) {
// trim off any whitespace from the substring:
numbers[i] = trim(numbers[i]);
sensorValues[i] = float(numbers[i]);
}
// Put the value between 0 & 127
int val = Math.min(127,Math.abs((int)sensorValues[0]));
// Sends the value as Controller 10 on the MIDI channel we opened
midiOut.sendController(
new Controller(10,val)
);
// Problem with the pitch, so -1700, really not accurate ^^
int val2 = Math.min(127,Math.abs((int)sensorValues[1]-1700));
midiOut.sendController(
new Controller(11,val2)
);
}
}
}
}
[...] read more [...]
Pingback by TerminalDigit - Wii Nunchuck Used As Motion Capture Input Via Arduino — July 9, 2008 @ 11:07 am
[...] Play-Collective] Submit These icons link to social bookmarking sites where readers can share and discover new web [...]
Pingback by Tech Ticker » Blog Archive » Wii Nunchuck got a new use — July 9, 2008 @ 12:53 pm
[...] Via Link [...]
Pingback by Wii Nunchuck and Arduino controls 3D Studio Max - Hack a Wii - Wiimote Hacks, Mod Chips, DIY Nintendo Wii projects and more — July 10, 2008 @ 6:32 am
[...] demonstrates how to use a Nintendo Nunchuck to control 3D Studio Max with the help of an Arduino microcontroller. The code is available so that you can play with it [...]
Pingback by Nintendo Nunchuck takes control 3D Studio Max with the help of an Arduino - Hacked Gadgets - DIY Tech Blog — July 10, 2008 @ 1:51 pm
[...] Więcej informacji możecie znaleźć na blogu autora. [...]
Pingback by Wiimot przydatny w pracy z 3D Studio - GRRR.pl - blog o grach, nowe gry komputerowe, konsole — July 10, 2008 @ 2:01 pm
Melka, that looks great! Keep up the good work! Exciting to see where you take this…
Jordan
BrickTable & Arduino Monome Clone
Comment by Jordan — July 12, 2008 @ 12:45 am
[...] a cool Nintendo Wii hack that controls 3D Studio Max with a Nintendo Wii Nunchuck and Arduino as controller. A good way to [...]
Pingback by Wii Hack - Wii Nunchuck and Arduino controls 3D Studio Max! | zedomax.com - Obsessively profiling DIYs, Hacks, Gadgets, Tech, Web2.0,and beyond. — July 12, 2008 @ 1:40 am
that looks cool, would it be possible to use wiimote inputs as a way of modeling in 3d studio max? like a sculpting tool?
Comment by Russ — July 19, 2008 @ 3:22 pm
nice - i was wondering since you didn’t mention it - which version of 3dSMax did you use for this experiment?
and would it be possible to use midi output directly from a Midi sequencer output as apposed to the controler using your method of conecting a controler to 3dsmax?
lastly - how would you add a read ahead for the Midi CC messages to smooth and quicken response time?
Comment by chase — August 14, 2008 @ 4:13 am
I used 3D Max 2008. Yes, you can use the output from any MIDI interface, as the motion capture controller uses the standard MIDI protocol.
I’m not sure I understand your last question though ^^
Comment by melka — August 14, 2008 @ 3:36 pm