Aspose 中的公共 API 更改。3D 1.7.0
Contents
[
Hide
]
内容摘要
- 添加 Aspose.ThreeD.Entities.Frustum类
- 添加 Aspose.ThreeD.ImageRenderOptions类
- 在 Aspose.ThreeD.Entities.Camera类中添加MoveForward方法
- 在 Aspose.ThreeD.Entities.Geometry类中添加CastShadows和ReceiveShadows成员
- 在 Aspose.ThreeD.Entities.PolygonModifier类中添加generatenomal方法
- 在 Aspose.ThreeD.Utilities.Quaternion类中添加Concate方法
本文档介绍了对 Aspose.3D API 从版本1.5.0到1.7.0的更改,模块/应用程序开发人员可能会感兴趣。它不仅包括新的和更新的公共方法,还包括对 Aspose.3D 中幕后行为的任何更改的描述。
添加 Aspose.ThreeD.Entities.Frustum类
增加了一个新的平截头类。相机和灯光是实体类的子类。在1.7.0版本中,这些类是从截头锥体继承的,而截头锥体是从实体继承的,因为属性Position,Up,LookAt,Direction,Target,NearPlane和FarPlane被提取到截头锥体中。
将成员从 Aspose.ThreeD.Entities.Camera提取到 Aspose.ThreeD.Entities.Frustum 所有这些属性都被提取到截头锥体:
C#
Aspose.ThreeD.Utilities.Vector3 Position{ get;set;}
Aspose.ThreeD.Utilities.Vector3 Up{ get;set;}
Aspose.ThreeD.Utilities.Vector3 LookAt{ get;set;}
Aspose.ThreeD.Utilities.Vector3 Direction{ get;set;}
Aspose.ThreeD.Node Target{ get;set;}
double NearPlane{ get;set;}
double FarPlane{ get;set;}
从类 Aspose.ThreeD.Entities.Light提取成员到 Aspose.ThreeD.Entities.Frustum 所有这些属性都被提取到截头锥体:
C#
Aspose.ThreeD.Node Target{ get;set;}
Aspose.ThreeD.Utilities.Vector3 Direction{ get;set;}
添加 Aspose.ThreeD.ImageRenderOptions类
将 3D 文件转换为图像文件格式
C#
// load an existing 3D scene
Scene scene = new Scene("test.obj");
// create a camera at (10,10,10) and look at the origin point for rendering, it must be attached to the scene before render
Camera camera = new Camera();
scene.RootNode.CreateChildNode("camera", camera);
camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
camera.LookAt = Vector3.Origin;
//Specify the image render option
ImageRenderOptions opt = new ImageRenderOptions();
// set background color
opt.BackgroundColor = Color.AliceBlue;
// specify the path of textures
opt.AssetDirectories.Add(@"assets\textures");
// turn on shadow
opt.EnableShadows = true;
//render the scene in given camera's perspective into specified png file with size 1024x1024
scene.Render(camera, fileName, new Size(1024, 1024), ImageFormat.Png, opt);
已将成员添加到类 Aspose.ThreeD.Scene:
C#
public void Render(Aspose.ThreeD.Entities.Camera camera, string fileName, System.Drawing.Size size, System.Drawing.Imaging.ImageFormat format)
public void Render(Aspose.ThreeD.Entities.Camera camera, string fileName, System.Drawing.Size size, System.Drawing.Imaging.ImageFormat format, Aspose.ThreeD.ImageRenderOptions options)
public void Render(Aspose.ThreeD.Entities.Camera camera, System.Drawing.Bitmap bitmap)
public void Render(Aspose.ThreeD.Entities.Camera camera, System.Drawing.Bitmap bitmap, Aspose.ThreeD.ImageRenderOptions options)
在 Aspose.ThreeD.Entities.Camera类中添加MoveForward方法
它将相机朝其方向向前移动。摄像机的方向由任何目标/方向/外观指定
- **目标:**空间中的目标节点,无论目标/摄像机更改其空间位置,摄像机都将始终看着该目标。
- **查看:**在空间中的固定位置,相机将始终看着这个位置。
- **方向:**方向向量,相机的方向直接由该向量指定,无论其位置如何。
方法签名:
C#
public void MoveForward(double distance)
在 Aspose.ThreeD.Entities.Geometry类中添加CastShadows和ReceiveShadows成员
某些文件格式可以在几何体 (如 FBX) 中存储与阴影相关的设置,并且它们也用于渲染。在此代码示例中,红色框和圆环的阴影投射到平面上,红色框不会接收阴影,蓝色框不会投射阴影。
C#
Scene scene = new Scene();
Camera camera = new Camera();
camera.NearPlane = 0.1;
scene.RootNode.CreateChildNode("camera", camera);
Light light;
scene.RootNode.CreateChildNode("light", light = new Light()
{
NearPlane = 0.1,
CastShadows = true,
Color = new Vector3(Color.White)
}).Transform.Translation = new Vector3(9.4785, 5, 3.18);
light.LookAt = Vector3.Origin;
light.Falloff = 90;
//Create a plane
Node plane = scene.RootNode.CreateChildNode("plane", new Plane(20, 20));
plane.Material = new PhongMaterial() {DiffuseColor = new Vector3(Color.DarkOrange)};
plane.Transform.Translation = new Vector3(0, 0, 0);
//Create a torus for casting shadows
Mesh m = (new Torus("", 1, 0.4, 20, 20, Math.PI*2)).ToMesh();
Node torus = scene.RootNode.CreateChildNode("torus", m);
torus.Material = new PhongMaterial() {DiffuseColor = new Vector3(Color.Cornsilk)};
torus.Transform.Translation = new Vector3(2, 1, 1);
{//Create a blue box don't cast shadows
m = (new Box()).ToMesh();
m.CastShadows = false;
Node box = scene.RootNode.CreateChildNode("box", m);
box.Material = new PhongMaterial() {DiffuseColor = new Vector3(Color.Blue)};
box.Transform.Translation = new Vector3(2, 1, -1);
}
{// Create a red box that don't receive shadow but cast shadows
m = (new Box()).ToMesh();
m.ReceiveShadows = false;
Node box = scene.RootNode.CreateChildNode("box", m);
box.Material = new PhongMaterial() {DiffuseColor = new Vector3(Color.Red)};
box.Transform.Translation = new Vector3(-2, 1, 1);
}
camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
camera.LookAt = Vector3.Origin;
ImageRenderOptions opt = new ImageRenderOptions() {EnableShadows = true};
scene.Render(camera, "pic.png", new Size(1024, 1024), ImageFormat.Png, opt);
在 Aspose.ThreeD.Entities.PolygonModifier类中添加generatenomal方法
它允许开发人员从网格实例生成正常数据,如果在网格上定义了VertexElementSmoothingGroup元素,则生成的正常数据将由VertexElementSmoothingGroup平滑。
方法签名:
C#
public static Aspose.ThreeD.Entities.VertexElementNormal GenerateNormal(Aspose.ThreeD.Entities.Mesh mesh)
示例代码:
C#
//Load a 3ds file, 3ds file doesn't have normal data, but it has smoothing group
Scene s = new Scene("test.3ds");
//Visit all nodes and create normal data for all meshes
s.RootNode.Accept(delegate(Node n)
{
Mesh mesh = n.GetEntity<Mesh>();
if (mesh != null)
{
VertexElementNormal normals = PolygonModifier.GenerateNormal(mesh);
mesh.VertexElements.Add(normals);
}
return true;
});
在 Aspose.ThreeD.Utilities.Quaternion类中添加Concate方法
它允许开发人员将两个旋转变换连接成以四元数表示的一个。
方法签名:
C#
public Aspose.ThreeD.Utilities.Quaternion Concate(Aspose.ThreeD.Utilities.Quaternion rhs)
示例代码:
C#
Scene scene = new Scene();
Quaternion q1 = Quaternion.FromEulerAngle(Math.PI * 0.5, 0, 0);
Quaternion q2 = Quaternion.FromAngleAxis(- Math.PI * 0.5, Vector3.XAxis);
//concatenate q1 and q2. q1 and q2 rotate alone x-axis with same angle but different direction, so the concatenated result will be identity quaternion.
Quaternion q3 = q1.Concate(q2);
//Create 3 cylinders to represent each quaternion
Node cylinder = scene.RootNode.CreateChildNode("cylinder-q1", new Cylinder(0.1, 1, 2));
cylinder.Transform.Rotation = q1;
cylinder.Transform.Translation = new Vector3(-5, 2, 0);
cylinder = scene.RootNode.CreateChildNode("cylinder-q2", new Cylinder(0.1, 1, 2));
cylinder.Transform.Rotation = q2;
cylinder.Transform.Translation = new Vector3(0, 2, 0);
cylinder = scene.RootNode.CreateChildNode("cylinder-q3", new Cylinder(0.1, 1, 2));
cylinder.Transform.Rotation = q3;
cylinder.Transform.Translation = new Vector3(5, 2, 0);
//Save to file
scene.Save("test.fbx", FileFormat.FBX7400ASCII);