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

three-css-layout

v0.1.1

Published

Three CSS Layout

Downloads

17

Readme

Overview

TLDR - Three CSS Layout will fit any Object3D inside an animated <div />.

Demo1Demo2jsFiddleWiki

Three CSS Layout aim to simplify the positioning, scaling and rotation of three.js objects relative to an HTML layout. Consists of two classes, the parent layout CSSLayout and its child objects CSSLayoutObject. The combination of these two classes allow you to take advantage of the HTML structure and emulate CSS responsiveness, transitions, keyframe animations and scroll inside a three.js environment.

Getting Started

Installation

You can include three-css-layout in your project by installing it using npm:

npm install three-css-layout

Usage

  1. Initialize the parent CSSLayout:

    import { CSSLayout } from "three-css-layout";
    
    const cssLayout = new CSSLayout("#layout");
  2. Create your CSSLayoutObject child objects:

    import { CSSLayoutObject } from "three-css-layout";
    
    // First object
    const cssLayoutObject1 = new CSSLayoutObject("#three-model-1");
    cssLayoutObject1.add(my3DModel);
    
    // Second object
    const cssLayoutObject2 = new CSSLayoutObject("#three-group");
    cssLayoutObject2.add(myGroup);
    
    // ...
    
    // Add all your objects to the parent CSSLayout
    cssLayout.add(cssLayoutObject1, cssLayoutObject2);
  3. Fit Camera or Plane:

    // Fit the camera viewport
    const camera = new THREE.PerspectiveCamera(
      75,
      window.innerWidth / window.innerHeight,
      0.1,
      1000
    );
    cssLayout.fitCamera(camera, "cover");
    cssLayout.scroll();
    
    // OR
    
    // Fit a plane
    cssLayout.fitPlane(10, 5);
  4. Fit on window resize

    For a 3D responsive design

    function onWindowResize() {
     ...
    
     cssLayoutObject.fitCamera(camera, "cover");
    }
  5. Fit in the animation loop
    If you have a css animation or transitions, you can cam update the CSSLayout child objects in the animation loop.

    function animation() {
     ...
    
     cssLayout.updateObjects();
    
     renderer.render(scene, camera);
    }

Limitation

Three CSS Layout has the following considerations for optimal performance:

  • Animation Constraints:

    • The library may encounter limitations when handling CSS animations involving the transform property combined with other CSS properties. To ensure optimal performance, consider utilizing either transform in isolation or alternative approaches for animations.
  • Dynamic Element Changes:

    • For optimal performance, the library does not automatically recompute the clientBoundingBox when the dimensions (width, height...) or position (top, left, margin, etc.) of the HTML element change. To reflect these changes, you need to set elementNeedsUpdate to true. (This limitation does not apply to any css transform change).

    • Similarly, if the Object3D associated with the layout undergoes changes, set objectNeedsUpdate o true to reflect the changes.

Contributing

Contributions are welcome! Fork the repository, make your changes, and submit a pull request.

License

Licensed under the MIT License.

Acknowledgments

Special thanks to the three.js community for inspiration and support.


Feel free to use, modify, and enhance Three CSS Layout to suit your needs. Happy coding!