npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@easytwin/engine

v0.50.9

Published

- [engine 核心](./src/engine/) - [测试页面](./src/page/) - [增加组件](#在引擎中新增组件component) - [引擎绘制模块](#使用引擎的draw-模块)

Downloads

6

Readme

EasyTwin Engine

引擎代码

使用引擎的 draw 模块

// 设置对应的绘制模式
world.drawUtils.mode = 'multi-rect';
// 设置为那个组件做绘制, 这里会触发与前端的交互,通知前端xxx组件的绘制状态
world.drawUtils.setActiveComponent(this);
// 设置绘制组件需要的 绘制点的根节点
world.drawUtils.showDrawPoint(this.group);
// 同上
world.drawUtils.showDrawMoveRect(this.group);

world.drawUtils.startDraw();

在引擎中新增组件(Component)

// 在改文件中全局替换Template 为你想要的组件名字
export const TemplateComponentType = 'Template';

EasyTwinComponentTypeMap

  • 这个 map 是用于判断所属组件是属于哪一种类型
  • 前 8 代表某种类型, 后 8 单边具体对应
  • 可以出现控制辅助器的类型为 1

getEntityArchetype

// 函数的返回是有顺序的, 按照你期望的顺序加入函数的返回序列中
if (entity.getComponentByType('Model')) return 'Model';

isEntityDigital

// 函数用于判断该实体是否属于数字要素的一种
if (entity.isEntityDigital(entity: EngineEntity)) return boolean;

组件可以被控制器依附

switch (this.type) {
  case 'XXX':
}
// 在switch 中加入你新增的组件类型

getObjectById

  getObjectById(id: string) {
    // 返回你想要返回给选中模块的物体, 一般选中会通过子mesh 的id,来寻找你需要返回出的组件子实体
    return this.group;
  }

组件拖动完成

onDragEnd(): void
// 在选中模块中, 拖动组件会触发组件的 onDragEnd 函数,在这里你可以更新 组件中的位置等属性

setVisible

// 如果没有特别的实现, 通用实现就是控制 组件下的group 的children 的某一个子的显示隐藏, 如果uuid 为空就直接设置group的显隐
setVisible(visible: boolean, uuid?: string): void

在引擎中实现对于 dom 元素的选中

// 在可以被选中的dom对象添加数据元素 它自身的id, 所属实体的id, 所属组件的id
clickDom.dataset.id = id;
clickDom.dataset.entityId = entityId;
clickDom.dataset.componentId = componentId;

// 在选中模块中, 将通过ev.target 来直接获取组件id, 来判断是否点中
const componentId = target.getAttribute('data-component-id');
const objectId = target.getAttribute('data-id');

custom attribute

为了能在数字要素传出自定义属性 如果数字要素含有多个子,就在子的 data 数据中加上 customAttribute 字段 不然就放在最外层

removeObjectById

  public removeObjectById(id: string): void {
    const object = this.getObjectById(id);
    if (object) {
      const child = this.childMap.get(object.uuid);
      this.childMap.delete(object.uuid);
      child && child.dispose();
      child && this.group.remove(child);

      this.needDataUpdateServer = true;
    }
  }

setVisible


  // 以poi panel v2为例
  public setVisible(visible: boolean): PoiPanelV2Component {
    const getExtendVisible = (object: Object3D, visible: boolean): boolean => {
      if (object.parent) {
        return getExtendVisible(object.parent, object.parent.visible && visible);
      } else {
        return visible;
      }
    };

    const extendVisible = getExtendVisible(this.group, this.group.visible);

    this.childMap.forEach((child) => {
      child.setVisible(visible && extendVisible);
    });

    return this;
  }
  //在新增的组件中实现 设置显隐的方法, 并在load 该组件的函数中增加对于它显隐的控制调用
    public loadPoiPanelV2Component(
    world: World,
    entity: EngineEntity,
    options: ComponentOptions,
    isAdded: boolean = false,
  ): PoiPanelV2Component {
    const { type, id, name, states } = options;
    const component = entity.addComponent<PoiPanelV2Component>(
      id,
      name ?? '',
      PoiPanelV2Component,
      isAdded,
    );

    ......

    component.setVisible(entity.visible);

    .....

    return component;
  }