浏览我们的产品
Aspose.3D for .NET 17.9发行说明
其他改进和变化
钥匙 | 摘要 | 类别 |
---|---|---|
THREEDNET-286 | 添加支持以从FBX唯一标识网格 | 新功能 |
THREEDNET-288 | 添加支持在完全定制的着色器中渲染场景 | 新功能 |
THREEDNET-284 | 提高写入大型FBX文件时的内存消耗 | 增强 |
THREEDNET-293 | 错误的将OBJ与纹理导出到GLTF和GLB | Bug |
THREEDNET-290 | 动画属性旋转 (Euler) 和FBX格式的比例 | Bug |
公共API和向后不兼容的更改
请参阅对公共API所做的任何更改的列表,如添加、重命名、删除或不推荐使用的成员,以及对Aspose.3D for .NET所做的任何非向后兼容的更改。如果您对列出的任何更改有疑问,请在Aspose.3D支持论坛。
将CreateAnimationClip成员添加到Aspose.ThreeD.Scene类
它有助于创建动画。
定义C#
/// <summary>
/// A shorthand function to create and register the <see cref="AnimationClip"/>
/// The first <see cref="AnimationClip"/> will be assigned to the <see cref="CurrentAnimationClip"/>
/// </summary>
/// <param name="name">Animation clip's name</param>
/// <returns></returns>
public Aspose.ThreeD.Animation.AnimationClip CreateAnimationClip(string name)
这是创建动画剪辑的简写函数,在制作此函数之前,要创建动画剪辑,您必须:
遗留方法C#
AnimationClip anim = new AnimationClip("anim");
scene.AnimationClips.Add(anim);
//set this as current clip
scene.CurrentAnimationClip = anim;
等效代码为:
新方法C#
//create an animation clip
AnimationClip anim = scene.CreateAnimationClip("anim");
CreateAnimationClip方法将在场景中制作动画剪辑。
将CreateAnimationNode成员添加到Aspose.ThreeD.Animation.AnimationClip类
它有助于创建动画节点。
定义C#
/// <summary>
/// A shorthand function to create and register the animation node on current clip.
/// </summary>
/// <param name="nodeName">New animation node's name</param>
/// <returns></returns>
public Aspose.ThreeD.Animation.AnimationNode CreateAnimationNode(string nodeName)
这是创建和注册AnimationNode的一个简写函数,在此函数之前你需要写:
遗留方法C#
var anode = new AnimationNode("animRot");
anim.Animations.Add(anode);
等效代码为:
新方法C#
var anode = anim.CreateAnimationNode("animRot");
将三个成员添加到Aspose.ThreeD.Animation.Curve类
所有这些成员都有助于创建关键框架。
定义C#
/// <summary>
/// Create a new key frame with specified value
/// A synonym of <see cref="CreateKeyFrame(double, float)"/>
/// </summary>
/// <param name="time">Time position(measured in seconds)</param>
/// <param name="value">The value at this time position</param>
public void Add(double time, float value)
/// <summary>
/// Create a new key frame with specified value
/// A synonym of <see cref="CreateKeyFrame(double, float, Interpolation)"/>
/// </summary>
/// <param name="time">Time position(measured in seconds)</param>
/// <param name="value">The value at this time position</param>
/// <param name="interpolation">The interpolation type of this key frame</param>
public void Add(double time, float value, Aspose.ThreeD.Animation.Interpolation interpolation)
/// <summary>
/// Gets the enumerator to traverse all key frames.
/// </summary>
/// <returns></returns>
public System.Collections.Generic.IEnumerator<Aspose.ThreeD.Animation.KeyFrame> GetEnumerator()
Add方法是CreateKeyFrame的同义词,CreateKeyFrame方法都被标记为已过时,类曲线现在实现了IEnumerable
将BindCurve成员添加到Aspose.ThreeD.Animation.CurveMapping类
这将在CurveMapping中绑定现有通道上的曲线数据。
定义C#
/// <summary>
/// Bind the curve to specified channel
/// </summary>
/// <param name="channelName">Which channel the curve will be bound to</param>
/// <param name="curve">The curve data</param>
public void BindCurve(string channelName, Aspose.ThreeD.Animation.Curve curve)
在17.9手动创建动画的版本之前,您需要:
C#
//create a curve mapping on cube node's transform object, the curve manipulates the property 'Scale'
var scale = anode.CreateCurveMapping(cube1.Transform, "Scale");
// Create the animation curve on Y component of the scale
Curve scaleYCurve = scale.CreateCurve("Y");
//let cube1.Transform.Scale.Y to be 1.0f at 0th sec using bezier interpolation
scaleYCurve.CreateKeyFrame(0, 1.0f, Interpolation.Bezier);
//let cube1.Transform.Scale.Y to be 2.0f at 2th sec using bezier interpolation
scaleYCurve.CreateKeyFrame(2, 2.0f, Interpolation.Bezier);
//let cube1.Transform.Scale.Y to be 0.2f at 5th sec using linear interpolation
scaleYCurve.CreateKeyFrame(5, 0.2f, Interpolation.Linear);
//let cube1.Transform.Scale.Y to be 1.0f at 8th sec using bezier interpolation
scaleYCurve.CreateKeyFrame(8, 1.0f, Interpolation.Bezier);
现在在版本17.9中,您可以使用语法sugar实现相同的任务:
C#
//create a curve mapping on cube node's transform object, the curve manipulates the property 'Scale'
var scale = anode.CreateCurveMapping(cube1.Transform, "Scale");
// Create the animation curve on Y component of the scale
scale.BindCurve("Y", new Curve()
{
//let cube1.Transform.Scale.Y to be 1.0f at 0th sec using bezier interpolation
{0, 1.0f, Interpolation.Bezier},
//let cube1.Transform.Scale.Y to be 2.0f at 2th sec using bezier interpolation
{2, 2.0f, Interpolation.Bezier},
//let cube1.Transform.Scale.Y to be 0.2f at 5th sec using linear interpolation
{5, 0.2f, Interpolation.Linear},
//let cube1.Transform.Scale.Y to be 1.0f at 8th sec using bezier interpolation
{8, 1.0f, Interpolation.Bezier}
});
将ShaderSet和PresetShaders成员添加到Aspose.ThreeD.Renderer类
ShaderSet允许您覆盖Aspose.3D的渲染器的默认实现,如果您分配了自定义的ShaderSet实例,则属性PresetShaders将变为preetshaders。自定义的,如果您想恢复到Aspose.3D的默认shader集,则可以分配preetshaders。默认通过使用此机制使属性ShaderSet无效,我们可以允许用户控制渲染效果,而我们仍然可以提供具有足够可扩展性的自己的实现。
定义C#
/// <summary>
/// Gets or sets the shader set that used to render the scene
/// </summary>
Aspose.ThreeD.Render.ShaderSet ShaderSet{ get;set;}
/// <summary>
/// Gets or sets the preset shader set
/// </summary>
Aspose.ThreeD.Render.PresetShaders PresetShaders{ get;set;}
添加Aspose.ThreeD.Render.PresetShaders类
现在只有默认值可用,将来可以提供其他渲染样式,例如非现实着色器。
定义C#
/// <summary>
/// This defines the preset internal shaders used by the renderer.
/// </summary>
public enum PresetShaders
{
/// <summary>
/// Use the default shaders for phong/lambert/pbr materials
/// </summary>
Default,
/// <summary>
/// User's customized shader set
/// </summary>
Customized
}
添加Aspose.ThreeD.Render.ShaderSet类
它有助于自定义每个不同材质使用的着色程序,以完全控制最终渲染结果。
定义C#
/// <summary>
/// Shader programs for each kind of materials
/// </summary>
public class ShaderSet : IDisposable
{
/// <summary>
/// Gets or sets the shader that used to render the lambert material
/// </summary>
public ShaderProgram Lambert { get; set; }
/// <summary>
/// Gets or sets the shader that used to render the phong material
/// </summary>
public ShaderProgram Phong { get; set; }
/// <summary>
/// Gets or sets the shader that used to render the PBR material
/// </summary>
public ShaderProgram Pbr { get; set; }
/// <summary>
/// Gets or sets the fallback shader when required shader is unavailable
/// </summary>
public ShaderProgram Fallback { get; set; }
}
使用具有线性化深度而不是颜色的自定义着色器在全景模式下渲染场景。
它有助于自定义每个不同材质使用的着色程序,以完全控制最终渲染结果。
定义C#
public void RenderPanoramaInDepth()
{
string path = TestData + @"/textures/skybox2/skybox.obj";
//load the scene
Scene scene = new Scene(path);
//create a camera for capturing the cube map
Camera cam = new Camera(ProjectionType.Perspective);
cam.NearPlane = 0.1;
cam.FarPlane = 200;
scene.RootNode.CreateChildNode(cam).Transform.Translation = new Vector3(5, 6, 0);
cam.RotationMode = RotationMode.FixedDirection;
//create two lights to illuminate the scene
scene.RootNode.CreateChildNode(new Light() {LightType = LightType.Point}).Transform.Translation = new Vector3(-10, 7, -10);
scene.RootNode.CreateChildNode(new Light()
{
LightType = LightType.Point,
ConstantAttenuation = 0.1,
Color = new Vector3(Color.CadetBlue)
}).Transform.Translation = new Vector3(49, 0, 49);
//create a render target
using (var renderer = Renderer.CreateRenderer())
{
//Create a cube map render target with depth texture, depth is required when rendering a scene.
IRenderTexture rt = renderer.RenderFactory.CreateCubeRenderTexture(new RenderParameters(false), 512, 512);
//create a 2D texture render target with no depth texture used for image processing
IRenderTexture final = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(false, 32, 0, 0), 1024 * 3 , 1024);
//a viewport is required on the render target
rt.CreateViewport(cam, RelativeRectangle.FromScale(0, 0, 1, 1));
renderer.ShaderSet = CreateDepthShader(renderer);
renderer.Render(rt);
//execute the equirectangular projection post-processing with the previous rendered cube map as input
PostProcessing equirectangular = renderer.GetPostProcessing("equirectangular");
equirectangular.Input = rt.Targets[0];
renderer.Execute(equirectangular, final);
//save the texture into disk
((ITexture2D)final.Targets[0]).Save(RenderResult + "/depth-equirectangular.png", ImageFormat.Png);
}
}
private static ShaderSet CreateDepthShader(Renderer renderer)
{
GLSLSource src = new GLSLSource();
src.VertexShader = @"#version 330 core
layout (location = 0) in vec3 position;
uniform mat4 matWorldViewProj;
out float depth;
void main()
{
gl_Position = matWorldViewProj * vec4(position, 1.0f);
float zfar = 200.0;
float znear = 0.5;
//visualize the depth by linearize it so we don't get a blank screen
depth = (2.0 * znear) / (zfar + znear - gl_Position.z /gl_Position.w * (zfar - znear));
}";
src.FragmentShader = @"#version 330 core
in float depth;
out vec4 color;
void main()
{
color = vec4(depth, depth, depth, 1);
}";
//we only need the position to render the depth map
VertexDeclaration fd = new VertexDeclaration();
fd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position);
//compile shader from GLSL source code and specify the vertex input format
var shader = renderer.RenderFactory.CreateShaderProgram(src, fd);
//connect GLSL uniform to renderer's internal variable
shader.Variables = new ShaderVariable[]
{
new ShaderVariable("matWorldViewProj", VariableSemantic.MatrixWorldViewProj)
};
//create a shader set
ShaderSet ret = new ShaderSet();
//we only use the fallback, and left other shaders unassigned, so all materials will be rendered by this shader
ret.Fallback = shader;
return ret;
}
使用示例
请查看Aspose.3D Wiki docs中添加或更新的帮助主题列表: