Coder Social home page Coder Social logo

ehtick / threejs-slice-geometry-typescript Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ikaroskappler/threejs-slice-geometry-typescript

0.0 0.0 0.0 508 KB

Slice three.js geometry with a plane.

Home Page: https://tdhooper.github.io/threejs-slice-geometry/examples

License: MIT License

JavaScript 6.67% TypeScript 93.33%

threejs-slice-geometry-typescript's Introduction

threejs-slice-geometry TypeScript port

This is a TypeScript port of the library threejs-slice-geometry.

Thanks to tdhooper for the awesome JavaScript implementation!

TypeScript port by Ikaros Kappler.

Three.js Slice Geometry

Slice three.js geometry with a plane.

Usage

Javascript

var plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
var geom = new THREE.BoxGeometry(1, 1, 1);
// The result will be a Gmetry instance and cannot be added to a three scene
geom = sliceGeometry(Gmetry.fromBufferGeometry(geom), plane); // This is new
var material = new THREE.MeshBasicMaterial({ wireframe: true });
// Call .toBufferGeometry here to go back to threejs
var mesh = new THREE.Mesh(geom.toBufferGeometry(), material);
scene.add(mesh);

Typescript

import { sliceGeometry } from "threejs-slice-geometry-typescript";

const plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
const geomBufferGeometry = new THREE.BoxGeometry(1, 1, 1);
// The result will be a Gmetry instance and cannot be added to a three scene
const geom = sliceGeometry(Gmetry.fromBufferGeometry(geomBufferGeometry), plane); // This is new
const material = new THREE.MeshBasicMaterial({ wireframe: true });
// Call .toBufferGeometry here to go back to threejs
const mesh = new THREE.Mesh(geom.toBufferGeometry(), material);
scene.add(mesh);

Compatibility with old THREEJS versions

Since threejs r125 the THREE.Geometry class no longer exist (deprecated, will be removed in the future). See https://discourse.threejs.org/t/three-geometry-will-be-removed-from-core-with-r125/22401

I used a replacement class here from the ThreeGreometryHellfix.Gmetry repository. It is acually based on the code of the old Geometry class and still works, but you should think about using THREE.BufferGeometry in the future. Read about the pros and cons here https://github.com/IkarosKappler/three-geometry-hellfix

Typescript (with threesjs <= r124)

import { sliceGeometry } from "threejs-slice-geometry-typescript";

const plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
const geom = new THREE.BoxGeometry(1, 1, 1);
geom = sliceGeometry(geom, plane);
const material = new THREE.MeshBasicMaterial({ wireframe: true });
const mesh = new THREE.Mesh(geom, material);
scene.add(mesh);

Javascript (with threesjs <= r124)

var plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
var geom = new THREE.BoxGeometry(1, 1, 1);
geom = sliceGeometry(geom, plane);
var material = new THREE.MeshBasicMaterial({ wireframe: true });
var mesh = new THREE.Mesh(geom, material);
scene.add(mesh);

Builds

CJS builds from typescript

Original JS builds:

Examples

https://tdhooper.github.io/threejs-slice-geometry/examples

threejs-slice-geometry-typescript's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.