Skip to content

Commit

Permalink
Merge pull request #920 from vorth/more-java
Browse files Browse the repository at this point in the history
Adding POV-Ray exporter for online
  • Loading branch information
vorth authored Sep 15, 2024
2 parents 241e82f + fc130db commit a86ffd3
Show file tree
Hide file tree
Showing 446 changed files with 53,859 additions and 179 deletions.
7 changes: 6 additions & 1 deletion cicd/jsweet-legacy-code.bash
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ banner 'Patching up the core bundle as an ES6 module' ##########################

OUTJS=$LEGACY/core-java.js
echo 'import { java, javaemul } from "./candies/j4ts-2.1.0-SNAPSHOT/bundle.js"' > $OUTJS
# echo 'import { javax } from "./candies/j4ts-awt-swing-0.0.2-SNAPSHOT/bundle.js"' >> $OUTJS

cat 'online/jsweetOut/core/js/bundle.js' | \
sed \
Expand All @@ -55,3 +54,9 @@ cat 'online/jsweetOut/core/js/bundle.js' | \
-e 's/(java || (java = {}));/(java);/' \
>> $OUTJS


banner 'You should regenerate the un-bundled Typescript!'

echo '/* THIS FILE IS CURRENTLY IGNORED! We are using the generated core-java.js instead, for now. */' > $LEGACY/ts/core-java.ts
cat online/jsweetOut/core/ts/bundle.ts >> $LEGACY/ts/core-java.ts

15 changes: 3 additions & 12 deletions core/src/main/java/com/vzome/core/exporters/POVRayExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.vzome.core.math.symmetry.Embedding;
import com.vzome.core.render.RenderedManifestation;
import com.vzome.core.viewing.CameraIntf;
import com.vzome.xml.ResourceLoader;

