How to convert a XML with edges elements into a SVG? - c#

I have XML files, used on Unity in C#, imported from an Adobe Animate project. I want to create animate elements into Unity, so my question is, is that possible to do that ? Because of course, I searched a lot, and that's something only few people did, then how ?
Here, you have a short example of one XML file
<strokes>
<StrokeStyle index="1">
<SolidStroke scaleMode="normal" weight="3">
<fill>
<SolidColor color="#FFCC33" colorReferenceID="14"/>
</fill>
</SolidStroke>
</StrokeStyle>
</strokes>
<edges>
<Edge strokeStyle="1" edges="!-634 1767|-690 1566!-690 1566|-889 1509!-889 1509|-859 550!-859 550|-681 512!-681 512|-634 330!-634 330|-479 239!-479 239[-46 149 274 -38!274 -38|809 11!809 11[911 179 797 368!797 368[704 429 479 466!479 466|39 486!39 486|61 559!61 559
|1078 599!1078 599|1141 649!1141 649|1132 1729!1132 1729|1100 1767!1100 1767|560 1787!560 1787|545 1976!545 1976|-647 1951!-647 1951|-634 1767!-634 3369|-690 3570!-690 3570|-889 3627!-889 3627|-859 4586!-859 4586|-681 4624!-681 4624|-634
4806!-634 4806|-479 4897!-479 4897[-46 4987 274 5174!274 5174|745 5174!745 5174[911 4957 797 4768!797 4768[704 4707 479 4670!479 4670|39 4650!39 4650|61 4577!61 4577|1078 4537!1078 4537|1141 4487!1141 4487|1132 3407!1132 3407|1100 3369
!1100 3369|560 3349!560 3349|545 3160!545 3160|-647 3185!-647 3185|-634 3369"/>
<Edge cubics="!-634 330(;-634,330 -479,239 -479,239q-634 330 -479 239);"/>
</edges>
Format is not important, easiest way seems to convert this file into a SVG, but It can be a picture format.
I didn't try lots of things, once again I couldn't find examples of this problem, and what I wanted to do first is to create a "drawer", which create the csv using edges, and draw each edge directly on Unity.
The problem of this idea is the fact that I'll have all this elements drawn, but they will not be a unique element, movable.

Related

C#, How to add Pitch to SpeechSynthesizer.SpeakSsml(String)

I use SpeechSynthesizer.SpeakSsml(String).
However not able to build an SSML containing pitch.
So far I could not find any working example online.
MS's Speech Synthesizer isn't built to do singing synthesis, but you can change the pitch characteristics using the <prosody> element:
SpeechSynthesizer.SpeakSsml("<speak version=\"1.0\" xml:lang=\"en\"><prosody pitch=\"x-low\">Hello World</prosody>.<prosody pitch=\"x-high\">Hello World</prosody></speak>");

Decoding JPEG MCUs in C#

abstract
In the process of writing an unpacker for a IPK-archive (NDS Homebrew Image Viewer) I got stuck at the point where I had to decode single MCUs. The original Sourcecode indicates the usage of DCT but the reference implementation is all in ARM assembly...
I'm currently writing a rudimentary unpacker for the files utilized by NDS Homebrew "Image Viewer" (http://gamebrew.org/wiki/Image_Viewer).
The original site seems down but I found the source code (including a file format description) inside the archive hosted on gamebrew.
The unpacker is written in C# due to convenience (BinaryReader) and also because there is no need for it to be fast.
I've already managed to extract the thumbnails. Those are stored as deflated (zlib) BGR-Bitmaps.
The full-size images are split up into MCU's (8x8 samples). Each MCU is also stored in deflated form.
As of now I got the decompressed data with what seems like DCTed data. It also looks like they've "multiplexed" the individual channels (is this the 4:1:1?).
In the NDS version the byte data then gets passed together with a quantization-table (array of 64 signed 16bit-integers) into a function which looks like this:
void customjpeg_DecodeYUV411(s32 *pQuantizeTable,u8 *pData,u16 *pBuf)
{
pDCs=(s16*)pData;
pACs=(s8*)&pDCs[4*4*6];
static __attribute__ ((section (".dtcm"))) DCTELEM _y0[DCTSIZE2],_y1[DCTSIZE2],_y2[DCTSIZE2],_y3[DCTSIZE2],_cb[DCTSIZE2],_cr[DCTSIZE2];
TYUV411toRGB15_Data YUV411toRGB15_Data[4]={
{ NULL, _y0, &_cb[((4*0)*DCTSIZE)+(4*0)], &_cr[((4*0)*DCTSIZE)+(4*0)] },
{ NULL, _y1, &_cb[((4*0)*DCTSIZE)+(4*1)], &_cr[((4*0)*DCTSIZE)+(4*1)] },
{ NULL, _y2, &_cb[((4*1)*DCTSIZE)+(4*0)], &_cr[((4*1)*DCTSIZE)+(4*0)] },
{ NULL, _y3, &_cb[((4*1)*DCTSIZE)+(4*1)], &_cr[((4*1)*DCTSIZE)+(4*1)] },
};
// PrfStart();
// 3.759ms
for(u32 y=0;y<4;y++){
YUV411toRGB15_Data[0]._pBuf=&pBuf[((8*0)*64)+(8*0)];
YUV411toRGB15_Data[1]._pBuf=&pBuf[((8*0)*64)+(8*1)];
YUV411toRGB15_Data[2]._pBuf=&pBuf[((8*1)*64)+(8*0)];
YUV411toRGB15_Data[3]._pBuf=&pBuf[((8*1)*64)+(8*1)];
for(u32 x=0;x<4;x++){
DCT13bit_asm(pQuantizeTable,_y0);
DCT13bit_asm(pQuantizeTable,_y1);
DCT13bit_asm(pQuantizeTable,_y2);
DCT13bit_asm(pQuantizeTable,_y3);
DCT13bit_asm(pQuantizeTable,_cb);
DCT13bit_asm(pQuantizeTable,_cr);
YUV411_13bit_toRGB15_asm(YUV411toRGB15_Data);
YUV411toRGB15_Data[0]._pBuf+=DCTSIZE*2;
YUV411toRGB15_Data[1]._pBuf+=DCTSIZE*2;
YUV411toRGB15_Data[2]._pBuf+=DCTSIZE*2;
YUV411toRGB15_Data[3]._pBuf+=DCTSIZE*2;
}
pBuf+=(DCTSIZE*2)*64;
}
// PrfEnd(0); ShowLogHalt();
}
(taken from: customjpeg.cpp)
why are the calls run 4x4 times per mcu?
is it pure DCT? because i don't see where the "dequantization" is done and i've seen (afaik) some references to the zigzag-pattern(?) in the assembly..
am I missing something?
I've checked with some online resources, but they only seem to focus on the encoding process.
Unfortunately I lack the mathematical background, therefore I haven't grasped on to the full concept of DCT and thus the reversal process isn't as straight forward to me..
I've spent a whole day to get this running by utilizing libraries and C#-DCT implementations but I was unsuccessful.

How load textures in Balder?

I use Balder engine to work with 3D objects. I have *.ase file which contain
*MAP_DIFFUSE {
*MAP_NAME "carrier_body"
*MAP_CLASS "Bitmap"
*MAP_SUBNO 1
*MAP_AMOUNT 1.0000
*BITMAP "//carrier_body.tga"
........
I've added my ase file and carrier_body.tga to resource of the project but when I load mesh from ase
var tank=ContentManager.Load<Mesh>("tanks_carrier.ase");
I've caught the exception:
There is no loader for the specified file type 'tga'
How right way to loading textures for ase file in Balder?
I passed the problem. Balder is not supported tga format for textures, I've used png texture and all worked nice.

WorkflowMarkupSerializer doesn't keep positions in a state machine workflow

I am using WorkflowMarkupSerializer to save a statemachine workflow - it saves the states OK, but does not keep their positions. The code to write the workflow is here:
using (XmlWriter xmlWriter = XmlWriter.Create(fileName))
{
WorkflowMarkupSerializer markupSerializer
= new WorkflowMarkupSerializer();
markupSerializer.Serialize(xmlWriter, workflow);
}
The code to read the workflow is:
DesignerSerializationManager dsm
= new DesignerSerializationManager();
using (dsm.CreateSession())
{
using (XmlReader xmlReader
= XmlReader.Create(fileName))
{
//deserialize the workflow from the XmlReader
WorkflowMarkupSerializer markupSerializer
= new WorkflowMarkupSerializer();
workflow = markupSerializer.Deserialize(
dsm, xmlReader) as Activity;
if (dsm.Errors.Count > 0)
{
WorkflowMarkupSerializationException error
= dsm.Errors[0]
as WorkflowMarkupSerializationException;
throw error;
}
}
}
Open Control Panel -> "Regional and language options" and set list separator to ',' (comma)
and workflow serializer will use ',' (comma) as separator for X,Y coordinates for struct SizeF
then select ';' and workflow serializer will use ';' (semicolon) as separator.
This really stupid that serializer use regional setting for serialize markup.
The position of all the states is kept in a separate file. You'll need to drag it around with the markup of the workflow itself. Luckily, it's just XML as well, so you might be able to reuse most of the code you have up there. If memory serves, I believe it's simply NameOfYourWorkflow.layout.
I agree with x0n - the designer is really bad in Visual Studio.
OK, this tutorial gives good information on how to do it - although so far I am only able to save the layout, I haven't been able to correctly use the layout. The information in question is about 2/3rds down (or just do a search for .layout)
(How does one close his own question?)
Note that there is a bug in either the serialize or deserialize of the XML created (named in the example with an extension of .layout.)
It produces the following xml as the first line of the file:
<?xml version="1.0" encoding="utf-8"?><StateMachineWorkflowDesigner xmlns:ns0="clr-namespace:System.Drawing;Assembly=System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Name="New" Location="30, 30" Size="519, 587" AutoSizeMargin="16, 24" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
When reading this back in, the size attribute causes an exception. I removed Size="519, 587" from the file and the workflow is loaded back correctly. Right now, I write the file, open it and remove the size, then close it. I need to think about a more elegant solution, but at least I am now saving and restoring a state machine workflow.
Hah, even the workflow designer hosted in Visual Studio 2008 loses the positions of states randomly. This tells me it's probably not an easy task, and is information external to the Activities that comprise it. I'd dig more around the host for information; if I find something, I'll post back.

C# code to search and result in xml

I’m after some C# code that will have the following methods that will return Xml as the result.
Search the Apple iTunes App store. If I pass it a name or partial name the function must return a list of possible search results or just one result if it is a perfect match.
Example shown below:
<App>
<AppId>321564880</AppId>
<Name>Doodle Clock - Clock A Doodle Do!</Name>
<ReleaseDate>Released Sep 28, 2009</ReleaseDate>
<Artist>YARG</Artist>
<Description>Description of App</Description>
<Copyright>© YARG Limited 2009</Copyright>
<Price>$0.99</Price>
<Category>Lifestyle</Category>
<MainImageUrl><!—main App icon image urlà </ImageUrl>
<ExtraImages>
<!-- these will be the extra images you see in the App store other than the main application icon -->
<ImageUrl> <!—url of extra image 1à</ImageUrl>
<ImageUrl> <!—url of extra image 2à</ImageUrl>
<ImageUrl> <!—url of extra image 3à</ImageUrl>
</ExtraImages>
<Version>Version: 1.1 (iPhone OS 3.0 Tested)</Version>
<Size>1.5 MB</Size>
</App>
Okay the best way to create xml file and parse and manipulate them is using XDocument,XElement,etc. Because they are enumerable which means you can use LINQ on them and that will help you a lot.
For example :
XElement element = new XElement("Persons",
new XElement("Person","John",
new XAttribute("Id","1")),
new XElement("Person","Aaron",
new XAttribute("Id",2))
)
returns
<Persons>
<Person Id="1">John</Person>
<Person Id="2">Aaron</Person>
</Person>
More information : System.Xml.Linq Namespace
If you are looking for speed, then you can use XMLReader and XMLWriter but you can't find the flexibility that System.Xml.Linq provides.
You should use XPath in .NET:
http://www.aspfree.com/c/a/.NET/Working-with-XPath-The-NET-Way/
I would use XmlTextReader. It's the fastest way (though read-forward-only) - if you are maybe looking for speed. If not, XPath should do.

Categories

Resources