Initial commit

This commit is contained in:
Ad5001 2023-02-27 01:26:17 +01:00
commit 716a818e42
Signed by: Ad5001
GPG Key ID: EF45F9C6AFE20160
16 changed files with 991 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.css.map
*.css

157
LICENSE.md Normal file
View File

@ -0,0 +1,157 @@
### GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
<https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates the
terms and conditions of version 3 of the GNU General Public License,
supplemented by the additional permissions listed below.
#### 0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the
GNU General Public License.
"The Library" refers to a covered work governed by this License, other
than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
#### 1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
#### 2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
- a) under this License, provided that you make a good faith effort
to ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
- b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
#### 3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from a
header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
- a) Give prominent notice with each copy of the object code that
the Library is used in it and that the Library and its use are
covered by this License.
- b) Accompany the object code with a copy of the GNU GPL and this
license document.
#### 4. Combined Works.
You may convey a Combined Work under terms of your choice that, taken
together, effectively do not restrict modification of the portions of
the Library contained in the Combined Work and reverse engineering for
debugging such modifications, if you also do each of the following:
- a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
- b) Accompany the Combined Work with a copy of the GNU GPL and this
license document.
- c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
- d) Do one of the following:
- 0) Convey the Minimal Corresponding Source under the terms of
this License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
- 1) Use a suitable shared library mechanism for linking with
the Library. A suitable mechanism is one that (a) uses at run
time a copy of the Library already present on the user's
computer system, and (b) will operate properly with a modified
version of the Library that is interface-compatible with the
Linked Version.
- e) Provide Installation Information, but only if you would
otherwise be required to provide such information under section 6
of the GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the Application
with a modified version of the Linked Version. (If you use option
4d0, the Installation Information must accompany the Minimal
Corresponding Source and Corresponding Application Code. If you
use option 4d1, you must provide the Installation Information in
the manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.)
#### 5. Combined Libraries.
You may place library facilities that are a work based on the Library
side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
- a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities, conveyed under the terms of this License.
- b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
#### 6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
as you received it specifies that a certain numbered version of the
GNU Lesser General Public License "or any later version" applies to
it, you have the option of following the terms and conditions either
of that published version or of any later version published by the
Free Software Foundation. If the Library as you received it does not
specify a version number of the GNU Lesser General Public License, you
may choose any version of the GNU Lesser General Public License ever
published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

343
README.md Normal file
View File

