我怎样才能让这个 papervision3d 代码工作?
该代码可以工作,但它确实将立方体显示为第一个代码,并且视图、缩放和交互性不同,因此我希望立方体显示为具有相同功能的第一个代码。
第一个代码在这里: http://papervision2.com/10-advanced-interactivity/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
public class Main extends BasicView
{
protected var cube:Cube;
protected var interactiveMats:Array;
protected var materialsList:MaterialsList;
protected var targetrotationX:Number;
protected var targetrotationY:Number;
protected var targetrotationZ:Number;
protected var tweening:Boolean;
public function Main():void
{
super();
init();
}
protected function init():void
{
createChildren();
startRendering();
}
protected function createChildren():void
{
//Set the viewport to interactive
viewport.interactive = true;
//Create Materials:
materialsList = new MaterialsList();
interactiveMats = ["front", "back", "left", "right", "bottom", "top"];
var colorsArray:Array = [0x76b6f8, 0x4291e1, 0x1f73c8, 0xe77111, 0xe8914c, 0xfad2b2];
for (var i:int = 0; i < interactiveMats.length; i++)
{
//Create a color box so we can use our MouseEvents
var colorBox:Sprite = new Sprite();
colorBox.graphics.beginFill(colorsArray[i]);
colorBox.graphics.drawRect(0, 0, 100, 100);
colorBox.graphics.endFill();
colorBox.name = interactiveMats[i];
//Add a textField for reference
var textField:TextField = new TextField()
colorBox.addChild(textField)
textField.text = interactiveMats[i];
//Add a MouseEvent to the Sprite
colorBox.mouseChildren = false;
colorBox.addEventListener(MouseEvent.CLICK, onMovieMatClicked);
//Create the MovieMat
var movieMat:MovieMaterial = new MovieMaterial(colorBox, true, true);
movieMat.interactive = true;
movieMat.smooth = true;
materialsList.addMaterial(movieMat, interactiveMats[i]);
}
//Create Cube
cube = new Cube(materialsList, 100, 100, 100);
//Add cube to the scene
scene.addChild(cube);
}
protected function onMovieMatClicked(evt:MouseEvent):void
{
if (tweening)
{
// Let it rotate again
tweening = false;
}
else
{
switch(evt.target.name) {
case "front":
targetrotationX = 0;
targetrotationY = 180;
targetrotationZ = 0;
tweening = true;
break;
case "back":
targetrotationX = 0;
targetrotationY = 0;
targetrotationZ = 0;
tweening = true;
break;
case "left":
targetrotationX = 0;
targetrotationY = -90;
targetrotationZ = 0;
tweening = true;
break;
case "right":
targetrotationX = 0;
targetrotationY = 90;
targetrotationZ = 0;
tweening = true;
break;
case "top":
targetrotationX = -90;
targetrotationY = 0;
targetrotationZ = 0;
tweening = true;
break;
case "bottom":
targetrotationX = 90;
targetrotationY = 0;
targetrotationZ = 180;
tweening = true;
break;
}
}
}
override protected function onRenderTick(event:Event = null):void
{
super.onRenderTick(event);
if (tweening) {
// If a face has been clicked
if (camera.zoom <230) {
// If the camera isn't zoomed enough then zoom in a bit more:
camera.zoom += Math.sqrt(230-camera.zoom)/5;
}
// Test each rotation and rotate it towards the target rotation:
// X axis:
if (cube.rotationX < targetrotationX)
{
cube.rotationX += Math.sqrt(targetrotationX-cube.rotationX);
cube.rotationX = Math.round(cube.rotationX);
}
else if (cube.rotationX > targetrotationX)
{
cube.rotationX -= Math.sqrt(cube.rotationX-targetrotationX);
cube.rotationX = Math.round(cube.rotationX);
}
// Y axis:
if (cube.rotationY < targetrotationY)
{
cube.rotationY += Math.sqrt(targetrotationY-cube.rotationY);
cube.rotationY = Math.round(cube.rotationY);
}
else if (cube.rotationY > targetrotationY)
{
cube.rotationY -= Math.sqrt(cube.rotationY-targetrotationY);
cube.rotationY = Math.round(cube.rotationY);
}
// Z axis:
if (cube.rotationZ < targetrotationZ)
{
cube.rotationZ += Math.sqrt(targetrotationZ-cube.rotationZ);
cube.rotationZ = Math.round(cube.rotationZ);
}
else if (cube.rotationZ > targetrotationZ)
{
cube.rotationZ -= Math.sqrt(cube.rotationZ-targetrotationZ);
cube.rotationZ = Math.round(cube.rotationZ);
}
}
else
{
// If the camera is zoomed in, it shouldn't be now
if (camera.zoom > 200)
{
// So zoom out a bit.
camera.zoom -= Math.sqrt(camera.zoom-2)/5;
}
// Rotate the cube a bit:
cube.rotationX += 2;
cube.rotationY += 2;
// Make sure that we dont "wind up" the rotation
if (cube.rotationX>= 360) cube.rotationX = 0;
if (cube.rotationY>= 360) cube.rotationY = 0;
}
}
}
}
This code works but it does display the cube as the first code and the view, zoom and interactivity is different, so i wanted the cube to be displayed as in the first code with the same features.
first code is here: http://papervision2.com/10-advanced-interactivity/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
public class Main extends BasicView
{
protected var cube:Cube;
protected var interactiveMats:Array;
protected var materialsList:MaterialsList;
protected var targetrotationX:Number;
protected var targetrotationY:Number;
protected var targetrotationZ:Number;
protected var tweening:Boolean;
public function Main():void
{
super();
init();
}
protected function init():void
{
createChildren();
startRendering();
}
protected function createChildren():void
{
//Set the viewport to interactive
viewport.interactive = true;
//Create Materials:
materialsList = new MaterialsList();
interactiveMats = ["front", "back", "left", "right", "bottom", "top"];
var colorsArray:Array = [0x76b6f8, 0x4291e1, 0x1f73c8, 0xe77111, 0xe8914c, 0xfad2b2];
for (var i:int = 0; i < interactiveMats.length; i++)
{
//Create a color box so we can use our MouseEvents
var colorBox:Sprite = new Sprite();
colorBox.graphics.beginFill(colorsArray[i]);
colorBox.graphics.drawRect(0, 0, 100, 100);
colorBox.graphics.endFill();
colorBox.name = interactiveMats[i];
//Add a textField for reference
var textField:TextField = new TextField()
colorBox.addChild(textField)
textField.text = interactiveMats[i];
//Add a MouseEvent to the Sprite
colorBox.mouseChildren = false;
colorBox.addEventListener(MouseEvent.CLICK, onMovieMatClicked);
//Create the MovieMat
var movieMat:MovieMaterial = new MovieMaterial(colorBox, true, true);
movieMat.interactive = true;
movieMat.smooth = true;
materialsList.addMaterial(movieMat, interactiveMats[i]);
}
//Create Cube
cube = new Cube(materialsList, 100, 100, 100);
//Add cube to the scene
scene.addChild(cube);
}
protected function onMovieMatClicked(evt:MouseEvent):void
{
if (tweening)
{
// Let it rotate again
tweening = false;
}
else
{
switch(evt.target.name) {
case "front":
targetrotationX = 0;
targetrotationY = 180;
targetrotationZ = 0;
tweening = true;
break;
case "back":
targetrotationX = 0;
targetrotationY = 0;
targetrotationZ = 0;
tweening = true;
break;
case "left":
targetrotationX = 0;
targetrotationY = -90;
targetrotationZ = 0;
tweening = true;
break;
case "right":
targetrotationX = 0;
targetrotationY = 90;
targetrotationZ = 0;
tweening = true;
break;
case "top":
targetrotationX = -90;
targetrotationY = 0;
targetrotationZ = 0;
tweening = true;
break;
case "bottom":
targetrotationX = 90;
targetrotationY = 0;
targetrotationZ = 180;
tweening = true;
break;
}
}
}
override protected function onRenderTick(event:Event = null):void
{
super.onRenderTick(event);
if (tweening) {
// If a face has been clicked
if (camera.zoom <230) {
// If the camera isn't zoomed enough then zoom in a bit more:
camera.zoom += Math.sqrt(230-camera.zoom)/5;
}
// Test each rotation and rotate it towards the target rotation:
// X axis:
if (cube.rotationX < targetrotationX)
{
cube.rotationX += Math.sqrt(targetrotationX-cube.rotationX);
cube.rotationX = Math.round(cube.rotationX);
}
else if (cube.rotationX > targetrotationX)
{
cube.rotationX -= Math.sqrt(cube.rotationX-targetrotationX);
cube.rotationX = Math.round(cube.rotationX);
}
// Y axis:
if (cube.rotationY < targetrotationY)
{
cube.rotationY += Math.sqrt(targetrotationY-cube.rotationY);
cube.rotationY = Math.round(cube.rotationY);
}
else if (cube.rotationY > targetrotationY)
{
cube.rotationY -= Math.sqrt(cube.rotationY-targetrotationY);
cube.rotationY = Math.round(cube.rotationY);
}
// Z axis:
if (cube.rotationZ < targetrotationZ)
{
cube.rotationZ += Math.sqrt(targetrotationZ-cube.rotationZ);
cube.rotationZ = Math.round(cube.rotationZ);
}
else if (cube.rotationZ > targetrotationZ)
{
cube.rotationZ -= Math.sqrt(cube.rotationZ-targetrotationZ);
cube.rotationZ = Math.round(cube.rotationZ);
}
}
else
{
// If the camera is zoomed in, it shouldn't be now
if (camera.zoom > 200)
{
// So zoom out a bit.
camera.zoom -= Math.sqrt(camera.zoom-2)/5;
}
// Rotate the cube a bit:
cube.rotationX += 2;
cube.rotationY += 2;
// Make sure that we dont "wind up" the rotation
if (cube.rotationX>= 360) cube.rotationX = 0;
if (cube.rotationY>= 360) cube.rotationY = 0;
}
}
}
}
code2 taken from: http://papervision2.com/advanced-interactivity/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但是,文章已提交,它将
<
解析为<
,将>
解析为>
。对每个错误进行查找/替换,大部分错误就会消失。
However the article was submitted, it parsed
<
to<
and>
to>
.Do a find/replace for each of those and the bulk of the errors should go away.