Coder Social home page Coder Social logo

model-to-svg's Introduction

model-to-svg

Three.js We have input properties:

// some json file
{
 data: {
  camera: {
   fov: number,
   position: Vec3,
   lookAt: Vec3
  },
  unitLabels: [
   {
    name: string,
    origin: Vec3,
    vertices: [Vec3, Vec3, Vec3, Vec3],
    normal: Vec3
   }
  ]
 }
}

Perspective camera and scene

So, above all, we need to set up perspective camera and create scene using library Three.js:

const data = data;
const scene = new THREE.Scene();

const camera = new THREE.PerspectiveCamera(data.camera.fov, innerWidth/innerHeight, ...);
camera.position.set(data.camera.pos);
camera.lookAt.set(data.camera.lookAt);

Text and figure geometry

In the same way, we can apply a transformation to all planes and perspective transformation to them. For example, we have more than one plane

for (let i = 0; i < 2; i++) {
  const planeGeometry= new THREE.PlaneGeometry(data.unitLabels[...].vertices);
  const planeMaterial= new THREE.MeshBasicMaterial({...});
  const planeMesh = new THREE.Mesh( planeGeometry, planeMaterial );

  scene.add(planeMesh);

  // Text
  const loader = new THREE.FontLoader();

  loader.load('someFont.json', function(font) {
   const textGeometry = new THREE.TextGeometry(data.unitLabels[...].name, {...});
   textGeometry.center();

   const textMaterial = new THREE.MeshBasicMaterial({...});
   const textMesh = new THREE.Mesh( textGeometry, textMaterial );

   textMesh.position.set(x, y, z);
   scene.add(textMesh);
  });
}

By the way, we can improve the display of the font by perspective camera transformation to each point of symbols defined as svg path. When applying Vector3(x, y, z).project(camera) we will get letters as the output.

Convert to SVG

Now we able to do the final step. Fortunately, the library Three.js has a lot of renderers including SVGRenderer. So, we use it and receive our goal.

model-to-svg's People

Contributors

ewelai avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.