2021.10.28

2021SC@SDUSC

Class Texture

纹理对象。存储在CPU上,渲染图形时使用。

Properties:

IsNormalMap

返回布尔值,是否为一个normal map。

Methods

FromFile(String,Boolean)

从图像文件中加载纹理,并创建虚拟纹理对象。支持的文件格式取决于运行平台。所有平台都支持加载 PNG、 BMP、 TGA、 HDR 和 JPEG 文件。

参数里面路径自不必说,另一个布尔值代表是否创建bipmap。

返回一个texture,或者null。

Bipmap:在三维计算机图形的贴图渲染中有一个常用的技术被称为Mipmapping。为了加快渲染速度和减少图像锯齿,贴图被处理成由一系列被预先计算和优化过的图片组成的文件,这样的贴图被称为 MIP map。

LoadFile(String, Boolean)

从图像文件中加载纹理。支持的文件格式取决于运行时平台。所有平台都支持加载 PNG、 BMP、 TGA、 HDR 和 JPEG 文件。

Save(String)

保存。只支持编辑器。

Texture* Texture::FromFile(const StringView& path, bool generateMips)
{
    auto texture = Content::CreateVirtualAsset<Texture>();
    if (texture->LoadFile(path, generateMips))
    {
        texture->DeleteObject();
        texture = nullptr;
    }
    return texture;
}

void SkinnedModel::Draw(RenderContext& renderContext, const SkinnedMesh::DrawInfo& info)
{

绘制蒙皮模型

ASSERT(info.Buffer);
if (!CanBeRendered())
    return;
const auto frame = Engine::FrameCount;
const auto modelFrame = info.DrawState->PrevFrame + 1;
CHECK_INVALID_BUFFER(info.Buffer);

检查Flag:CanBeRendered

  lodIndex = RenderTools::ComputeSkinnedModelLOD(this, info.Bounds.Center, info.Bounds.Radius, renderContext);
    if (lodIndex == -1)
    {
        // Handling model fade-out transition
        if (modelFrame == frame && info.DrawState->PrevLOD != -1)
        {
            // Check if start transition
            if (info.DrawState->LODTransition == 255)
            {
                info.DrawState->LODTransition = 0;
            }

            RenderTools::UpdateModelLODTransition(info.DrawState->LODTransition);

            // Check if end transition
            if (info.DrawState->LODTransition == 255)
            {
                info.DrawState->PrevLOD = lodIndex;
            }
            else
            {
                const auto prevLOD = ClampLODIndex(info.DrawState->PrevLOD);
                const float normalizedProgress = static_cast<float>(info.DrawState->LODTransition) * (1.0f / 255.0f);
                LODs[prevLOD].Draw(renderContext, info, normalizedProgress);
            }
        }

        return;
    }
}

下面是更新一帧

