我是 As 和 Flash 的新手,我需要通过 Actionscript 中的代码镜像汽车的一半。有人可以帮我编码吗?我在网上看过,但对我来说似乎没有什么很清楚。
我在 Flash Professional CS6 中的 main.as 文件中有许多 'CarParts'.as 文件,其中一些将被镜像以保存数据,例如:carPaintLeft.as、wheelsLeft.as、rimsLeft.as、windowsLeft.as , carLeft.as,... 所有这些都必须从我的绘图中心 (x0,y0,z0) 镜像到我的 X 轴上。
例如,这里是 PaintInstance.as,一个包含 9 个不同网格的数据文件(在这种情况下,所有网格都具有相同的材质:汽车油漆,例如红色)。我将它导入到我的 Main.as 文件中,我需要镜像所有它(9 个网格)。我该如何编写代码,我应该在哪里编写代码,在我的 Main.as 中,还是应该在 PaintInstance.as 中编写?这是我的 PaintInstance.as:
package
{
import ASBase;
import away3d.containers.ObjectContainer3D;
import away3d.entities.Mesh;
import away3d.core.base.Geometry;
import away3d.materials.MaterialBase;
import away3d.core.base.Geometry;
import away3d.materials.ColorMaterial;
import data.Hood_coverData;
import flash.display.Bitmap;
import data.Sideclosures_mainbodytopData;
import data.Extmirror_bodypart_iData;
import data.Fender_bodypartData;
import data.Frontdoor_bodyData;
import data.Sidemoldingpart_iData;
import data.Sidemoldingpart_iiData;
import data.Frontdoor_doorhandlepart_iData;
import data.Frontdoor_doorhandlepart_iiData;
public class PaintInstance extends ASBase
{
function PaintInstance ():void
{
super();
buildMaterials();
generate();
}
private function generate():void
{
var cont_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var cont:ObjectContainer3D = buildContainer( cont_rd, "cont", null);
var hood_coverData:Hood_coverData = new Hood_coverData();
var geomhood_cover:Geometry = hood_coverData.geometryData;
var hood_cover_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var hood_cover:Mesh = buildMesh(geomhood_cover, hood_cover_rd, "hood_cover", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);
hood_cover.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");
var sideclosures_mainbodytopData:Sideclosures_mainbodytopData = new Sideclosures_mainbodytopData();
var geomsideclosures_mainbodytop:Geometry = sideclosures_mainbodytopData.geometryData;
var sideclosures_mainbodytop_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var sideclosures_mainbodytop:Mesh = buildMesh(geomsideclosures_mainbodytop, sideclosures_mainbodytop_rd, "sideclosures_mainbodytop", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);
sideclosures_mainbodytop.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");
var extmirror_bodypart_iData:Extmirror_bodypart_iData = new Extmirror_bodypart_iData();
var geomextmirror_bodypart_i:Geometry = extmirror_bodypart_iData.geometryData;
var extmirror_bodypart_i_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var extmirror_bodypart_i:Mesh = buildMesh(geomextmirror_bodypart_i, extmirror_bodypart_i_rd, "extmirror_bodypart_i", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);
extmirror_bodypart_i.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");
var fender_bodypartData:Fender_bodypartData = new Fender_bodypartData();
var geomfender_bodypart:Geometry = fender_bodypartData.geometryData;
var fender_bodypart_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var fender_bodypart:Mesh = buildMesh(geomfender_bodypart, fender_bodypart_rd, "fender_bodypart", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);
fender_bodypart.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");
var frontdoor_bodyData:Frontdoor_bodyData = new Frontdoor_bodyData();
var geomfrontdoor_body:Geometry = frontdoor_bodyData.geometryData;
var frontdoor_body_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var frontdoor_body:Mesh = buildMesh(geomfrontdoor_body, frontdoor_body_rd, "frontdoor_body", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);
frontdoor_body.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");
var sidemoldingpart_iData:Sidemoldingpart_iData = new Sidemoldingpart_iData();
var geomsidemoldingpart_i:Geometry = sidemoldingpart_iData.geometryData;
var sidemoldingpart_i_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var sidemoldingpart_i:Mesh = buildMesh(geomsidemoldingpart_i, sidemoldingpart_i_rd, "sidemoldingpart_i", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);
sidemoldingpart_i.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");
var sidemoldingpart_iiData:Sidemoldingpart_iiData = new Sidemoldingpart_iiData();
var geomsidemoldingpart_ii:Geometry = sidemoldingpart_iiData.geometryData;
var sidemoldingpart_ii_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var sidemoldingpart_ii:Mesh = buildMesh(geomsidemoldingpart_ii, sidemoldingpart_ii_rd, "sidemoldingpart_ii", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);
sidemoldingpart_ii.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");
var frontdoor_doorhandlepart_iData:Frontdoor_doorhandlepart_iData = new Frontdoor_doorhandlepart_iData();
var geomfrontdoor_doorhandlepart_i:Geometry = frontdoor_doorhandlepart_iData.geometryData;
var frontdoor_doorhandlepart_i_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var frontdoor_doorhandlepart_i:Mesh = buildMesh(geomfrontdoor_doorhandlepart_i, frontdoor_doorhandlepart_i_rd, "frontdoor_doorhandlepart_i", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);
frontdoor_doorhandlepart_i.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");
var frontdoor_doorhandlepart_iiData:Frontdoor_doorhandlepart_iiData = new Frontdoor_doorhandlepart_iiData();
var geomfrontdoor_doorhandlepart_ii:Geometry = frontdoor_doorhandlepart_iiData.geometryData;
var frontdoor_doorhandlepart_ii_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
var frontdoor_doorhandlepart_ii:Mesh = buildMesh(geomfrontdoor_doorhandlepart_ii, frontdoor_doorhandlepart_ii_rd, "frontdoor_doorhandlepart_ii", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);
frontdoor_doorhandlepart_ii.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");
}
private function buildMaterials():void
{
var material:MaterialBase;
material = generateMaterial("FrontDoor_DoorHandlePart_II0", 0xFF0000);
ColorMaterial(material).alpha = 1;
ColorMaterial(material).ambientColor = 0x0;
ColorMaterial(material).specularColor = 0x0;
ColorMaterial(material).specular = 0;
}
}
}
我只有这些,但我不是很明白,有人可以帮助我吗?在您的PrefabClass.meshes 的speudo 代码循环中如果(yourPrefabClass.meshes[indexloop].name == “theNameOfTheWheelMeshThaTIWantToMirror”)
var myWheel:Mesh = yourPrefabClass.meshes[indexloop];
var mirror:Mirror = new Mirror();
mirror.apply(myWheel, Mirror.X_AXIS, Mirror.CENTER, 0);
所以,例如对我来说会是什么?:
private function Mirror(): void
{
for (PaintInstance.meshes)
{
if (PaintInstance.meshes["Hood_Cover","sideclosures_mainbodytop","extmirror_bodypart_i","fender_bodypart","frontdoor_body","sidemoldingpart_i","sidemoldingpart_ii","frontdoor_doorhandlepart_i","frontdoor_doorhandlepart_ii"].name == “Hood_Cover”)
{
var Hood_Cover:Mesh = PaintInstance.meshes["Hood_Cover","sideclosures_mainbodytop","extmirror_bodypart_i","fender_bodypart","frontdoor_body","sidemoldingpart_i","sidemoldingpart_ii","frontdoor_doorhandlepart_i","frontdoor_doorhandlepart_ii"];
var mirror:Mirror = new Mirror ();
mirror.apply(Hood_Cover, Mirror.X_AXIS, Mirror.CENTER, 0);
}
}
}
他们告诉我:对于很多网格,我必须在 class.meshes 循环中插入一个 switch 语句,并在 switch 案例中具有专用的镜像功能,例如,您可以在其中推送一堆镜像命令。
喜欢
switch(mesh.name){ case “myWheel”: doMirror(mesh, [ xmax, zmin ] );
我知道你们中的一些人可能很清楚,但我基本上对动作脚本一无所知,只是一个 lil 编程,我现在需要这样做......有人可以告诉我我必须替代什么吗?
非常感谢提前