@ -0,0 +1,343 @@
# enecss
(or backwards, sscene)
A CSS library to facilitate the creation of low-poly 3D scenes using only CSS.
---
## Building
Use [Sass](https://sass-lang.com/) to build enecss...
```bash
sass src/main.scss main.css
```
...or include it into your own builds.
```sass
@import "enecss/src/main.scss";
```
## Using
### Creating the scene
Once you've included enecss into your HTML file, you can declare a scene and a root node in HTML using the following:
```html
<section class="scene">
<figure class="root" style='--width: 400px; --height: 400px;'>
</figure>
</section>
```
The 2D size of the scene is provided in the `--width` and `--height` variables. The default depth is `600px`, and is currently hardcoded.
**Note**: This guide will make extensive use of inline styling for ease of use and easy representability. If your context does not allow you to use this tool, you can just declare an ID to every node and port those styles to a stylesheet.
**Note**: A `section` is not mandatory for the scene node. However, the `figure` node is necessary for every object element you want to create.
### Creating objects
There are a few basic objects. All parameters of the objects will be specified in CSS variables (which, as mentioned previously, can be set either inline or via a stylesheet).
1. The basic mesh
This is the most basic element in the list, a rectangle. It doesn't even need to be a `figure`, and can take a single texture, which will be reproduced on both its sides.
Example: A white rectangle with a black outline.
```html
<div style="width: 500px; height: 500px; background: white; outline: solid 1px black;"></div>
```
Other objects are often composed of basic meshes, to which you can style and use like any other HTML element (See [Manipulating meshes](#Manipulating-meshes))
2. Axises
Object transformations are relative to their own position and rotation. If you're having trouble figuring out which way is which, you can use the `axises` object.
You can declare one using a `figure` with the `axises` class. A plane has four optional parameters like `--width` and `--height` for its two dimentions, and `--length` and `--length2` for the dimensions of the axis themselves.
Code to add axises:
```html
<figure class="axises">
<div class="axis axis-x">x</div>
<div class="axis axis-y">y</div>
<div class="axis axis-z">z</div>
</figure>
```
3. Plane
The biggest problem of the basic mesh is that the texture is reproduced on both sides. A plane allows for one texture on each side by superposing two basic meshes.
You can declare a plane by using a `figure` with the `plane` class. A plane has two parameters `--width` and `--height` for its two dimentions.
Example: A dual textured plane.
```html
<figure class="plane" style='--width: 100px; --height: 200px;'>
<img class="face front" src="side1.png" />
<img class="face back " src="side2.png" />
</figure>
```
4. Cube
Cubes are, well, cubes. It uses six square basic meshes to create one cube.
You can declare a plane by using a `figure` with the `cube` class. A plane has one parameter: `--size` for its verticle size.
Example: A cube with a texture on the front.
```html
<figure class="cube" style='--size: 200px;'>
<img class="face front " src="side1.png" />
<div class="face back "></div>
<div class="face right "></div>
<div class="face left "></div>
<div class="face top "></div>
<div class="face bottom"></div>
</figure>
```
5. Cuboid Rectangular
They're like cubes, but with different dimensions for every side.
You can declare one by using a `figure` with the `cuboid rectangular` classes. It has has three parameter:
- `--width` for its horizontal (x) size.
- `--length` for its vertical (y) size.
- `--depth` for its (z) size.
Example: A simple white cuboid rectangular with outlined verticles.
```html
<figure class="cuboid rectangular" style='--length: 7px; --width: 10px; --depth: 20px;'>
<div class="face front " style="outline: solid 1px black;"></div>
<div class="face back " style="outline: solid 1px black;"></div>
<div class="face left " style="outline: solid 1px black;"></div>
<div class="face right " style="outline: solid 1px black;"></div>
<div class="face top " style="outline: solid 1px black;"></div>
<div class="face bottom" style="outline: solid 1px black;"></div>
</figure>
```
6. Cylinder
Cylinders in this framework work by using several simple meshes to make it an n-sides prism.
You can declare one by using a `figure` with the `cylinder` classes. It has has three parameter:
- `--radius` for the radius of the base.
- `--height` for its vertical (y) size.
- `--strip-count` Number of stripes to use (24 by default, 90 max).
You can have the cylinder textured by adding the `textured` class, and linking an image in the `--texture` variable. Enecss will fill the stripes with the texture from left to right.
Example: A textured cylinder.
```html
<figure class="cylinder textured" style='--height: 170px; --radius: 18px; --strip-count: 24; --texture: url(/texture.png);'>
<div class="strip strip-1"></div>
<div class="strip strip-2"></div>
<div class="strip strip-3"></div>
<div class="strip strip-4"></div>
<div class="strip strip-5"></div>
<div class="strip strip-6"></div>
<div class="strip strip-7"></div>
<div class="strip strip-8"></div>
<div class="strip strip-9"></div>
<div class="strip strip-10"></div>
<div class="strip strip-11"></div>
<div class="strip strip-12"></div>
<div class="strip strip-13"></div>
<div class="strip strip-14"></div>
<div class="strip strip-15"></div>
<div class="strip strip-16"></div>
<div class="strip strip-17"></div>
<div class="strip strip-18"></div>
<div class="strip strip-19"></div>
<div class="strip strip-20"></div>
<div class="strip strip-21"></div>
<div class="strip strip-22"></div>
<div class="strip strip-23"></div>
<div class="strip strip-24"></div>
</figure>
```
**Note regarding editing objects**: I recommend using your web browser's dev tools to edit elements, then save the copy back the modified HTML from there.
### Parenting objects
When you use several objects, you can 'parent' them to one another (just like you would in any 3D editor), in the same way you would parent any node in HTML.
```html
<figure id="parent" style='transform: rotateY(30deg);'>
<figure id="child" class="cube position-at-center" style='--size: 100px;'>
<div class="face front " style="background: white;"></div>
<div class="face back " style="background: white;"></div>
<div class="face right " style="background: white;"></div>
<div class="face left " style="background: white;"></div>
<div class="face top " style="background: white;"></div>
<div class="face bottom" style="background: white;"></div>
</figure>
</figure>
```
All the transformations of the parent will be applied to the child, which means in this case, the cube will be rotated 30° on the Y axis.
**Note**: The `position-at-center` class allow for objects that do NOT have applied transform to position themselves at the center of their parents. The same result can be achieved by prepending `translateX(-50%) translateY(-50%)` to the object's transform.
### Manipulating mesh
Every lowest level node is a 3D 'mesh' (a rectangular plane object, in this case). It is important to note that you can use *any* html element as a mesh.
- `div` will not provide anything by default
- `a` will make a 3D clickable link or state switcher (more on that later)
- `button` will allow for a clickable surface with a temporary state (more on that later)
- `img` will make for a texturable surface.
- `video` can make a 3D video player (no performance waranty though)
And best of all! They can be nested!
For example...
```html
<div class="face front">
<img class="fill" src="texture.png"/>
<a class="fill" href="#state1"></a>
</div>
```
... is a clickable textured element.
If you want to hide even a single mesh, you can use the `hidden` class, or even better.
If you're not sure where a specific mesh is, you can add the `debug` class to it, which will add a red outline to the mesh.
### Basic interactivity
If you want to be able to rotate the object around using your mouse, you can add view sections nodes *on the same level as the scene node, just before it*.
```html
<div class="view-section view-top-0 view-left-0"></div>
<div class="view-section view-top-0 view-left-1"></div>
<div class="view-section view-top-0 view-left-2"></div>
<div class="view-section view-top-0 view-left-3"></div>
<div class="view-section view-top-0 view-left-4"></div>
<div class="view-section view-top-0 view-left-5"></div>
<div class="view-section view-top-0 view-left-6"></div>
<div class="view-section view-top-0 view-left-7"></div>
<div class="view-section view-top-0 view-left-8"></div>
<div class="view-section view-top-1 view-left-0"></div>
<div class="view-section view-top-1 view-left-1"></div>
<div class="view-section view-top-1 view-left-2"></div>
<div class="view-section view-top-1 view-left-3"></div>
...
<div class="view-section view-top-8 view-left-8"></div>
```
This divides the screen in 81 sections to allow for gradual rotation from the center of the scene.
### Advanced interactivity: States
'States' is the most advanced feature you can use to save interaction data in CSS. It's possible to use the location hashmap to save a current state which, best of all, can stay registered even if the user erases his cookies.
Though only one state can be detected at the time, it's possible to create multiple CSS variables that vary depending on the state.
#### Registering a new state
First of all, to register a state, you should create a new element *on the same level as the scene node, just before it*.
For instance:
```html
<div id="state1"></div>
...
<section class="scene">
```
And there you go! You have registered a new state. The `div`'s id is what will be refered as the state's name from now on.
#### Entering the state
In order to enter a state, there are two ways.
You can use Javascript (which kind of destroys the purpose) OR use an `a` element.
```html
<a href="#state1">Click me!</a>
```
By clicking the element, the user will be able to change the state of the scene.
As mentioned before, you can use `a` elements in meshes, meaning you can have *interactive meshes* that change the state of the scene.
For instance, on a plane:
```html
<figure class="plane">
<div class="face front">
<img class="fill" src="texture.png"/>
<a class="fill" href="#state1"></a>
</div>
<div class="face back"></div>
</figure>
```
#### Detecting and Using States
Now that we know how to declare and enter states, let's get into the heart of the matter.
Detecting states is pretty easy: in your CSS file, we can use a combinasion of the `:target` element and the [General sibling combinator](https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_combinator) to apply custom styles to the scene using states.
For instance:
```css
#state1:target ~ section.scene {
/* custom styles here */
}
```
You can even apply styles to specific elements:
```css
#state1:target ~ section.scene #element {
/* custom styles here */
}
```
#### Locking rotation
If you use many different kinds of of rotation, it might be a good idea to lock it based on certain states.
To do so, use the scene selector, and set the `--rotation-x` and `--rotation-y` to fixed `!important` values.
```css
#state1:target ~ section.scene {
--rotation-x: -40deg !important;
--rotation-y: 40deg !important;
}
```
If you're still having trouble with selecting interactive elements, you might add the class `interactive` to your root, or any large enough element to lock the location on the current default.
### Tooltips
Having tooltips can help the user know what they are pointing at. Any `interactive` element (with the class, or `a` or `button`) can have one, using a div with the `tooltip` class. You can apply transforms to the tooltip for it to appear exactly where you want it to.
Example:
```html
<figure class="cuboid rectangular interactive">
...
<div class="tooltip" style="transform: translateY(-30px) translateX(-20px) translateZ(50px) rotateX(-90deg);">Click me!</div>
</figure>
```
## Examples
There is a sample cube example which makes use of practically everything you saw before in the `examples/cube` folder.
## F.A.Q.
### Why?
The question you're looking for is: "Why not?" I created this for fun, but maybe someone, somewhere, will find some use of this. Pretty sure there exists plenty of environements on the web that allows CSS and not JS.
### Enterprise Support?
No. At least, not for now.
### Shadows? Shaders? Raytracing?
✨Unimplementable✨ (at least with just CSS)
## Credits
This framework contains organised research led by various other people. In no particular order:
- Cylinder by [allenski on StackOverflow](https://stackoverflow.com/a/66130780)
- States by [Robin Rendle](https://css-tricks.com/a-whole-website-in-a-single-html-file/)

198
examples/cube/cube.html Normal file
View File

@ -0,0 +1,198 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML CSS Cube Test</title>
<link rel="stylesheet" href="../../main.css">
<link rel="stylesheet" href="cube.css">
</head>
<body>
<!-- States -->
<div id="cube-open"></div>
<div id="object-found"></div>
<!-- View mouse areas -->
<div class="view-section view-top-0 view-left-0"></div>
<div class="view-section view-top-0 view-left-1"></div>
<div class="view-section view-top-0 view-left-2"></div>
<div class="view-section view-top-0 view-left-3"></div>
<div class="view-section view-top-0 view-left-4"></div>
<div class="view-section view-top-0 view-left-5"></div>
<div class="view-section view-top-0 view-left-6"></div>
<div class="view-section view-top-0 view-left-7"></div>
<div class="view-section view-top-0 view-left-8"></div>
<div class="view-section view-top-1 view-left-0"></div>
<div class="view-section view-top-1 view-left-1"></div>
<div class="view-section view-top-1 view-left-2"></div>
<div class="view-section view-top-1 view-left-3"></div>
<div class="view-section view-top-1 view-left-4"></div>
<div class="view-section view-top-1 view-left-5"></div>
<div class="view-section view-top-1 view-left-6"></div>
<div class="view-section view-top-1 view-left-7"></div>
<div class="view-section view-top-1 view-left-8"></div>
<div class="view-section view-top-2 view-left-0"></div>
<div class="view-section view-top-2 view-left-1"></div>
<div class="view-section view-top-2 view-left-2"></div>
<div class="view-section view-top-2 view-left-3"></div>
<div class="view-section view-top-2 view-left-4"></div>
<div class="view-section view-top-2 view-left-5"></div>
<div class="view-section view-top-2 view-left-6"></div>
<div class="view-section view-top-2 view-left-7"></div>
<div class="view-section view-top-2 view-left-8"></div>
<div class="view-section view-top-3 view-left-0"></div>
<div class="view-section view-top-3 view-left-1"></div>
<div class="view-section view-top-3 view-left-2"></div>
<div class="view-section view-top-3 view-left-3"></div>
<div class="view-section view-top-3 view-left-4"></div>
<div class="view-section view-top-3 view-left-5"></div>
<div class="view-section view-top-3 view-left-6"></div>
<div class="view-section view-top-3 view-left-7"></div>
<div class="view-section view-top-3 view-left-8"></div>
<div class="view-section view-top-4 view-left-0"></div>
<div class="view-section view-top-4 view-left-1"></div>
<div class="view-section view-top-4 view-left-2"></div>
<div class="view-section view-top-4 view-left-3"></div>
<div class="view-section view-top-4 view-left-4"></div>
<div class="view-section view-top-4 view-left-5"></div>
<div class="view-section view-top-4 view-left-6"></div>
<div class="view-section view-top-4 view-left-7"></div>
<div class="view-section view-top-4 view-left-8"></div>
<div class="view-section view-top-5 view-left-0"></div>
<div class="view-section view-top-5 view-left-1"></div>
<div class="view-section view-top-5 view-left-2"></div>
<div class="view-section view-top-5 view-left-3"></div>
<div class="view-section view-top-5 view-left-4"></div>
<div class="view-section view-top-5 view-left-5"></div>
<div class="view-section view-top-5 view-left-6"></div>
<div class="view-section view-top-5 view-left-7"></div>
<div class="view-section view-top-5 view-left-8"></div>
<div class="view-section view-top-6 view-left-0"></div>
<div class="view-section view-top-6 view-left-1"></div>
<div class="view-section view-top-6 view-left-2"></div>
<div class="view-section view-top-6 view-left-3"></div>
<div class="view-section view-top-6 view-left-4"></div>
<div class="view-section view-top-6 view-left-5"></div>
<div class="view-section view-top-6 view-left-6"></div>
<div class="view-section view-top-6 view-left-7"></div>
<div class="view-section view-top-6 view-left-8"></div>
<div class="view-section view-top-7 view-left-0"></div>
<div class="view-section view-top-7 view-left-1"></div>
<div class="view-section view-top-7 view-left-2"></div>
<div class="view-section view-top-7 view-left-3"></div>
<div class="view-section view-top-7 view-left-4"></div>
<div class="view-section view-top-7 view-left-5"></div>
<div class="view-section view-top-7 view-left-6"></div>
<div class="view-section view-top-7 view-left-7"></div>
<div class="view-section view-top-7 view-left-8"></div>
<div class="view-section view-top-8 view-left-0"></div>
<div class="view-section view-top-8 view-left-1"></div>
<div class="view-section view-top-8 view-left-2"></div>
<div class="view-section view-top-8 view-left-3"></div>
<div class="view-section view-top-8 view-left-4"></div>
<div class="view-section view-top-8 view-left-5"></div>
<div class="view-section view-top-8 view-left-6"></div>
<div class="view-section view-top-8 view-left-7"></div>
<div class="view-section view-top-8 view-left-8"></div>
<div class="dialog">Congratulations! You found the object!</div>
<!-- Scene figure -->
<section class="scene">
<figure class="root" style='--width: 300px; --height: 300px;'>
<figure class="cube position-at-center" style='left: 50%; top: 50%; --size: 100px;'>
<svg class="face front interactive" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="m0 0v24h24v-24h-24zm5.5 2a3.5 3.5 0 0 1 3.5 3.5 3.5 3.5 0 0 1-3.5 3.5 3.5 3.5 0 0 1-3.5-3.5 3.5 3.5 0 0 1 3.5-3.5zm13 0a3.5 3.5 0 0 1 3.5 3.5 3.5 3.5 0 0 1-3.5 3.5 3.5 3.5 0 0 1-3.5-3.5 3.5 3.5 0 0 1 3.5-3.5zm-6.5 6.5a3.5 3.5 0 0 1 3.5 3.5 3.5 3.5 0 0 1-3.5 3.5 3.5 3.5 0 0 1-3.5-3.5 3.5 3.5 0 0 1 3.5-3.5zm-6.5 6.5a3.5 3.5 0 0 1 3.5 3.5 3.5 3.5 0 0 1-3.5 3.5 3.5 3.5 0 0 1-3.5-3.5 3.5 3.5 0 0 1 3.5-3.5zm13 0a3.5 3.5 0 0 1 3.5 3.5 3.5 3.5 0 0 1-3.5 3.5 3.5 3.5 0 0 1-3.5-3.5 3.5 3.5 0 0 1 3.5-3.5z" fill="white" fill-rule="evenodd"/>
<g fill="none" stroke="#000" stroke-width=".3">
<ellipse cx="5.5" cy="5.5" rx="3.4812" ry="3.4812"/>
<ellipse cx="18.5" cy="5.5" rx="3.4812" ry="3.4812"/>
<ellipse cx="12" cy="12" rx="3.4812" ry="3.4812"/>
<ellipse cx="5.5" cy="18.5" rx="3.4812" ry="3.4812"/>
<ellipse cx="18.5" cy="18.5" rx="3.4812" ry="3.4812"/>
</g>
</svg>
<div class="interactive face back "></div>
<div class="interactive face right "></div>
<div class="interactive face left "></div>
<div class="interactive face top "></div>
<div class="interactive face bottom"></div>
<figure id="buttons">
<figure class="cuboid rectangular button button0">
<div class="face front "></div>
<div class="face back "></div>
<div class="face left "></div>
<div class="face right "></div>
<div class="face top "></div>
<div class="face bottom"></div>
</figure>
<figure class="cuboid rectangular button button1">
<div class="face front "></div>
<div class="face back "></div>
<div class="face left "></div>
<div class="face right "></div>
<div class="face top "></div>
<div class="face bottom"></div>
</figure>
<figure class="cuboid rectangular button button2">
<div class="face front "></div>
<div class="face back "></div>
<div class="face left "></div>
<div class="face right "></div>
<div class="face top "></div>
<div class="face bottom"></div>
</figure>
<figure class="cuboid rectangular button button3">
<div class="face front "></div>
<div class="face back "></div>
<div class="face left "></div>
<div class="face right "></div>
<div class="face top "></div>
<div class="face bottom"></div>
</figure>
<figure class="cuboid rectangular button button4">
<div class="face front "></div>
<div class="face back "></div>
<div class="face left "></div>
<div class="face right "></div>
<div class="face top "></div>
<div class="face bottom"></div>
</figure>
<figure class="cuboid rectangular button button5 interactive">
<a href="#cube-open" class="face front "></a>
<a href="#cube-open" class="face back "></a>
<a href="#cube-open" class="face left "></a>
<a href="#cube-open" class="face right "></a>
<a href="#cube-open" class="face top "></a>
<a href="#cube-open" class="face bottom"></a>
<div class="tooltip" style="transform: translateY(-30px) translateX(-20px) translateZ(50px) rotateX(-90deg);">Click me!</div>
</figure>
</figure>
<figure id="object-wires" class="cylinder textured">
<a href="#object-found" class="strip strip-1 "></a>
<a href="#object-found" class="strip strip-2 "></a>
<a href="#object-found" class="strip strip-3 "></a>
<a href="#object-found" class="strip strip-4 "></a>
<a href="#object-found" class="strip strip-5 "></a>
<a href="#object-found" class="strip strip-6 "></a>
<a href="#object-found" class="strip strip-7 "></a>
<a href="#object-found" class="strip strip-8 "></a>
<a href="#object-found" class="strip strip-9 "></a>
<a href="#object-found" class="strip strip-10"></a>
<a href="#object-found" class="strip strip-11"></a>
<a href="#object-found" class="strip strip-12"></a>
<a href="#object-found" class="strip strip-13"></a>
<a href="#object-found" class="strip strip-14"></a>
<a href="#object-found" class="strip strip-15"></a>
<a href="#object-found" class="strip strip-16"></a>
<a href="#object-found" class="strip strip-17"></a>
<a href="#object-found" class="strip strip-18"></a>
<a href="#object-found" class="strip strip-19"></a>
<a href="#object-found" class="strip strip-20"></a>
<a href="#object-found" class="strip strip-21"></a>
<a href="#object-found" class="strip strip-22"></a>
<a href="#object-found" class="strip strip-23"></a>
<a href="#object-found" class="strip strip-24"></a>
</figure>
</figure>
</figure>
</section>
</body>
</html>

View File

@ -0,0 +1,13 @@
.scene figure.cylinder.textured { // TODO: Add other elements with strips.
// Maps a texture on a cylinder from left to right
--pstripcount: var(--strip-count, 24);
--ptexture: var(--texture, transparent);
@for $i from 1 to 90 {
& > .strip-#{$i} {
background: no-repeat space calc(100% * #{$i - 1} / (var(--pstripcount) - 1)) 0/calc(100% * (var(--pstripcount) - 1)) 100% var(--ptexture);
}
}
}

29
src/elements/axis.scss Normal file
View File

@ -0,0 +1,29 @@
.scene figure.axises {
width: var(--width, 100px);
height: var(--height, 100px);
& > .axis {
display: inline;
position: absolute;
width: var(--length, 100px);
height: var(--length2, 10px);
$offset: calc(var(--length) / 2);
&-x {
background-color: red;
color: red;
}
&-y {
transform: translateY($offset) translateX(calc(-1 * $offset)) rotateZ(90deg);
background-color: green;
color: green;
}
&-z {
transform: translateZ($offset) translateX(calc(-1 * $offset)) rotateX(90deg) rotateZ(90deg);
background-color: blue;
color: blue;
}
}
}

View File

@ -0,0 +1,26 @@
.scene figure.cylinder {
// Two parameters: height (y), radius (x,z), and strip-count (number of strip, up to 90)
width: calc(var(--radius, 20px) * 2);
height: var(--height, 100px);
--pradius: var(--radius, 20px);
--pstripcount: var(--strip-count, 24);
& > .strip {
position: absolute;
width: calc(2 * var(--PI) * var(--pradius) / var(--pstripcount));
height: var(--height, 100px);
background: white;
}
&.debug > .strip {
border: solid red;
border-width: 2px 0;
}
@for $i from 1 to 90 {
& > .strip-#{$i} { transform: rotateY(calc($i * (360deg / var(--pstripcount)))) translateZ(var(--pradius)); }
}
}

View File

@ -0,0 +1,20 @@
.scene figure.cube {
--halfsize: calc(var(--size, 100px) / 2);
width: var(--size, 100px);
height: var(--size, 100px);
& > .face {
position: absolute;
width: var(--size, 100px);
height: var(--size, 100px);
&.front { transform: rotateY( 0deg) translateZ(var(--halfsize)); }
&.right { transform: rotateY( 90deg) translateZ(var(--halfsize)); }
&.back { transform: rotateY(180deg) translateZ(var(--halfsize)); }
&.left { transform: rotateY(-90deg) translateZ(var(--halfsize)); }
&.top { transform: rotateX( 90deg) translateZ(var(--halfsize)); }
&.bottom { transform: rotateX(-90deg) translateZ(var(--halfsize)); }
}
}

View File

@ -0,0 +1,58 @@
.scene figure.cuboid.rectangular {
// Three parameters: width (x), length (y), and depth (z)
--pwidth: var(--width, 100px);
--plength: var(--length, 100px);
--pdepth: var(--depth, 100px);
--halfdepth: calc(var(--pdepth) / 2);
--halflength: calc(var(--plength) / 2);
--mhalfwidth: calc(var(--pwidth) * -1);
--mhalflength: calc(var(--plength) * -1);
--mhalfdepth: calc(var(--pdepth) * -1);
width: var(--pwidth);
height: var(--plength);
& > .face {
position: absolute;
&.front {
width: var(--pwidth);
height: var(--plength);
transform: rotateY(0deg) translateZ(var(--halfdepth));
}
&.back {
width: var(--pwidth);
height: var(--plength);
transform: rotateY(180deg) translateZ(var(--halfdepth));
}
&.left {
width: var(--pdepth);
height: var(--plength);
transform: rotateY(-90deg) translateZ(var(--halfdepth));
}
&.right {
width: var(--pdepth);
height: var(--plength);
transform: translateX(var(--pwidth)) rotateY(-90deg) translateZ(var(--halfdepth));
}
&.top {
width: var(--pwidth);
height: var(--pdepth);
transform: rotateX(90deg) translateZ(var(--halfdepth));
}
&.bottom {
width: var(--pwidth);
height: var(--pdepth);
transform: translateY(var(--plength)) rotateX(90deg) translateZ(var(--halfdepth));
}
}
}

39
src/elements/figure.scss Normal file
View File

@ -0,0 +1,39 @@
.scene {
& > figure.root {
display: block;
transform-origin: 50% 50%;
width: var(--width);
height: var(--height);
position: relative;
transform: rotateX(var(--rotation-x, 0deg)) rotateY(var(--rotation-y, 0deg));
transition: transform 0.2s;
}
& figure {
transform-style: preserve-3d;
margin-inline-start: 0;
margin-inline-end: 0;
margin-block-start: 0;
margin-block-end: 0;
position: absolute;
pointer-events: none;
}
& .position-at-center {
transform: translateX(-50%) translateY(-50%);
}
& .debug {
outline: solid 2px red;
outline-offset: -2px;
opacity: 1;
}
& .hidden {
display: none;
}
}

17
src/elements/plane.scss Normal file
View File

@ -0,0 +1,17 @@
// Planes are simple two faced figures with a width and a length.
// The root element must contain to faces: front and back.
.scene figure.plane {
width: var(--width);
height: var(--height);
& > .face {
position: absolute;
width: var(--width);
height: var(--height);
&.front { transform: rotateY( 0deg); }
&.back { transform: rotateY(180deg) translateZ(1px); }
}
}

21
src/main.scss Normal file
View File

@ -0,0 +1,21 @@
@import "scene";
@import "view";
/* elements */
@import "elements/figure";
@import "elements/axis";
@import "elements/plane";
@import "elements/circular/cylinder";
@import "elements/cuboids/cube";
@import "elements/cuboids/rectangular";
/* effects */
@import "effects/texture/strip-mapping";
/* UI elements */
@import "ui/buttons";
@import "ui/tooltips";

10
src/scene.scss Normal file
View File

@ -0,0 +1,10 @@
section.scene {
--PI: 3.14159265358979;
max-width: fit-content;
max-height: fit-content;
perspective: 600px;
border: solid 1px red;
pointer-events: none;
z-index: 1;
}

11
src/ui/buttons.scss Normal file
View File

@ -0,0 +1,11 @@
.fill {
z-index: 1;
width: 100%;
height: 100%;
position: absolute;
}
a, button, .interactive {
pointer-events: auto !important;
}

16
src/ui/tooltips.scss Normal file
View File

@ -0,0 +1,16 @@
.scene > figure.root figure.interactive:hover > .tooltip {
opacity: 0.8
}
.tooltip {
width: fit-content;
padding: 5px;
opacity: 0;
border-radius: 5px;
background: #222;
font-size: 1em;
color: white;
transition: opacity 0.2s;
}

31
src/view.scss Normal file
View File

@ -0,0 +1,31 @@
// Rotating canvas view
.view-section {
position: fixed;
width: 11.11vw;
height: 11.11vh;
z-index: 0;
}
@for $i from 0 through 9 {
// view sections
$rotation-x: $i * 20deg - 80deg;
$rotation-y: 160deg - ($i * 40deg);
.view-top-#{$i} {
top: 11.11vh * $i;
}
.view-top-#{$i}:hover ~ section.scene {
--rotation-x: #{$rotation-x};
}
.view-left-#{$i} {
left: 11.11vw * $i;
}
.view-left-#{$i}:hover ~ section.scene {
--rotation-y: #{$rotation-y};
}
}