if (modelFrame == frame)
{
    if (info.DrawState->PrevLOD != lodIndex && info.DrawState->LODTransition == 255)
    {
        info.DrawState->LODTransition = 0;
    }

    RenderTools::UpdateModelLODTransition(info.DrawState->LODTransition);

如果有新的帧,并且需要变化,那么调用对应方法。

if (info.DrawState->PrevLOD == lodIndex)
{
    LODs[lodIndex].Draw(renderContext, info, 0.0f);
}
else if (info.DrawState->PrevLOD == -1)
{
    const float normalizedProgress = static_cast<float>(info.DrawState->LODTransition) * (1.0f / 255.0f);
    LODs[lodIndex].Draw(renderContext, info, 1.0f - normalizedProgress);
}
else
{
    const auto prevLOD = ClampLODIndex(info.DrawState->PrevLOD);
    const float normalizedProgress = static_cast<float>(info.DrawState->LODTransition) * (1.0f / 255.0f);
    LODs[prevLOD].Draw(renderContext, info, normalizedProgress);
    LODs[lodIndex].Draw(renderContext, info, normalizedProgress - 1.0f);
}

绘制

bool SkinnedModel::Init(const Span<int32>& meshesCountPerLod)
{
    if (meshesCountPerLod.IsInvalid() || meshesCountPerLod.Length() > MODEL_MAX_LODS)
    {
        Log::ArgumentOutOfRangeException();
        return true;
    }

    // Dispose previous data and disable streaming (will start data uploading tasks manually)
    StopStreaming();

    // Setup
    MaterialSlots.Resize(1);
    MinScreenSize = 0.0f;

    // Setup LODs
    for (int32 lodIndex = 0; lodIndex < LODs.Count(); lodIndex++)
    {
        LODs[lodIndex].Dispose();
    }
    LODs.Resize(meshesCountPerLod.Length());
    _loadedLODs = meshesCountPerLod.Length();

    // Setup meshes
    for (int32 lodIndex = 0; lodIndex < meshesCountPerLod.Length(); lodIndex++)
    {
        auto& lod = LODs[lodIndex];
        lod._model = this;
        lod.ScreenSize = 1.0f;
        const int32 meshesCount = meshesCountPerLod[lodIndex];
        if (meshesCount <= 0 || meshesCount > MODEL_MAX_MESHES)
            return true;

        lod.Meshes.Resize(meshesCount);
        for (int32 meshIndex = 0; meshIndex < meshesCount; meshIndex++)
        {
            lod.Meshes[meshIndex].Init(this, lodIndex, meshIndex, 0, BoundingBox::Zero, BoundingSphere::Empty);
        }
    }

    return false;
}

模型的初始化

Class VisualScript

可视化脚本 ,包含一个图表、用于可视化脚本的函数和参数。

构造器不谈。

Properties:

Meta

脚本元数据。类型是一个Metadata。跳过去看一下。

结构体:VisualScript Metadata

Fields

BaseTypename 基类名,string类型。

Flags 脚本标志,类型是flag。

枚举 Flags

Fields:

Abstract 脚本是抽象的,不能被直接初始化

None 无标志

Sealed 脚本是密封的,不能被继承

Parameters

获取在此图形中声明的 visualscript 参数列表(不包括基类型)。类型是VisjectGraphParameter的数组。

Class VisjectGraphParameter

可视对象图参数。继承了GraphParameter,没有任何新添加的东西。所以我们再看基类。

Class GraphParameter

表示图形中的参数。

Properties

Identifier

参数的唯一ID  类型是Guid

IsPublic

是否被暴露在外,一个布尔值。

Name

名字。String。

Type

类型,Type类型。

TypeTypename

获取参数类型的类型名(不包括生成类型)。

Value

参数值,类型是Object。什么都行。

Methods

Getmetadata(int32)

获取分配给此参数的 Visject Meta 条目的数据。返回字节流。

ScriptTypeName

获取可视脚本的类型名。标识其脚本类型。String类型。

Methods

CreateInstance()

创建新的可视脚本实例

GetMetaData(Int32)

拿到元数据。

GetMethodMetaData(Int32, Int32)

拿到元数据。多一个参数是index

GetMethodsCount

返回脚本中方法的数量 int32类型。

GetMethodSignature(Int32, out String, out Byte, out String, out String[], out String[], out Boolean[])

拿到方法的签名。

参数列在下面:

Index int32

Name string

Flags byte

ReturnTypeName string

ParamNames string[]

paramTypeNames string[]

ParamOuts Boolean[]

GetScriptInstanceParameterValue(String, Object)

获取给定实例的 visualscript 参数的值。

参数,一个名字,string类型,一个instance,Object

返回值Object。

LoadSurface()

加载表面图。加载成功就返回字节流。

SaveSurface(Byte[], ref VisualScript.Metadata)

更新图表面(保存新图表面、丢弃缓存的数据、重载)。

SetScriptInstanceParameterValue(String, Object, Object)

设置给定实例的 visualscript 参数的值。

class VisualScriptExecutor : public VisjectExecutor
{
    friend VisualScripting;
public:

    /// <summary>
    /// Initializes a new instance of the <see cref="VisualScriptExecutor"/> class.
    /// </summary>
    VisualScriptExecutor();

    void Invoke(const Guid& scriptId, int32 nodeId, int32 boxId, const Guid& instanceId, Variant& result) const;

private:
    void OnError(Node* node, Box* box, const StringView& message) override;
    Value eatBox(Node* caller, Box* box) override;
    Graph* GetCurrentGraph() const override;

    void ProcessGroupParameters(Box* box, Node* node, Value& value);
    void ProcessGroupTools(Box* box, Node* node, Value& value);
    void ProcessGroupFunction(Box* boxBase, Node* node, Value& value);
    void ProcessGroupFlow(Box* boxBase, Node* node, Value& value);
};

struct VisualScriptThread
{
    uint32 StackFramesCount;
    VisualScripting::StackFrame* Stack;
};

首先,需要将数据转换成pandas的DataFrame格式,代码如下: ```python import pandas as pd data = {'日期/项目(A厂)': ['2021.1.1', '2021.1.2', '2021.1.3', '2021.1.4', '2021.1.5', '2021.1.6', '2021.1.7', '2021.1.8', '2021.1.9', '2021.1.10', '2021.1.11', '2021.1.12', '2021.1.13', '2021.1.14', '2021.1.15', '2021.1.16', '2021.1.17', '2021.1.18', '2021.1.19', '2021.1.20', '2021.1.21', '2021.1.22', '2021.1.23', '2021.1.24', '2021.1.25', '2021.1.26', '2021.1.27', '2021.1.28', '2021.1.29', '2021.1.30', '2021.1.31'], '进水': [149, 164, 86, 164, 146, 136, 93, 96, 90, 134, 141, None, None, None, 138, 138, 161, None, None, None, None, None, None, None, None, None, 114, 107, 121, None, None], 'COD': [20.1, 10.1, 37.1, 16.4, 10.9, 18.7, 17.2, 17.1, 18.5, 23.8, 17.7, 15.6, 11.0, 19.5, 18.5, 15.2, 16.5, 16.3, 17.3, 29.5, 20.7, 19.5, 18.9, 12.0, 23.9, 11.7, 10.6, 11.1, 14.2, 10.6, 12.5], '氨氮': [3.54, 0.65, 1.92, 1.44, 0.84, 1.59, 1.15, 1.61, 1.42, 2.46, 2.50, 1.48, 1.04, 3.55, 1.60, 1.82, 2.60, 2.10, 1.54, 3.54, 2.67, 3.25, 2.12, 2.38, 2.34, 1.51, 1.58, 1.31, 1.66, 1.26, 1.71], '总磷': [30.7, 20.1, 44.1, 21.5, 18.4, 29.7, 23.5, 24.2, 26.9, 31.7, 28.3, None, None, 24.0, 26.9, 27.8, 20.5, 27.9, 31.8, 37.8, 24.9, 29.3, None, 23.4, 23.5, 12.4, 27.9, 19.3, 17.6, 19.5, 15.4]} df = pd.DataFrame(data) ``` 接下来,我们可以使用matplotlib库进行数据可视化,这里我选择绘制折线图。代码如下: ```python import matplotlib.pyplot as plt # 设置图形大小 plt.figure(figsize=(10, 6)) # 绘制折线图 plt.plot(df['日期/项目(A厂)'], df['进水'], label='进水') plt.plot(df['日期/项目(A厂)'], df['COD'], label='COD') plt.plot(df['日期/项目(A厂)'], df['氨氮'], label='氨氮') plt.plot(df['日期/项目(A厂)'], df['总磷'], label='总磷') # 添加标题和标签 plt.title('A厂水质监测', fontsize=16) plt.xlabel('日期', fontsize=12) plt.ylabel('含量', fontsize=12) # 添加图例 plt.legend() # 显示图形 plt.show() ``` 运行上述代码,即可得到一张含有4条曲线的折线图,用于展示A厂水质监测数据的趋势。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值