Ai
13 Star 86 Fork 30

AnyCAD/anycad.rapid.net.sample

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Graphics_GeometryDynamic.cs 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
cloud 提交于 2023-06-23 10:55 +08:00 . 增加EnableAnimation精确控制动画启停
using AnyCAD.Foundation;
using System;
namespace AnyCAD.Demo.Graphics
{
class Graphics_GeometryDynamic : TestCase
{
uint worldWidth = 128;
uint worldDepth = 128;
BufferGeometry mGeometry;
public override void Run(IRenderView render)
{
mGeometry = GeometryBuilder.CreatePlane(20000, 20000, worldWidth - 1, worldDepth - 1);
var position = mGeometry.GetAttribute(0);
position.SetDataUsage(EnumBufferDataUsage.DYNAMIC_DRAW);
var mPosition = new Float32Array(position.GetData());
for (uint i = 0; i < position.GetCount()/3; i++)
{
float z = (float)(35 * Math.Sin(i / 2));
mPosition.SetValue(i * 3 + 2, z);
}
var material = BasicMaterial.Create("basic-water");
var img = FileImage.Create(GetResourcePath("textures/water.png"));
var texture = new ImageTexture2D();
texture.SetSource(img);
var desc = texture.GetDesc();
desc.SetWrapS(EnumTextureWrappingType.REPEAT);
desc.SetWrapT(EnumTextureWrappingType.REPEAT);
texture.SetRepeat(new Vector2(5, 5));
material.AddTexture("map", texture);
var color = ColorTable.Hex(0x0044ff);
material.SetUniform("diffuse", color);
var node = new PrimitiveSceneNode(mGeometry, material);
node.SetPickable(false);
node.SetCulling(false);
render.ShowSceneNode(node);
render.EnableAnimation(true);
}
public override void Exit(IRenderView render)
{
render.EnableAnimation(false);
}
public override void Animation(IRenderView render, float time)
{
var position = mGeometry.GetAttribute(0);
position.SetDataUsage(EnumBufferDataUsage.DYNAMIC_DRAW);
var mPosition = new Float32Array(position.GetData());
var count = mPosition.GetItemCount() / 3;
for (uint i = 0; i < count; i++)
{
var z = (float)(35 * Math.Sin(i / 5 + (time * 50 + i) / 7));
mPosition.SetValue(i*3+2, z);
}
position.RequestUpdate();
mGeometry.RequestUpdate();
render.RequestDraw();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/anycad/anycad.rapid.net.sample.git
git@gitee.com:anycad/anycad.rapid.net.sample.git
anycad
anycad.rapid.net.sample
anycad.rapid.net.sample
master

搜索帮助