thefranke / unityx3d

A script to import/export X3D to/from Unity
26 stars 10 forks source link

X3D Exporter #2

Open brutzman opened 6 years ago

brutzman commented 6 years ago

X3D Exporter

The X3D Exporter by Tob is great - thanks!.

We're hoping to help with improvement of this important tool. It is in the "top ten" items of Web3D Consortium X3D Projects Wish List.

David Tan tested it on the following example. Exported results worked without modifications in InstantReality but not in any other X3D tool. Attached in next post please find

Here are some issues with the X3D output:

<?xml version="1.0" encoding="UTF-8"?> <?!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "http://www.web3d.org/specifications/x3d-3.3.dtd"&gt; <?X3D profile='Immersive' version='3.3' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.3.xsd'&gt;

List of illegal X3D nodes (InstantReality extensions perhaps?) and potential X3D replacements:

All X3D scene export results can be checked online using the X3D Validator

datan8457 commented 6 years ago

I've summarized the process / outputs of my use of the X3D Exporter in this post.

Disclaimer - My x3d experience is limited to exactly the below. I made no edits to theFranke's .cs script. I am also not a Unity/.cs expert. I have only worked in this area for a few months.


I placed the unityx3d.cs file in my Unity project's "Assets" folder as shown below: explorerdirectoryview_s

My Unity project consists of a semi-spherical volume composed of scaled cubes. unitysceneview1

The individual cubes are untextured and simply have a material with the shader qualities noted below: gameobjectmaterial

Then per the readme, I selected the empty gameObject that contains all the cells and selected "Assets-> X3D -> Export X3D...": unitysceneview2

It then runs for a few minutes and the .x3d file appears.

Opening the file in InstantReality and selecting Navigation -> Show All provides the below view: x3doutputwhite

I then opened the .x3d file in a text editor and did a find+replace all "<appearance />" with the below: x3dappearancechanged

There was no specific reason why I chose the RGB values, Any valid color should work.

This then produced: x3doutputfront x3doutputiso x3doutputtop


In summary, works pretty well (though the output file is over 10mb in size).

I have attached an output from a much coarser run of the project that is ~500kb.

smallX3DoutputSample.txt

thefranke commented 6 years ago

TextureCoordinate2D as

@brutzman The potential fix is missing. Which node did you mean?

thefranke commented 6 years ago

CommonSurfaceShader - see X3D Programmable Shaders Component

@brutzman The CommonSurfaceShader is an Avalon-only component and is used because the regular Material node does not support the rich variety of parameters used commonly in renderers today. You can however switch it off if you untick Unity -> Preferences -> UnityX3D -> Use CommonSurfaceShader

thefranke commented 6 years ago

I've pushed a round of fixes for everything except the header part "ISO//Web3D//DTD X3D 3.3//EN", which somehow I can't get to work right now with the XML C# API.

andreasplesch commented 6 years ago
doctype = doc.CreateDocumentType("X3D", "ISO//Web3D//DTD X3D 3.3//EN", "http://www.web3d.org/specifications/x3d-3.3.dtd", null);

seems to work, at least here:

https://dotnetfiddle.net/d3UFIt

I can submit an (untested) PR if desired.