/**
* Renders out to POV-Ray using #declare statements to reuse geometry.
Expand Down Expand Up @@ -67,18 +68,8 @@ public void doExport( File povFile, Writer writer, int height, int width ) throw
output .println( "#declare parallel_proj = " + (mScene .isPerspective()?0:1) + ";" );
output .println();

InputStream input = getClass() .getClassLoader()
.getResourceAsStream( PREAMBLE_FILE );
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int num;
try {
while ( ( num = input .read( buf, 0, 1024 )) > 0 )
out .write( buf, 0, num );
} catch (IOException e) {
e.printStackTrace();
}
output .println( new String( out .toByteArray() ) );
String preamble = ResourceLoader.loadStringResource( PREAMBLE_FILE );
output .println( preamble );
output .println();

for ( int i = 0; i<3; i++ ) {
Expand Down
9 changes: 3 additions & 6 deletions online/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ core.config {
encoding = 'UTF-8'
sourceMap = false // I can't set breakpoints if the browser cannot find the Java file, so disabling for now.

bundle = true
bundle = true // I set this to false to generate the unbundled Typescript sources

workingDir = project.file( '.jsweet/core' )
tsOut = project.file( 'jsweetOut/core/ts' )
Expand Down Expand Up @@ -241,15 +241,12 @@ core.config {

'com/vzome/core/commands/CommandExecutePythonScript.java',

// These have already been reimplemented
'com/vzome/core/edits/ImportSimpleMeshJson.java',
'com/vzome/core/edits/ImportColoredMeshJson.java',
'com/vzome/core/edits/DodecagonSymmetry.java',
'com/vzome/core/edits/GhostSymmetry24Cell.java',
'com/vzome/core/edits/Symmetry4d.java',

'com/vzome/core/edits/RunZomodScript.java',
'com/vzome/core/edits/RunPythonScript.java',
'com/vzome/core/edits/RealizeMetaParts.java',
// 'com/vzome/core/edits/ReplaceWithShape.java',

// These have already been reimplemented
'com/vzome/core/exporters/ColoredMeshJsonExporter.java',
Expand Down
10 changes: 7 additions & 3 deletions online/src/app/classic/menus/filemenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { saveFileAs, openFile, saveTextFileAs, saveTextFile } from "../../../vie
import { CommandAction, Divider, Menu, MenuAction, MenuItem, SubMenu } from "../../framework/menus.jsx";
import { UrlDialog } from '../dialogs/webloader.jsx'
import { SvgPreviewDialog } from "../dialogs/svgpreview.jsx";
import { useCamera } from "../../../viewer/context/camera.jsx";
import { INITIAL_DISTANCE, useCamera } from "../../../viewer/context/camera.jsx";
import { useImageCapture } from "../../../viewer/context/export.jsx";

const queryParams = new URLSearchParams( window.location.search );
Expand All @@ -33,7 +33,7 @@ export const FileMenu = () =>
{
const { rootController, state, setState,
createDesign, openDesignFile, fetchDesignUrl, importMeshFile, guard, edited } = useEditor();
const { state: cameraState } = useCamera();
const { state: cameraState, mapViewToWorld } = useCamera();
const [ showDialog, setShowDialog ] = createSignal( false );
const fields = () => controllerProperty( rootController(), 'fields', 'fields', true );

Expand Down Expand Up @@ -98,7 +98,11 @@ export const FileMenu = () =>
const exportAs = ( extension, mimeType, format=extension, params={} ) => evt =>
{
const camera = unwrap( cameraState.camera );
camera .magnification = Math.log( camera.distance / INITIAL_DISTANCE );

const lighting = unwrap( cameraState.lighting );
lighting .directionalLights .forEach( light => light .worldDirection = mapViewToWorld( light.direction ) );

controllerExportAction( rootController(), format, { camera, lighting, ...params } )
.then( text => {
const name = (state.designName || 'untitled') .concat( "." + extension );
Expand Down Expand Up @@ -163,7 +167,7 @@ export const FileMenu = () =>

<SubMenu label="Export 3D Rendering">
<ExportItem label="Collada DAE" ext="dae" mime="text/plain" disabled={true} />
<ExportItem label="POV-Ray" ext="pov" mime="text/plain" disabled={true} />
<ExportItem label="POV-Ray" ext="pov" mime="text/plain" />
<ExportItem label="vZome Shapes JSON" format="shapes" ext="shapes.json" mime="application/json" />
<ExportItem label="VRML" ext="vrml" mime="text/plain" />
</SubMenu>
Expand Down
11 changes: 9 additions & 2 deletions online/src/viewer/context/camera.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { createContext, createEffect, useContext } from 'solid-js';
import { PerspectiveCamera } from "three";
import { PerspectiveCamera, Vector3 } from "three";

import { createStore } from 'solid-js/store';

Expand Down Expand Up @@ -154,6 +154,13 @@ const CameraProvider = ( props ) =>
}
const trackballProps = { camera: trackballCamera, sync }; // no need (or desire) for reactivity here

const mapViewToWorld = ( [ x, y, z ] ) =>
{
const vec = new Vector3( x, y, z );
vec .transformDirection( trackballCamera.matrixWorldInverse );
return [ vec.x, vec.y, vec.z ];
}

const setCamera = loadedCamera =>
{
setState( 'camera', loadedCamera );
Expand All @@ -179,7 +186,7 @@ const CameraProvider = ( props ) =>
const providerValue = {
name: props.name,
perspectiveProps, trackballProps, state,
resetCamera, setCamera, setLighting, togglePerspective, toggleOutlines, setDistance,
resetCamera, setCamera, setLighting, togglePerspective, toggleOutlines, setDistance, mapViewToWorld,
};

// The perspectiveProps is used to initialize PerspectiveCamera in clients.
Expand Down
2 changes: 1 addition & 1 deletion online/src/worker/java/java/util/UUID.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private UUID( String s )

public static UUID randomUUID()
{
return new UUID( Double.toString( Math.random() ) );
return new UUID( Double.toString( Math.random() ) .substring( 2 ) );
}

public String toString()
Expand Down
Loading

0 comments on commit a86ffd3

Please sign in to comment.