1.0.6 • Published 2 years ago

plant-td v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

使用plant-td

引入

const Plant = require("plant-td");

创建一个场景

const plant = new Plant({
  width: 1920,                      // 宽度
  height: 1080,                     // 高度
  align: "center",                  // 位置["center", "top-left", "top-right", "bottom-left", "bottom-right"]
  backgroundColor: 0xffffff,        // 背景颜色
  camera: [2160, 1080, 0],          // 主相机位置
  AxesHelper: 250                   // 坐标系
});

挂载场景

const container = document.getElementById("#container");
plant.mount(container);
// plant.compass(compassEl);        // 挂载指南针
// plant.describe(describeEl);      // 挂载描述标签

添加对象

使用颜色材质添加一个对象

plant.add({
  name: "createdByColor",           // name属性[作用相当于类名]
  geometry: "BoxGeometry",          // 对象类型,见threejs官网
  size: [600, 600, 600],            // 对象大小
  pos: [0, 0, 0],                   // 对象位置
  material: {                       // 对象材质
    color: 0x0000ff,
  },
  rx: 0,                            // rotateX
  ry: 0,
  rz: 0,
  data: {}                          // 用户自定义数据
});

使用图像材质创建一个对象

plant.add({
  name: "createByImage",
  material: {                       // 使用绝对地址或网络地址、暂时不支持使用相对地址
    image: "/public/image/demo.png"
  }
})

使用模型材质创建一个对象

plant.add({
  name: "createByModel",
  material: {                       // 会注册进模型加载队列,当模型加载完成之后才创建
    model: "demo"
  }
})

注册模型

plant.load([                        // 使用该目录下index.obj加载模型、index.mtl加载材质
  {
    name: "demo",
    path: "/public/model/demo"
  }
])

查找对象

plant.find(name)                    // 创建时添加的name属性,name可使用数组

删除对象

plant.remove(object)

改变对象材质(不可逆)

plant.skin(material)                // 材质格式同上

激活对象

plant.active(material)              // 会注册进修改历史、可复原

复原历史修改

plant.restore()                     // 复原历史材质修改
1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago