[softxels](https://github.com/danielesteban/softxels/)
[![npm-version](https://img.shields.io/npm/v/softxels.svg)](https://www.npmjs.com/package/softxels)
==
[![screenshot](screenshot.png)](https://github.com/danielesteban/softxels)
### Examples
* Editable world:
* Demo (cave worldgen): [https://softxels.gatunes.com/#/cave](https://softxels.gatunes.com/#/cave)
* Demo (terrain worldgen): [https://softxels.gatunes.com/#/terrain](https://softxels.gatunes.com/#/terrain)
* Demo (cave worldgen with persistence): [https://softxels.gatunes.com/#/cave/persist](https://softxels.gatunes.com/#/cave/persist)
* Demo (terrain worldgen with persistence): [https://softxels.gatunes.com/#/terrain/persist](https://softxels.gatunes.com/#/terrain/persist)
* Source: [example/main.js](example/main.js)
* Random walkers:
* Demo: [https://softxels-walker.glitch.me](https://softxels-walker.glitch.me)
* Source: [https://glitch.com/edit/#!/softxels-walker](https://glitch.com/edit/#!/softxels-walker)
* Demo (react-three-fiber): [https://04s6kb.csb.app](https://04s6kb.csb.app)
* Source (react-three-fiber): [https://codesandbox.io/s/softxels-04s6kb](https://codesandbox.io/s/softxels-04s6kb)
* Studio:
* Demo: [https://softxels-studio.gatunes.com](https://softxels-studio.gatunes.com)
* Source: [https://github.com/danielesteban/softxels-studio](https://github.com/danielesteban/softxels-studio)
* Viewer:
* Demo: [https://softxels-viewer.gatunes.com](https://softxels-viewer.gatunes.com)
* Source: [https://github.com/danielesteban/softxels-viewer](https://github.com/danielesteban/softxels-viewer)
* VR sculpting:
* Demo [https://softxels-xr.glitch.me](https://softxels-xr.glitch.me)
* Source: [https://glitch.com/edit/#!/softxels-xr](https://glitch.com/edit/#!/softxels-xr)
### Installation
```bash
npm install softxels
```
### Basic usage
```js
import World, { WorldGen } from 'softxels';
import { PerspectiveCamera, Scene, sRGBEncoding, WebGLRenderer } from 'three';
const aspect = window.innerWidth / window.innerHeight;
const camera = new PerspectiveCamera(70, aspect, 0.1, 1000);
const renderer = new WebGLRenderer({ antialias: true });
renderer.outputEncoding = sRGBEncoding;
renderer.setSize(window.innerWidth, window.innerHeight);
const scene = new Scene();
const world = new World(WorldGen());
scene.add(world);
renderer.setAnimationLoop(() => {
world.updateChunks(camera.position);
renderer.render(scene, camera);
});
```
### World constructor
```js
new World({
chunkMaterial: MeshBasicMaterial({ // A ThreeJS Material instance to render all chunks (default: null)
vertexColors: true,
}),
chunkSize: 32, // An uInt8 that controls the data/render chunks size (default: 32)
renderRadius: 5, // Controls the chunk radius updateChunks loads around the anchor (default: 5)
storage: { // An optional interface to load/store the chunk data
saveInterval: 5000, // The minimum time in between chunk saves in ms (default: 0)
async get(key), // An arbitrary async function that receives a chunk key and resolves the chunk data
set(key, value), // An arbitrary function that receives a chunk key and the data to be stored
},
});
```
### WorldGen constructor
```js
new WorldGen({
generator: null, // 'cave', 'terrain' or null to disable it (default: null)
seed: 1337, // A uInt32 seed to drive the world generation noise (default: Random)
});
```
### updateChunks
```js
// This will load all the chunks around the anchor in the selected renderRadius
// passed to the constructor.
// It will also unload all the chunks further away (renderRadius + 2).
// You should call this everytime you move the anchor.
// It does remember the last chunk the anchor was in, so... It will only
// update when the anchor crosses a chunk boundary.
const anchor = new Vector3(1, 2, 3);
world.updateChunks(anchor);
```
### updateVolume
```js
world.updateVolume(
new Vector3(1, 2, 3), // A point in worldspace
2, // A uInt8 radius to update around the point
0xFF, // A uInt8 scalar where:
// 0 === OUTSIDE
// 0X80 === AT ISOSURFACE
// 0xFF === INSIDE
{ r: 0x11, g: 0x22, b: 0x33 } // An optional 24bit sRGB color
);
```
### Modifying the WASM programs
To build the C code, you'll need to install LLVM:
* Win: [https://chocolatey.org/packages/llvm](https://chocolatey.org/packages/llvm)
* Mac: [https://formulae.brew.sh/formula/llvm](https://formulae.brew.sh/formula/llvm)
* Linux: [https://releases.llvm.org/download.html](https://releases.llvm.org/download.html)
On the first build, it will complain about a missing file that you can get here:
[libclang_rt.builtins-wasm32-wasi-16.0.tar.gz](https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/libclang_rt.builtins-wasm32-wasi-16.0.tar.gz). Just put it on the same path that the error specifies and you should be good to go.
To build [wasi-libc](https://github.com/WebAssembly/wasi-libc), you'll need to install [GNU make](https://chocolatey.org/packages/make)
```bash
# clone this repo and it's submodules
git clone --recursive https://github.com/danielesteban/softxels.git
cd softxels
# build wasi-libc
cd vendor/wasi-libc && make -j8 && cd ../..
# install dev dependencies
npm install
# start the dev environment:
npm start
# open http://localhost:8080/ in your browser
```
没有合适的资源?快使用搜索试试~ 我知道了~
js构建三维体,GitHub项目
共42个文件
js:14个
json:5个
ogg:3个
需积分: 0 0 下载量 142 浏览量
2023-06-09
16:49:06
上传
评论
收藏 19.94MB ZIP 举报
温馨提示
js构建三维体,GitHub项目https://github.com/danielesteban/softxels 有时候不好下载,搬来放下
资源推荐
资源详情
资源评论
收起资源包目录
softxels-master.zip (42个子文件)
softxels-master
.github
workflows
gh-pages.yml 457B
FUNDING.yml 22B
src
core
worker.js 2KB
program.js 692B
chunk.js 1KB
worldgen.js 401B
module.js 102B
world.js 12KB
workers
compile.sh 241B
mesher.js 1KB
worldgen.js 985B
worldgen.wasm 12KB
mesher.c 23KB
worldgen.c 2KB
mesher.wasm 41KB
LICENSE 1KB
screenshot.png 1.14MB
package.json 1KB
vendor
wasi-libc
FastNoiseLite
rollup.config.js 1KB
package-lock.json 193KB
.gitmodules 219B
.gitignore 18B
example
sounds
ambient.ogg 313KB
underwater.ogg 470KB
plop.ogg 5KB
main.js 6KB
screenshot.png 673KB
package.json 529B
core
fish.js 6KB
player.js 7KB
renderer.js 3KB
rollup.config.js 1KB
package-lock.json 79KB
index.html 2KB
models
fish.glb 5.49MB
barramundi.glb 11.94MB
index.css 3KB
README.md 5KB
voxelizer
module.mjs 5KB
package.json 322B
cli.mjs 5KB
README.md 3KB
共 42 条
- 1
资源评论
cwr888
- 粉丝: 494
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功