?? lathe.wrl
字號:
NavigationInfo {
type ["EXAMINE" "ANY"]
}
Viewpoint {
position 0 12 16
orientation -1 0 0 0.7854
description "Front"
}
DirectionalLight {
intensity 0.7
direction 1 -1 -1
}
# The Tool, moveable by the plane sensor
Transform {
children [
DEF TOOLSENSOR PlaneSensor {
maxPosition 100 100
minPosition -100 -100
autoOffset FALSE
}
DEF TOOLTRANS Transform {
children [
Transform {
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.2 0.2 1
specularColor 1 1 1
shininess 0.8
}
}
#Cylinder for tool
geometry Cylinder {
radius 0.2
height 4
}
}
translation 0 -2.4 0
}
Transform {
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.5 0.5 1
specularColor 0.8 0.8 1
shininess 0.9
}
}
# for tool
geometry Cone {
bottomRadius 0.2
height 0.4
}
}
translation 0 -0.2 0
}
DEF SPARKTIMER TimeSensor {
cycleInterval 0.3
}
DEF SPARKSWITCH Switch {
whichChoice -1
choice Shape {
appearance Appearance {
material Material {
emissiveColor 1 1 0.5
}
}
geometry DEF SPARKS IndexedLineSet {
coord DEF SPARKCOORD Coordinate {
point []
}
coordIndex []
color DEF SPARKCOLOR Color {
color []
}
}
}
}
Sound {
minFront 10
maxFront 100
minBack 10
maxBack 100
source DEF TOOLSOUND AudioClip {
url "tool.wav"
loop TRUE
startTime 0
stopTime 1
}
}
]
}
]
rotation 1 0 0 -1.57
}
# The rotating stock, constructed by the script
part used for manufacturing
DEF ROTTRANS Transform {
children [
DEF ROTTOUCH TouchSensor {
}
Shape {
appearance Appearance {
material Material {
diffuseColor 0.5 0.5 1
shininess 0.9
specularColor 0.5 0.5 1
}
}
geometry DEF SHAPE Extrusion {
beginCap FALSE
endCap FALSE
convex FALSE
ccw FALSE
creaseAngle 1
crossSection [-1 -7, 1 -7, 1 7, -1 7]
spine [0 0 1, 0 -0.65 0.77, 0 -0.99 0.17, 0 -0.87 -0.5,
0 -0.35 -0.94, 0 0.34 -0.94, 0 0.87 -0.5,
0 0.98 0.17, 0 0.64 0.77, 0 0 1]
}
}
Sound {
minFront 10
maxFront 100
minBack 10
maxBack 100
source DEF LATHESOUND AudioClip {
#url "lathe.wav"
loop TRUE
}
}
]
}
DEF ROTTIME TimeSensor {
cycleInterval 0.5 #time control
loop TRUE
}
DEF ROTINT OrientationInterpolator {
key [0, 0.25, 0.5, 0.75, 1]
keyValue [-1 0 0 0, -1 0 0 1.57, -1 0 0 3.14, -1 0 0 4.71, -1 0 0 0]
}
# The floating panel (reset button)
#This is the sensor to measure the viewers position and
#viewing direction
DEF PANELPROX ProximitySensor {
size 100 100 100
}
#This transform follows the viewer, so it appears to be
#static
DEF PANELTRANS Transform {
children [
########### RESET ##############
Transform {
children [
DEF RESETBUTTON TouchSensor {
}
DEF BUTTON Shape {
appearance Appearance {
material Material {
diffuseColor 0 0 .8
emissiveColor 0 0 .8
}
}
geometry Box {
size 2 0.8 0.2
}
}
Transform {
children Shape {
appearance Appearance {
material Material {
diffuseColor 1 0.8 0
emissiveColor 1 0.8 0
}
}
geometry Text {
string "RESET"
maxExtent 1.9
fontStyle DEF BUTTONFONT FontStyle {
family "SANS"
size 0.5
justify ["MIDDLE", "MIDDLE"]
}
}
}
translation 0 0 0.11
}
]
translation -3 -3 -10
}
]
}
# The Script, to construct the piece, and handle interaction
DEF SCRIPT Script {
field SFInt32 linSteps 42
field SFInt32 rotSteps 9
field SFFloat radius 1
field SFFloat width 10
field SFInt32 sparks 20
eventOut MFVec2f crossSection
eventOut MFVec3f spine
eventOut MFVec3f sparkCoord
eventOut MFInt32 sparkIndex
eventOut MFColor sparkColor
eventOut SFInt32 sparkChoice
eventOut SFTime sparkTimerStart
eventOut SFTime toolSoundStart
eventOut SFTime toolSoundStop
eventIn SFBool sparkActive
eventIn SFFloat sparkFraction
eventIn SFVec3f set_toolPosition
eventIn SFBool set_toolActive
eventOut SFVec3f toolPosition_changed
eventOut SFVec3f toolOffset_changed
field SFVec3f toolPosition 0 -3 0
eventIn SFTime rotTouched
eventOut SFBool doRotate
eventOut SFFloat rotFraction
eventOut SFTime startSound
eventOut SFTime stopSound
eventIn SFTime reset
field SFVec2f last 0 3
field SFTime cutTime 0
url "vrmlscript:
function randomSparks() {
j = 0;
for (i = 1; i < sparks; i++) {
sparkCoord[i] = new SFVec3f(
Math.random() - 0.5,
Math.random() - 0.5,
1 + Math.random()
);
}
}
function initialize() {
spine = new MFVec3f();
crossSection = new MFVec2f();
//Create rotational Spine
step = 2 * Math.PI / rotSteps;
p = Math.PI / 2;
for (i = 0; i < rotSteps; i++) {
spine[i] = new SFVec3f(0, Math.cos(p), Math.sin(p));
p += step;
}
spine[rotSteps] = spine[0];
//Create CrossSection
crossSection[0] = new SFVec2f(-0.999, -0.5 * width);
for (i = 0; i < linSteps + 1; i++) {
crossSection[i+1] = new SFVec2f( radius,
(i * width / linSteps) - (0.5 * width));
}
crossSection[linSteps+2] = new SFVec2f(-0.999, 0.5 * width);
//Create Sparks
sparkCoord = new MFVec3f();
sparkIndex = new MFInt32();
sparkColor = new MFColor();
sparkCoord[0] = new SFVec3f(0, 0, 0);
sparkColor[0] = new SFColor(1, 1, 0.5);
for (i = 1, j = 0; i < sparks; i++) {
sparkIndex[j++] = 0;
sparkIndex[j++] = i;
sparkIndex[j++] = -1;
sparkColor[i] = new SFColor(
0.3+0.6*Math.random(),
0.2+0.6*Math.random(),
0);
}
randomSparks();
//Init last
last.x = Math.round(linSteps / 2);
toolPosition_changed = toolOffset_changed = toolPosition =
new SFVec3f(0, -3, 0);
doRotate = TRUE;
}
function set_toolActive(active, time) {
if (!active) toolOffset_changed = toolPosition;
}
function set_toolPosition(pos, time) {
toolPosition = pos;
if (toolPosition.x > 7) toolPosition.x = 7; else
if (toolPosition.x < -7) toolPosition.x = -7;
if (toolPosition.y > -.5) toolPosition.y = -.5; else
if (toolPosition.y < -6) toolPosition.y = -6;
center = Math.round( 0.5 * linSteps +
toolPosition.x * linSteps / width) + 1;
dist = -toolPosition.y;
val = crossSection[center];
cut = FALSE;
if (doRotate) {
if (Math.abs(center - last.x) <= 1) {
if (val.x + 1 > dist) {
val.x = dist - 1;
crossSection[center] = val;
cut = TRUE;
}
} else {
if (center < last.x) {
start = center;
end = last.x - 1;
d = dist;
deltaD = (last.y - dist) / (end - start);
} else {
start = last.x + 1;
end = center;
d = last.y;
deltaD = (dist - last.y) / (end - start);
}
for ( i = start; i <= end; i++ ) {
val = crossSection[i];
if (val.x + 1 > d) {
val.x = d - 1;
crossSection[i] = val;
cut = TRUE;
}
d += deltaD;
}
}
} else {
if (val.x + 1 > dist) toolPosition.y = -(val.x + 1);
}
last.x = center;
last.y = dist;
toolPosition_changed = toolPosition;
if (cut) {
randomSparks();
sparkTimerStart = time;
toolSoundStart = time;
cutTime = time;
sparkChoice = 0;
}
}
function sparkActive(active, time)
{
if (!active && time - cutTime >= 0.3) {
sparkChoice = -1;
toolSoundStop = time;
}
}
function sparkFraction(active)
{
randomSparks();
}
function rotTouched(time)
{
rotFraction = 0;
doRotate = !doRotate;
if (doRotate) startSound = time; else stopSound = time;
}
function reset(time)
{
initialize();
startSound = time;
}
"
}
ROUTE SCRIPT.crossSection TO SHAPE.set_crossSection
ROUTE SCRIPT.spine TO SHAPE.set_spine
ROUTE SCRIPT.sparkCoord TO SPARKCOORD.set_point
ROUTE SCRIPT.sparkIndex TO SPARKS.set_coordIndex
ROUTE SCRIPT.sparkColor TO SPARKCOLOR.set_color
ROUTE SCRIPT.sparkChoice TO SPARKSWITCH.set_whichChoice
ROUTE SCRIPT.sparkTimerStart TO SPARKTIMER.set_stopTime
ROUTE SCRIPT.sparkTimerStart TO SPARKTIMER.set_startTime
ROUTE SPARKTIMER.isActive TO SCRIPT.sparkActive
ROUTE SPARKTIMER.fraction_changed TO SCRIPT.sparkFraction
ROUTE SCRIPT.toolSoundStart TO TOOLSOUND.set_startTime
ROUTE SCRIPT.toolSoundStop TO TOOLSOUND.set_stopTime
ROUTE TOOLSENSOR.translation_changed TO SCRIPT.set_toolPosition
ROUTE TOOLSENSOR.isActive TO SCRIPT.set_toolActive
ROUTE SCRIPT.toolPosition_changed TO TOOLTRANS.set_translation
ROUTE SCRIPT.toolOffset_changed TO TOOLSENSOR.set_offset
ROUTE ROTTIME.fraction_changed TO ROTINT.set_fraction
ROUTE ROTINT.value_changed TO ROTTRANS.set_rotation
ROUTE SCRIPT.rotFraction TO ROTINT.set_fraction
ROUTE ROTTOUCH.touchTime TO SCRIPT.rotTouched
ROUTE SCRIPT.doRotate TO ROTTIME.set_enabled
ROUTE SCRIPT.startSound TO LATHESOUND.set_startTime
ROUTE SCRIPT.stopSound TO LATHESOUND.set_stopTime
ROUTE RESETBUTTON.touchTime TO SCRIPT.reset
ROUTE PANELPROX.position_changed TO PANELTRANS.set_translation
ROUTE PANELPROX.orientation_changed TO PANELTRANS.set_rotation
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -